/** * Either converts the given set to an IntSet if it is one or creates a new IntSet and copies the contents * @param set * @return */ public static SmallIntSet from(Set<Integer> set) { if (set instanceof SmallIntSet) { return (SmallIntSet) set; } else { return new SmallIntSet(set); } }
/** * Returns a mutable IntSet with no values set. Note this mutable set is initialized given a default size. If you wish * to not have less initialization over, please use {@link #mutableEmptySet(int)} providing a {@code 0} or similar. * @return IntSet with no values set */ public static IntSet mutableEmptySet() { return new SmallIntSet(); }
/** * Returns an IntSet that contains no values but is initialized to hold ints equal to the {@code maxExclusive -1} or * smaller. * @param maxExclusive largest int expected in set * @return IntSet with no values set */ public static IntSet mutableEmptySet(int maxExclusive) { return new SmallIntSet(maxExclusive); }
public static SmallIntSet of(PrimitiveIterator.OfInt iterator) { SmallIntSet set = new SmallIntSet(); iterator.forEachRemaining((IntConsumer) set::set); return set; }
/** * Returns an IntSet that contains all ints from the given Set that is mutable. Updates to the original Set or * the returned IntSet are not reflected in the other. * @param mutableSet set to copy from * @return IntSet with the values set */ public static IntSet mutableCopyFrom(Set<Integer> mutableSet) { if (mutableSet instanceof SingletonIntSet) { return mutableSet(((SingletonIntSet) mutableSet).value); } return new SmallIntSet(mutableSet); }
public static SmallIntSet of(int i1) { SmallIntSet set = new SmallIntSet(i1 + 1); set.set(i1); return set; }
public static SmallIntSet of(int... elements) { SmallIntSet set = new SmallIntSet(elements.length); for (int i : elements) { set.set(i); } return set; }
public static SmallIntSet of(int i1, int i2) { SmallIntSet set = new SmallIntSet(Math.max(i1, i2) + 1); set.set(i1); set.set(i2); return set; }
public static SmallIntSet of(int i1, int i2, int i3) { SmallIntSet set = new SmallIntSet(); set.set(i1); set.set(i2); set.set(i3); return set; }
public static SmallIntSet readFrom(ObjectInput input) throws IOException { int capacity = UnsignedNumeric.readUnsignedInt(input); int size = UnsignedNumeric.readUnsignedInt(input); SmallIntSet set = new SmallIntSet(capacity); for (int i = 0; i < size; i++) { int element = UnsignedNumeric.readUnsignedInt(input); set.set(element); } return set; } }
@Test(expected = UnsupportedOperationException.class) public void testAddAll1() throws Exception { SmallIntSet sis2 = new SmallIntSet(); es.addAll(sis2); }
@Parameterized.Parameters public static Object[] data() { return new Object[] { new SmallIntSet(), new ConcurrentSmallIntSet(64), }; }
@Test(expected = UnsupportedOperationException.class) public void addAll1() throws Exception { RangeSet rs = new RangeSet(4); SmallIntSet sis = new SmallIntSet(); rs.addAll(sis); }
@Test(expected = UnsupportedOperationException.class) public void removeAll1() throws Exception { RangeSet rs = new RangeSet(5); SmallIntSet sis = new SmallIntSet(); rs.removeAll(sis); }
@Test(expected = UnsupportedOperationException.class) public void retainAll1() throws Exception { IntSet rs = new RangeSet(5); SmallIntSet sis = new SmallIntSet(); rs.retainAll(sis); }
@Test(expected = UnsupportedOperationException.class) public void testAddAll1() throws Exception { IntSet sis = new SingletonIntSet(3); SmallIntSet sis2 = new SmallIntSet(); sis.addAll(sis2); }
@Test public void testEquals() throws Exception { IntSet sis2 = new SingletonIntSet(4); // Verify equals both ways assertNotEquals(es, sis2); assertNotEquals(sis2, es); // This is empty, just sets the range IntSet sis3 = new SmallIntSet(2); assertEquals(sis3, es); assertEquals(es, sis3); }
@Test public void testAddAll() throws Exception { intSet.add(1); intSet.add(4); IntSet intSet2 = new SmallIntSet(); intSet2.addAll(intSet); assertEquals(2, intSet2.size()); }
@Test public void testEquals1() throws Exception { SmallIntSet sis2 = new SmallIntSet(); sis2.add(2); // Verify equals both ways assertNotEquals(es, sis2); assertNotEquals(sis2, es); sis2.remove(2); assertEquals(es, sis2); assertEquals(sis2, es); }
@Test public void testContainsAll() throws Exception { IntSet intSet2 = new SmallIntSet(); intSet.add(1); intSet.add(4); intSet2.add(1); intSet2.add(4); intSet2.add(7); assertFalse(intSet.containsAll(intSet2)); assertTrue(intSet2.containsAll(intSet)); }