public MapPSet<E> plusAll(final Collection<? extends E> list) { PMap<E,Object> map = this.map; for(E e : list) map = map.plus(e, In.IN); return from(map); }
public void testSerializationForMapPSet() { final MapPSet<String> initialMapPSet = HashTreePSet.<String> empty() .plus(ELEMENT1) .plus(ELEMENT2) .plus(ELEMENT3); final byte[] serializedMapPSet = serializeToByteArray(initialMapPSet); assertNotNull(serializedMapPSet); assertTrue(serializedMapPSet.length > 0); @SuppressWarnings("unchecked") final MapPSet<String> deserializedMapPSet = deserializeFromByteArray(serializedMapPSet, MapPSet.class); assertNotNull(deserializedMapPSet); assertEquals(3, deserializedMapPSet.size()); assertNotSame(initialMapPSet, deserializedMapPSet); assertTrue(deserializedMapPSet.containsAll(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3))); assertTrue(deserializedMapPSet.minus(ELEMENT1).minus(ELEMENT2).minus(ELEMENT3).isEmpty()); }
public void testSet() { PSet<String> a = HashTreePSet.empty(), b = HashTreePSet.empty(); assertEqualsAndHash("empty sets not equal",a,b); assertTrue("adding element should change empty set",!a.equals(a.plus("one"))); a = a.plus("one"); assertEqualsAndHash("adding duplicate should not change set",a,a.plus("one")); a = a.plus("two").plus(""); b = b.plus("two").plus("").plus("one").plus("two"); assertEqualsAndHash(a,b); b = b.plus("three"); assertTrue(!a.equals(b)); int n = b.size(); for(@SuppressWarnings("unused") String s : b) n--; assertTrue("iterator() should return size() elements", n==0); assertEqualsAndHash("adding a set to itself should do nothing",b,b.plusAll(b)); assertEqualsAndHash("adding a set to the empty set should be identity", b, MapPSet.from(HashTreePMap.<String,Object>empty(), b)); // bug Mike found: assertEqualsAndHash(HashTreePSet.from(Arrays.asList(2)), HashTreePSet.empty().plus(1).plus(2).minus(1)); }
/** * @param <E> * @param list * @return empty().plusAll(map) */ public static <E> MapPSet<E> from(final Collection<? extends E> list) { return HashTreePSet.<E>empty().plusAll(list); } }
/** * @param <E> * @param e * @return empty().plus(e) */ public static <E> MapPSet<E> singleton(final E e) { return HashTreePSet.<E>empty().plus(e); }
/** * @param <E> * @param map * @return a PSet with the elements of map.keySet(), backed by map */ @SuppressWarnings("unchecked") public static <E> MapPSet<E> from(final PMap<E,?> map) { return new MapPSet<E>((PMap<E,Object>)map); }
public MapPSet<E> minusAll(final Collection<?> list) { PMap<E,Object> map = this.map.minusAll(list); return from(map); } }
/** * @param <E> * @param list * @return empty().plusAll(map) */ public static <E> MapPSet<E> from(final Collection<? extends E> list) { return HashTreePSet.<E>empty().plusAll(list); } }
/** * @param <E> * @param e * @return empty().plus(e) */ public static <E> MapPSet<E> singleton(final E e) { return HashTreePSet.<E>empty().plus(e); }
/** * @param <E> * @param map * @return a PSet with the elements of map.keySet(), backed by map */ @SuppressWarnings("unchecked") public static <E> MapPSet<E> from(final PMap<E,?> map) { return new MapPSet<E>((PMap<E,Object>)map); }
public MapPSet<E> minusAll(final Collection<?> list) { PMap<E,Object> map = this.map.minusAll(list); return from(map); } }
/** * @param <E> * @param list * @return empty().plusAll(map) */ public static <E> MapPSet<E> from(final Collection<? extends E> list) { return HashTreePSet.<E>empty().plusAll(list); } }
/** * @param <E> * @param e * @return empty().plus(e) */ public static <E> MapPSet<E> singleton(final E e) { return HashTreePSet.<E>empty().plus(e); }
/** * @param <E> * @param map * @return a PSet with the elements of map.keySet(), backed by map */ @SuppressWarnings("unchecked") public static <E> MapPSet<E> from(final PMap<E,?> map) { return new MapPSet<E>((PMap<E,Object>)map); }