Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2017-08-25 14:10:32 -0400
committerRyan D. Brooks2017-08-29 15:58:31 -0400
commit799f6b4527e3398c8e72c6914fa26f2a07d3108e (patch)
treeb1fe0a5fca5931aeba3cd769559cd9ad44a57aab
parentfc34536f84b5c00d1f1ff1e4edad1cd3905a7c5a (diff)
downloadorg.eclipse.osee-799f6b4527e3398c8e72c6914fa26f2a07d3108e.tar.gz
org.eclipse.osee-799f6b4527e3398c8e72c6914fa26f2a07d3108e.tar.xz
org.eclipse.osee-799f6b4527e3398c8e72c6914fa26f2a07d3108e.zip
refinement: Improve performance of attribute filtering
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ModificationType.java24
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java49
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteInvalidAttributeTypesFromBranch.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationNodeAdjacenciesTest.java7
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicates.java7
7 files changed, 30 insertions, 68 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ModificationType.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ModificationType.java
index 4afb001a82..4f9d130cf4 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ModificationType.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/ModificationType.java
@@ -11,9 +11,6 @@
package org.eclipse.osee.framework.core.enums;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
/**
@@ -57,8 +54,6 @@ public enum ModificationType {
// This should never appear in the database, it is only used by the gui to show applicability changes
APPLICABILITY("Applicability", 10);
- private final static Set<ModificationType> ALL_NOT_HARD_DELETED = new HashSet<>();
- private final static Set<ModificationType> ALL_MOD_TYPES = new HashSet<>();
private int value;
private String displayName;
@@ -123,25 +118,6 @@ public enum ModificationType {
return this == DELETED;
}
- public static Set<ModificationType> getAllNotHardDeletedTypes() {
- if (ALL_NOT_HARD_DELETED.isEmpty()) {
- synchronized (ALL_NOT_HARD_DELETED) {
- ALL_NOT_HARD_DELETED.addAll(getAllModTypes());
- ALL_NOT_HARD_DELETED.remove(ModificationType.DELETED);
- }
- }
- return ALL_NOT_HARD_DELETED;
- }
-
- public static Set<ModificationType> getAllModTypes() {
- if (ALL_MOD_TYPES.isEmpty()) {
- synchronized (ALL_MOD_TYPES) {
- ALL_MOD_TYPES.addAll(Arrays.asList(ModificationType.values()));
- }
- }
- return ALL_MOD_TYPES;
- }
-
public boolean isExistingVersionUsed() {
boolean result = false;
switch (this) {
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java
index a0e59f1d60..e2f9a005ac 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/Artifact.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.eclipse.osee.framework.core.data.Adaptable;
import org.eclipse.osee.framework.core.data.ApplicabilityId;
import org.eclipse.osee.framework.core.data.ArtifactTypeId;
@@ -546,55 +547,39 @@ public class Artifact extends NamedIdBase implements IArtifact, Adaptable, Fully
* @return attributes All attributes of the specified type name including deleted and artifact deleted
*/
public final List<Attribute<?>> getAllAttributesIncludingHardDeleted(AttributeTypeId attributeType) throws OseeCoreException {
- return getAttributesByModificationType(attributeType, ModificationType.getAllModTypes());
+ ensureAttributesLoaded();
+ return getAttributes((List<Attribute<?>>) attributes.getValues(attributeType), true);
}
/**
* The use of this method is discouraged since it directly returns Attributes.
*/
- public final List<Attribute<?>> getAttributes() throws OseeCoreException {
+ public final List<Attribute<?>> getAttributes() {
return getAttributes(false);
}
- public final List<Attribute<?>> getAttributes(boolean includeDeleted) throws OseeCoreException {
- List<Attribute<?>> attributes;
+ public final List<Attribute<?>> getAttributes(boolean includeDeleted) {
+ ensureAttributesLoaded();
+ return getAttributes(attributes.getValues(), includeDeleted);
+ }
+
+ private List<Attribute<?>> getAttributes(List<Attribute<?>> attributes, boolean includeDeleted) {
+ if (attributes == null) {
+ return java.util.Collections.emptyList();
+ }
if (includeDeleted) {
- attributes = getAttributesByModificationType(ModificationType.getAllModTypes());
- } else {
- attributes = getAttributesByModificationType(ModificationType.getAllNotHardDeletedTypes());
+ return attributes;
}
- return attributes;
+ return attributes.stream().filter(a -> !a.getModificationType().isHardDeleted()).collect(Collectors.toList());
}
/**
* The use of this method is discouraged since it directly returns Attributes.
*/
@Deprecated
- public final <T> List<Attribute<T>> getAttributes(AttributeTypeId attributeType) throws OseeCoreException {
- return Collections.castAll(
- getAttributesByModificationType(attributeType, ModificationType.getAllNotHardDeletedTypes()));
- }
-
- private List<Attribute<?>> getAttributesByModificationType(Set<ModificationType> allowedModTypes) throws OseeCoreException {
+ public final <T> List<Attribute<T>> getAttributes(AttributeTypeId attributeType) {
ensureAttributesLoaded();
- return filterByModificationType(attributes.getValues(), allowedModTypes);
- }
-
- private List<Attribute<?>> getAttributesByModificationType(AttributeTypeId attributeType, Set<ModificationType> allowedModTypes) throws OseeCoreException {
- ensureAttributesLoaded();
- return filterByModificationType(attributes.getValues(attributeType), allowedModTypes);
- }
-
- private List<Attribute<?>> filterByModificationType(Collection<Attribute<?>> attributes, Set<ModificationType> allowedModTypes) {
- List<Attribute<?>> filteredList = new ArrayList<>();
- if (allowedModTypes != null && !allowedModTypes.isEmpty() && attributes != null && !attributes.isEmpty()) {
- for (Attribute<?> attribute : attributes) {
- if (allowedModTypes.contains(attribute.getModificationType())) {
- filteredList.add(attribute);
- }
- }
- }
- return filteredList;
+ return Collections.castAll(getAttributes((List<Attribute<?>>) attributes.getValues(attributeType), false));
}
/**
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteInvalidAttributeTypesFromBranch.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteInvalidAttributeTypesFromBranch.java
index 885c6fe3b0..d08f13831d 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteInvalidAttributeTypesFromBranch.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/DeleteInvalidAttributeTypesFromBranch.java
@@ -76,7 +76,7 @@ public class DeleteInvalidAttributeTypesFromBranch extends AbstractBlam {
}
private void delete(Artifact art, AttributeType attrType) throws OseeCoreException {
- List<Attribute<?>> attrs = art.getAttributes(false);
+ List<Attribute<?>> attrs = art.getAttributes();
for (Attribute<?> attr : attrs) {
if (attr.isOfType(attrType)) {
attr.delete();
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
index 20668e35b2..52fd7e9c76 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
@@ -105,9 +105,12 @@ public class ArtifactTest {
when(deleted.getModificationType()).thenReturn(ModificationType.ARTIFACT_DELETED);
when(deleted.isDeleted()).thenReturn(true);
+ when(notDeleted.getModificationType()).thenReturn(ModificationType.NEW);
when(notDeleted.getOrcsData()).thenReturn(attributeData);
+ when(notDeleted.getAttributeType()).thenReturn(attributeType);
when(deleted.getOrcsData()).thenReturn(attributeData);
when(differentType.getOrcsData()).thenReturn(attributeData);
+ when(differentType.getModificationType()).thenReturn(ModificationType.NEW);
when(types.get(CoreArtifactTypes.GeneralData.getId())).thenReturn(CoreArtifactTypes.GeneralData);
when(types.get(CoreArtifactTypes.CodeUnit.getId())).thenReturn(CoreArtifactTypes.CodeUnit);
@@ -414,7 +417,6 @@ public class ArtifactTest {
@SuppressWarnings("unchecked")
public void testDeleteSoleAttribute() throws OseeCoreException {
when(attributeFactory.getMinOccurrenceLimit(attributeType)).thenReturn(0);
- when(notDeleted.getAttributeType()).thenReturn(attributeType);
when(notDeleted.getContainer()).thenReturn(artifact);
artifact.add(attributeType, notDeleted);
artifact.deleteSoleAttribute(attributeType);
@@ -425,8 +427,6 @@ public class ArtifactTest {
@SuppressWarnings("unchecked")
public void testDeleteSoleAttributeException() throws OseeCoreException {
when(attributeFactory.getMinOccurrenceLimit(attributeType)).thenReturn(1);
-
- when(notDeleted.getAttributeType()).thenReturn(attributeType);
artifact.add(attributeType, notDeleted);
thrown.expect(OseeStateException.class);
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java
index cbe8b896b3..de32756aea 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java
@@ -176,6 +176,7 @@ public class RelationManagerTest {
when(relation1.getRationale()).thenReturn("rationale on relation1");
when(relation1.getOrcsData()).thenReturn(data1);
when(relation1.getOrcsData().getLocalId()).thenReturn(10);
+ when(relation1.getModificationType()).thenReturn(ModificationType.NEW);
when(relation2.getLocalIdForSide(RelationSide.SIDE_A)).thenReturn(11);
when(relation2.getLocalIdForSide(RelationSide.SIDE_B)).thenReturn(33);
@@ -190,6 +191,7 @@ public class RelationManagerTest {
when(relation3.getRationale()).thenReturn("rationale on relation3");
when(relation3.getOrcsData()).thenReturn(data3);
when(relation3.getOrcsData().getLocalId()).thenReturn(12);
+ when(relation3.getModificationType()).thenReturn(ModificationType.NEW);
when(relation4.getLocalIdForSide(RelationSide.SIDE_A)).thenReturn(11);
when(relation4.getLocalIdForSide(RelationSide.SIDE_B)).thenReturn(55);
@@ -197,6 +199,7 @@ public class RelationManagerTest {
when(relation4.getRationale()).thenReturn("rationale on relation4");
when(relation4.getOrcsData()).thenReturn(data4);
when(relation4.getOrcsData().getLocalId()).thenReturn(13);
+ when(relation4.getModificationType()).thenReturn(ModificationType.NEW);
setupAdjacencies(node1, relation1, relation2, relation3, relation4);
setupAdjacencies(node2, relation1);
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationNodeAdjacenciesTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationNodeAdjacenciesTest.java
index 1b88e1efc9..559f9b8c93 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationNodeAdjacenciesTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationNodeAdjacenciesTest.java
@@ -58,19 +58,18 @@ public class RelationNodeAdjacenciesTest {
@Mock HasLocalId localId;
// @formatter:on
- private RelationNodeAdjacencies collection;
+ private final RelationNodeAdjacencies collection = new RelationNodeAdjacencies();
@Before
public void init() {
MockitoAnnotations.initMocks(this);
- collection = new RelationNodeAdjacencies();
-
collection.add(TYPE_1, dirty);
collection.add(TYPE_2, clean);
collection.add(TYPE_3, deleted);
when(dirty.isDirty()).thenReturn(true);
-
+ when(dirty.getModificationType()).thenReturn(ModificationType.NEW);
+ when(clean.getModificationType()).thenReturn(ModificationType.NEW);
when(deleted.getModificationType()).thenReturn(ModificationType.ARTIFACT_DELETED);
when(deleted.isDeleted()).thenReturn(true);
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicates.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicates.java
index d78da3c3cb..e6854c6a4f 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicates.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/util/OrcsPredicates.java
@@ -15,6 +15,8 @@ import static com.google.common.base.Predicates.contains;
import static com.google.common.base.Predicates.containsPattern;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not;
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
import java.util.regex.Pattern;
import org.eclipse.osee.framework.core.data.HasLocalId;
import org.eclipse.osee.framework.core.enums.DeletionFlag;
@@ -25,8 +27,6 @@ import org.eclipse.osee.orcs.core.internal.attribute.Attribute;
import org.eclipse.osee.orcs.core.internal.relation.Relation;
import org.eclipse.osee.orcs.data.HasDeleteState;
import org.eclipse.osee.orcs.data.Modifiable;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
/**
* @author Roberto E. Escobar
@@ -145,8 +145,7 @@ public final class OrcsPredicates {
if (flag == DeletionFlag.INCLUDE_HARD_DELETED) {
result = true;
- } else if (flag == DeletionFlag.INCLUDE_DELETED && ModificationType.getAllNotHardDeletedTypes().contains(
- modificationType)) {
+ } else if (flag == DeletionFlag.INCLUDE_DELETED && !modificationType.isHardDeleted()) {
result = true;
} else {
result = !data.isDeleted();

Back to the top