Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-09-17 17:12:25 +0000
committerEd Willink2016-09-19 11:20:11 +0000
commit2ab78f88c703412753b45e7b4936a9367a78c4a3 (patch)
tree1d503b69a0c9c26b34069d97942afbe8f0dccd2a
parentf8f64a1b8a404bd5252092fffca76afc188c35b9 (diff)
downloadorg.eclipse.qvtd-2ab78f88c703412753b45e7b4936a9367a78c4a3.tar.gz
org.eclipse.qvtd-2ab78f88c703412753b45e7b4936a9367a78c4a3.tar.xz
org.eclipse.qvtd-2ab78f88c703412753b45e7b4936a9367a78c4a3.zip
[501650] Use Lists rather than Sets for known unique collections
-rw-r--r--plugins/org.eclipse.qvtd.pivot.qvtimperative/src/org/eclipse/qvtd/pivot/qvtimperative/evaluation/QVTiModelManager.java40
-rw-r--r--plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/evaluation/TypedModelInstance.java3
-rw-r--r--plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/library/model/ModelObjectsOfKindOperation.java4
3 files changed, 22 insertions, 25 deletions
diff --git a/plugins/org.eclipse.qvtd.pivot.qvtimperative/src/org/eclipse/qvtd/pivot/qvtimperative/evaluation/QVTiModelManager.java b/plugins/org.eclipse.qvtd.pivot.qvtimperative/src/org/eclipse/qvtd/pivot/qvtimperative/evaluation/QVTiModelManager.java
index 4ed66cc78..ac4e8d059 100644
--- a/plugins/org.eclipse.qvtd.pivot.qvtimperative/src/org/eclipse/qvtd/pivot/qvtimperative/evaluation/QVTiModelManager.java
+++ b/plugins/org.eclipse.qvtd.pivot.qvtimperative/src/org/eclipse/qvtd/pivot/qvtimperative/evaluation/QVTiModelManager.java
@@ -130,6 +130,7 @@ public class QVTiModelManager extends AbstractModelManager
}
}
if (elements != null) {
+ assert !elements.contains(element);
elements.add((EObject) element);
}
}
@@ -186,18 +187,18 @@ public class QVTiModelManager extends AbstractModelManager
for (@NonNull EObject root : roots) {
// if (root != null) {
//if (root.eClass().getName().equals(type.getName())) {
- if (isInstance(type, root)) {
- elements.add(root);
- }
- for (TreeIterator<EObject> contents = root.eAllContents(); contents
- .hasNext();) {
- EObject element = contents.next();
- if ((element != null) && isInstance(type, element)) {
- // if (((EClass) type.getETarget()).getName().equals(element.eClass().getName())) {
- elements.add(element);
+ if (root.eContainer() == null) {
+ if (isInstance(type, root)) {
+ elements.add(root);
+ }
+ for (TreeIterator<EObject> contents = root.eAllContents(); contents.hasNext();) {
+ EObject element = contents.next();
+ if ((element != null) && isInstance(type, element)) {
+ // if (((EClass) type.getETarget()).getName().equals(element.eClass().getName())) {
+ elements.add(element);
+ }
}
}
- // }
}
}
else {
@@ -393,8 +394,8 @@ public class QVTiModelManager extends AbstractModelManager
{
protected final @NonNull QVTiModelManager modelManager;
protected final @NonNull TypedModel typedModel;
- private /*@LazyNonNull*/ Map<@NonNull Type, @NonNull Set<@NonNull Object>> kind2instances = null;
- private /*@LazyNonNull*/ Map<@NonNull Type, @NonNull Set<@NonNull Object>> type2instances = null;
+ private /*@LazyNonNull*/ Map<@NonNull Type, @NonNull List<@NonNull Object>> kind2instances = null;
+ private /*@LazyNonNull*/ Map<@NonNull Type, @NonNull List<@NonNull Object>> type2instances = null;
public QVTiTypedModelInstance(@NonNull QVTiModelManager modelManager, @NonNull TypedModel typedModel) {
this.modelManager = modelManager;
@@ -412,29 +413,26 @@ public class QVTiModelManager extends AbstractModelManager
}
@Override
- public @NonNull Set<@NonNull Object> getObjectsOfKind(org.eclipse.ocl.pivot.@NonNull Class type) {
+ public @NonNull List<@NonNull Object> getObjectsOfKind(org.eclipse.ocl.pivot.@NonNull Class type) {
if (kind2instances == null) {
kind2instances = new HashMap<>();
}
- Set<@NonNull Object> elements = kind2instances.get(type);
+ List<@NonNull Object> elements = kind2instances.get(type);
if (elements == null) {
- elements = new HashSet<>();
+ elements = modelManager.getElementsByType(typedModel, type);
kind2instances.put(type, elements);
- for (@NonNull Object o : modelManager.getElementsByType(typedModel, type)) {
- elements.add(o);
- }
}
return elements;
}
@Override
- public @NonNull Set<@NonNull Object> getObjectsOfType(org.eclipse.ocl.pivot.@NonNull Class type) {
+ public @NonNull List<@NonNull Object> getObjectsOfType(org.eclipse.ocl.pivot.@NonNull Class type) {
if (type2instances == null) {
type2instances = new HashMap<>();
}
- Set<@NonNull Object> elements = type2instances.get(type);
+ List<@NonNull Object> elements = type2instances.get(type);
if (elements == null) {
- elements = new HashSet<>();
+ elements = new ArrayList<>();
type2instances.put(type, elements);
EObject eClass = type.getESObject();
for (@NonNull Object eObject : getObjectsOfKind(type)) {
diff --git a/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/evaluation/TypedModelInstance.java b/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/evaluation/TypedModelInstance.java
index 8d2ee9d18..5c956b75d 100644
--- a/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/evaluation/TypedModelInstance.java
+++ b/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/evaluation/TypedModelInstance.java
@@ -18,8 +18,7 @@ import org.eclipse.jdt.annotation.Nullable;
/**
* A TypedModelInstance makes an input or output model of an executing transformation
* accessible as a model instance.
- *
- * @since 1.1
+ *
* @noimplement clients should derive from AbstractTypedModelInstance
*/
public interface TypedModelInstance
diff --git a/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/library/model/ModelObjectsOfKindOperation.java b/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/library/model/ModelObjectsOfKindOperation.java
index 9b98774bc..f58bd007f 100644
--- a/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/library/model/ModelObjectsOfKindOperation.java
+++ b/plugins/org.eclipse.qvtd.runtime/src/org/eclipse/qvtd/runtime/library/model/ModelObjectsOfKindOperation.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.qvtd.runtime.library.model;
-import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
@@ -40,6 +39,7 @@ public class ModelObjectsOfKindOperation extends AbstractBinaryOperation
}
TypedModelInstance typedModelInstance = (TypedModelInstance)sourceVal;
Collection<@NonNull ? extends Object> results = typedModelInstance.getObjectsOfKind(type);
- return createSetValue((CollectionTypeId)returnTypeId, new ArrayList<@NonNull Object>(results));
+ return createSetValue((CollectionTypeId)returnTypeId, results);
+ // return createSetValue((CollectionTypeId)returnTypeId, new ArrayList<@NonNull Object>(results));
}
}

Back to the top