Search in sources :

Example 1 with Sets.newHashSet

use of com.google.common.collect.Sets.newHashSet in project guava by google.

the class SetsTest method suite.

// suite
@GwtIncompatible
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SetsTest.class);
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            return Sets.newConcurrentHashSet(Arrays.asList(elements));
        }
    }).named("Sets.newConcurrentHashSet").withFeatures(CollectionSize.ANY, SetFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            int size = elements.length;
            // Remove last element, if size > 1
            Set<String> set1 = (size > 1) ? Sets.newHashSet(Arrays.asList(elements).subList(0, size - 1)) : Sets.newHashSet(elements);
            // Remove first element, if size > 0
            Set<String> set2 = (size > 0) ? Sets.newHashSet(Arrays.asList(elements).subList(1, size)) : Sets.<String>newHashSet();
            return Sets.union(set1, set2);
        }
    }).named("Sets.union").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set1 = Sets.newHashSet(elements);
            set1.add(samples().e3());
            Set<String> set2 = Sets.newHashSet(elements);
            set2.add(samples().e4());
            return Sets.intersection(set1, set2);
        }
    }).named("Sets.intersection").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set1 = Sets.newHashSet(elements);
            set1.add(samples().e3());
            Set<String> set2 = Sets.newHashSet(samples().e3());
            return Sets.difference(set1, set2);
        }
    }).named("Sets.difference").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestEnumSetGenerator() {

        @Override
        protected Set<AnEnum> create(AnEnum[] elements) {
            AnEnum[] otherElements = new AnEnum[elements.length - 1];
            System.arraycopy(elements, 1, otherElements, 0, otherElements.length);
            return Sets.immutableEnumSet(elements[0], otherElements);
        }
    }).named("Sets.immutableEnumSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            SafeTreeSet<String> set = new SafeTreeSet<String>(Arrays.asList(elements));
            return Sets.unmodifiableNavigableSet(set);
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Ordering.natural().sortedCopy(insertionOrder);
        }
    }).named("Sets.unmodifiableNavigableSet[TreeSet]").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER, CollectionFeature.SERIALIZABLE).createTestSuite());
    suite.addTest(testsForFilter());
    suite.addTest(testsForFilterNoNulls());
    suite.addTest(testsForFilterFiltered());
    return suite;
}
Also used : SortedSet(java.util.SortedSet) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) TestSuite(junit.framework.TestSuite) AnEnum(com.google.common.collect.testing.AnEnum) List(java.util.List) ArrayList(java.util.ArrayList) TestEnumSetGenerator(com.google.common.collect.testing.TestEnumSetGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 2 with Sets.newHashSet

use of com.google.common.collect.Sets.newHashSet in project jackrabbit-oak by apache.

the class ContentRemoteTreeTest method testGetChildrenWithSlicingAndFiltering.

@Test
public void testGetChildrenWithSlicingAndFiltering() {
    Tree bar = mock(Tree.class);
    doReturn("bar").when(bar).getName();
    Tree foo = mock(Tree.class);
    doReturn("foo").when(foo).getName();
    Tree baz = mock(Tree.class);
    doReturn("baz").when(baz).getName();
    Tree tree = mock(Tree.class);
    doReturn(asList(bar, foo, baz)).when(tree).getChildren();
    ContentRemoteTree remoteTree = createTree(tree, new RemoteTreeFilters() {

        @Override
        public Set<String> getNodeFilters() {
            return Sets.newHashSet("ba*");
        }

        @Override
        public int getChildrenStart() {
            return 1;
        }

        @Override
        public int getChildrenCount() {
            return 1;
        }
    });
    Map<String, RemoteTree> children = remoteTree.getChildren();
    assertFalse(children.containsKey("bar"));
    assertFalse(children.containsKey("foo"));
    assertFalse(children.containsKey("baz"));
}
Also used : Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Set(java.util.Set) RemoteTreeFilters(org.apache.jackrabbit.oak.remote.RemoteTreeFilters) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) Tree(org.apache.jackrabbit.oak.api.Tree) RemoteTree(org.apache.jackrabbit.oak.remote.RemoteTree) Test(org.junit.Test)

Example 3 with Sets.newHashSet

use of com.google.common.collect.Sets.newHashSet in project guava by hceylan.

the class SetsTest method suite.

@GwtIncompatible("suite")
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(SetsTest.class);
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            int size = elements.length;
            // Remove last element, if size > 1
            Set<String> set1 = (size > 1) ? Sets.newHashSet(Arrays.asList(elements).subList(0, size - 1)) : Sets.newHashSet(elements);
            // Remove first element, if size > 0
            Set<String> set2 = (size > 0) ? Sets.newHashSet(Arrays.asList(elements).subList(1, size)) : Sets.<String>newHashSet();
            return Sets.union(set1, set2);
        }
    }).named("Sets.union").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set1 = Sets.newHashSet(elements);
            set1.add(samples().e3);
            Set<String> set2 = Sets.newHashSet(elements);
            set2.add(samples().e4);
            return Sets.intersection(set1, set2);
        }
    }).named("Sets.intersection").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set1 = Sets.newHashSet(elements);
            set1.add(samples().e3);
            Set<String> set2 = Sets.newHashSet(samples().e3);
            return Sets.difference(set1, set2);
        }
    }).named("Sets.difference").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestEnumSetGenerator() {

        @Override
        protected Set<AnEnum> create(AnEnum[] elements) {
            AnEnum[] otherElements = new AnEnum[elements.length - 1];
            System.arraycopy(elements, 1, otherElements, 0, otherElements.length);
            return Sets.immutableEnumSet(elements[0], otherElements);
        }
    }).named("Sets.immutableEnumSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            SafeTreeSet<String> set = new SafeTreeSet<String>(Arrays.asList(elements));
            return Sets.unmodifiableNavigableSet(set);
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Ordering.natural().sortedCopy(insertionOrder);
        }
    }).named("Sets.unmodifiableNavigableSet[TreeSet]").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER).createTestSuite());
    suite.addTest(NavigableSetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            SafeTreeSet<String> set = new SafeTreeSet<String>(Arrays.asList(elements));
            return SerializableTester.reserialize(Sets.unmodifiableNavigableSet(set));
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            return Ordering.natural().sortedCopy(insertionOrder);
        }
    }).named("Sets.unmodifiableNavigableSet[TreeSet], reserialized").withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER).createTestSuite());
    suite.addTest(testsForFilter());
    suite.addTest(testsForFilterNoNulls());
    suite.addTest(testsForFilterFiltered());
    return suite;
}
Also used : SortedSet(java.util.SortedSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) TestSuite(junit.framework.TestSuite) AnEnum(com.google.common.collect.testing.AnEnum) List(java.util.List) ArrayList(java.util.ArrayList) TestEnumSetGenerator(com.google.common.collect.testing.TestEnumSetGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

Sets.newHashSet (com.google.common.collect.Sets.newHashSet)3 Set (java.util.Set)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 Sets.newEnumSet (com.google.common.collect.Sets.newEnumSet)2 Sets.powerSet (com.google.common.collect.Sets.powerSet)2 AnEnum (com.google.common.collect.testing.AnEnum)2 SafeTreeSet (com.google.common.collect.testing.SafeTreeSet)2 TestEnumSetGenerator (com.google.common.collect.testing.TestEnumSetGenerator)2 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)2 ArrayList (java.util.ArrayList)2 Collections.emptySet (java.util.Collections.emptySet)2 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 SortedSet (java.util.SortedSet)2 TreeSet (java.util.TreeSet)2 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)2 TestSuite (junit.framework.TestSuite)2 Sets.newLinkedHashSet (com.google.common.collect.Sets.newLinkedHashSet)1