public void testPlusMinus() { POrderedSet<Integer> s = Empty.orderedSet(); s = s.plus(3).plus(2).plus(1).minus(1).plus(2).plus(3).minus(17) .plus(5).plus(1).plus(4); int vals[] = new int[] { 3, 2, 5, 1, 4 }; assertEquals(vals.length, s.size()); Iterator<Integer> it = s.iterator(); for (int i = 0; i < vals.length; i++) { assertEquals(vals[i], s.get(i).intValue()); assertEquals(vals[i], it.next().intValue()); } }
/** * @param o * @return * @see org.pcollections.POrderedSet#indexOf(java.lang.Object) */ public int indexOf(Object o) { return set.indexOf(o); }
public void testBehavesLikePSet() { PSet<Integer> s = Empty.set(); POrderedSet<Integer> os = Empty.orderedSet(); Random r = new Random(); for (int i = 0; i < 100000; i++) { int v = r.nextInt(1000); if (r.nextFloat() < 0.8) { s = s.plus(v); os = os.plus(v); } else { s = s.minus(v); os = os.minus(v); } } assertEquals(s, os); } }
/** * @param e * @return * @see org.pcollections.MapPSet#plus(java.lang.Object) */ public POrderedSetX<T> plus(T e) { return new POrderedSetXImpl<>(set.plus(e)); }
/** * @param list * @return * @see org.pcollections.MapPSet#plusAll(java.util.Collection) */ public POrderedSetX<T> plusAll(Collection<? extends T> list) { return new POrderedSetXImpl<>(set.plusAll(list)); }
/** * @param e * @return * @see org.pcollections.MapPSet#minus(java.lang.Object) */ public POrderedSetX<T> minus(Object e) { return new POrderedSetXImpl<>(set.minus(e)); }
/** * @param index * @return * @see org.pcollections.POrderedSet#get(int) */ public T get(int index) { return set.get(index); }
/** * @param list * @return * @see org.pcollections.MapPSet#minusAll(java.util.Collection) */ public POrderedSetX<T> minusAll(Collection<?> list) { return new POrderedSetXImpl<>(set.minusAll(list)); }
/** * @return * @see org.pcollections.MapPSet#iterator() */ public Iterator<T> iterator() { return set.iterator(); }
/** * @return * @see org.pcollections.MapPSet#size() */ public int size() { return set.size(); }
@Override public OrderedSetX<T> plus(T e) { return from(get().plus(e)); }
@Override public OrderedSetX<T> plusAll(Collection<? extends T> list) { return from(get().plusAll(list)); }
@Override public OrderedSetX<T> minus(Object remove) { return from(get().minus(remove)); }
@Override public T get(int index) { return get().get(index); }
@Override public OrderedSetX<T> minusAll(Collection<?> list) { return from(get().minusAll(list)); }
public void testPlus() { POrderedSet<Integer> s = Empty.orderedSet(); s = s.plus(3).plus(2).plus(1).plus(1).plus(2).plus(3).plus(4); int vals[] = new int[] { 3, 2, 1, 4 }; assertEquals(vals.length, s.size()); Iterator<Integer> it = s.iterator(); for (int i = 0; i < vals.length; i++) { assertEquals(vals[i], s.get(i).intValue()); assertEquals(vals[i], it.next().intValue()); } }
public Fork increment(String flowId, int diff) { int c; Integer cobj = flowCounts.get(flowId); if (cobj == null) { c = 0; } else { c = cobj.intValue(); } return new Fork(flows.plus(flowId), flowCounts.plus(flowId, c + diff)); } }
public static <T> Monoid<POrderedSet<T>> toPOrderedSet() { return Monoid.<POrderedSet<T>>of(OrderedPSet.empty(), (POrderedSet<T> a) -> b -> a.plusAll(b), (T x) -> OrderedPSet.singleton(x)); } public static <T> Monoid<PBag<T>> toPBag() {
@Override public int indexOf(Object o) { return get().indexOf(o); }
/** * <pre> * {@code * POrderedSet<Integer> q = Reducers.<Integer>toPOrderedSet() .mapReduce(Stream.of(1,2,3,4)); * * } * </pre> * @return Reducer to POrderedSet */ public static <T> Reducer<POrderedSet<T>> toPOrderedSet() { return Reducer.<POrderedSet<T>> of(OrderedPSet.empty(), (final POrderedSet<T> a) -> b -> a.plusAll(b), (final T x) -> OrderedPSet.singleton(x)); } /**