summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwilk2011-04-19 17:17:08 (EDT)
committerRyan D. Brooks2011-04-19 17:17:08 (EDT)
commit0506c439cef8015ec648b71123a1f3f6e8e16de0 (patch)
tree183553bf0648acae9f5237ebc35d473af757859d
parent62cdeb9af32443a9a28cef8d51648bdc72322329 (diff)
downloadorg.eclipse.osee-0506c439cef8015ec648b71123a1f3f6e8e16de0.zip
org.eclipse.osee-0506c439cef8015ec648b71123a1f3f6e8e16de0.tar.gz
org.eclipse.osee-0506c439cef8015ec648b71123a1f3f6e8e16de0.tar.bz2
refactor: Add of java doc and test to Collections.setComplement() and removal of Collections.asCollection(T arg)
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/CollectionsTest.java19
-rw-r--r--plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java36
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java4
-rw-r--r--plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XWidgetAccessDecorationProvider.java4
4 files changed, 46 insertions, 17 deletions
diff --git a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/CollectionsTest.java b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/CollectionsTest.java
index 588bfd5..3b10a8d 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/CollectionsTest.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core.test/src/org/eclipse/osee/framework/jdk/core/test/util/CollectionsTest.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.jdk.core.test.util;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import org.junit.Assert;
import org.eclipse.osee.framework.jdk.core.util.Collections;
@@ -21,6 +22,7 @@ import org.junit.Test;
* @author Donald G. Dunne
*/
public class CollectionsTest {
+
@Test
public void moveItem() {
@@ -86,6 +88,23 @@ public class CollectionsTest {
}
+ @Test
+ public void test_setComplement() throws Exception {
+ Collection<Integer> A = Arrays.asList(1, 2, 3, 8);
+ Collection<Integer> B = Arrays.asList(1, 3, 5, 15, 20);
+
+ Collection<Integer> complementSet = Collections.setComplement(A, B);
+ Assert.assertTrue(complementSet.size() == 2);
+ Assert.assertTrue(complementSet.contains(2));
+ Assert.assertTrue(complementSet.contains(8));
+
+ complementSet = Collections.setComplement(B, A);
+ Assert.assertTrue(complementSet.size() == 3);
+ Assert.assertTrue(complementSet.contains(5));
+ Assert.assertTrue(complementSet.contains(15));
+ Assert.assertTrue(complementSet.contains(20));
+ }
+
private List<String> getTestList() {
List<String> newList = new ArrayList<String>();
newList.addAll(Arrays.asList("A", "B", "C", "D", "E"));
diff --git a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java
index 9ddfc93..889ba92 100644
--- a/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java
+++ b/plugins/org.eclipse.osee.framework.jdk.core/src/org/eclipse/osee/framework/jdk/core/util/Collections.java
@@ -95,14 +95,30 @@ public class Collections {
}
/**
- * The resultant set is those elements in superSet which are not in the subSet
+ * <p>
+ * Meaning:
+ * <li>elements outside of B
+ * <li>all elements unique to A
+ * </p>
*
- * @return Return complement list reference
+ * @return relative set complement of B in A.
+ * <p>
+ * <br/>
+ * Noted:<br/>
+ * A - B
+ * </p>
+ * <p>
+ * <br/>
+ * Examples:<br/>
+ * { 1, 2, 3 } - { 1, 4, 3 } = { 2 } <br/>
+ * <br/>
+ * { 1, 4, 3 } - { 1, 2, 3 } = { 4 }
+ * </p>
*/
- public static <T> List<T> setComplement(Collection<T> superSet, Collection<T> subList) {
- ArrayList<T> complement = new ArrayList<T>(superSet.size());
- for (T obj : superSet) {
- if (!subList.contains(obj)) {
+ public static <T> List<T> setComplement(Collection<T> set_A, Collection<T> set_B) {
+ ArrayList<T> complement = new ArrayList<T>(set_A.size());
+ for (T obj : set_A) {
+ if (!set_B.contains(obj)) {
complement.add(obj);
}
}
@@ -124,7 +140,7 @@ public class Collections {
}
/**
- * Returns the unique union of the given lists
+ * @return union of unique elements from the given lists
*/
public static <T> Set<T> setUnion(Collection<T>... lists) {
Set<T> union = new HashSet<T>(lists[0].size() * 2);
@@ -261,12 +277,6 @@ public class Collections {
return cast(clazz, objects, CastOption.MATCHING);
}
- public static <T extends Object> Collection<T> asCollection(T arg) {
- Collection<T> ret = new ArrayList<T>();
- ret.add(arg);
- return ret;
- }
-
public static <A extends Object> boolean moveItem(List<A> currentOrder, A itemToAdd, A targetItem, boolean insertAfter) {
int newIndex = currentOrder.indexOf(targetItem);
if (newIndex < 0 || newIndex > currentOrder.size() - 1) {
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java
index 5d1d694..3f63c84 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/blam/operation/RelationOrderRepairBlam.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.ui.skynet.blam.operation;
import java.io.IOException;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.CoreException;
@@ -24,7 +25,6 @@ import org.eclipse.osee.framework.core.exception.OseeTypeDoesNotExist;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.jdk.core.type.Pair;
-import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.skynet.core.relation.RelationTypeManager;
@@ -63,7 +63,7 @@ public class RelationOrderRepairBlam extends AbstractBlam {
@Override
public Collection<String> getCategories() {
- return Collections.asCollection("Admin");
+ return Collections.singletonList("Admin");
}
@Override
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XWidgetAccessDecorationProvider.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XWidgetAccessDecorationProvider.java
index ddd67bc..fe4b25b 100644
--- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XWidgetAccessDecorationProvider.java
+++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/widgets/XWidgetAccessDecorationProvider.java
@@ -53,7 +53,7 @@ public class XWidgetAccessDecorationProvider implements XWidgetDecorator.Decorat
try {
Artifact artifact = attributeWidget.getArtifact();
permissionStatus =
- policyHandlerService.hasAttributeTypePermission(Collections.singleton(artifact), attributeType,
+ policyHandlerService.hasAttributeTypePermission(Collections.singletonList(artifact), attributeType,
PermissionEnum.WRITE, Level.FINE);
} catch (OseeCoreException ex) {
OseeLog.log(SkynetGuiPlugin.class, Level.SEVERE, ex);
@@ -77,4 +77,4 @@ public class XWidgetAccessDecorationProvider implements XWidgetDecorator.Decorat
decorator.setVisible(isLocked);
}
}
-}; \ No newline at end of file
+};