src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
TypeToken extends TypeCapture<T> implements Serializable { public final TypeToken<?> resolveType(Type type) { TypeResolver resolver = typeResolver; if (resolver == null) { resolver = (typeResolver = TypeResolver.accordingTo(runtimeType)); } return of(resolver.resolveType(type)); } protected TypeToken(); private TypeT...
@Test public void testResolveType() throws Exception { TypeToken<HashMap<String, Integer>> mapToken = new TypeToken<HashMap<String, Integer>>() { }; TypeToken<?> entrySetToken = mapToken.resolveType(Map.class.getMethod("entrySet").getGenericReturnType()); assertThat(entrySetToken.toString(), equalTo("java.util.Set<java...
ListUtils { public static <E> List<E> selectRejected(final Collection<? extends E> inputCollection, final Predicate<? super E> predicate) { return CollectionUtils.selectRejected(inputCollection, predicate, new ArrayList<E>(inputCollection.size())); } private ListUtils(); static List<T> emptyIfNull(final List<T> list);...
@Test @SuppressWarnings("boxing") public void testSelectRejected() { final List<Long> list = new ArrayList<Long>(); list.add(1L); list.add(2L); list.add(3L); list.add(4L); final List<Long> output1 = ListUtils.selectRejected(list, EQUALS_TWO); final List<? extends Number> output2 = ListUtils.selectRejected(list, EQUALS_...
MultiMapUtils { public static boolean isEmpty(final MultiValuedMap<?, ?> map) { return map == null || map.isEmpty(); } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K...
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testEmptyUnmodifiableMultiValuedMap() { final MultiValuedMap map = MultiMapUtils.EMPTY_MULTI_VALUED_MAP; assertTrue(map.isEmpty()); try { map.put("key", "value"); fail("Should throw UnsupportedOperationException"); } catch (UnsupportedOperationException e...
MultiMapUtils { @SuppressWarnings("unchecked") public static <K, V> MultiValuedMap<K, V> emptyIfNull(final MultiValuedMap<K, V> map) { return map == null ? EMPTY_MULTI_VALUED_MAP : map; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unche...
@Test public void testEmptyIfNull() { assertTrue(MultiMapUtils.emptyIfNull(null).isEmpty()); final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); map.put("item", "value"); assertFalse(MultiMapUtils.emptyIfNull(map).isEmpty()); }
MultiMapUtils { public static <K, V> Collection<V> getCollection(final MultiValuedMap<K, V> map, final K key) { if (map != null) { return map.get(key); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static MultiValuedMap<K, V> emptyMultiValuedMap(); @SuppressWarnings("unchecked") static Multi...
@Test public void testGetCollection() { assertNull(MultiMapUtils.getCollection(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); } Collection<String> col = MultiMapUtils.getCo...
MultiMapUtils { public static <K, V> List<V> getValuesAsList(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof List) { return (List<V>) col; } return new ArrayList<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") stat...
@Test public void testGetValuesAsList() { assertNull(MultiMapUtils.getValuesAsList(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); } List<String> list = MultiMapUtils.getVal...
MultiMapUtils { public static <K, V> Set<V> getValuesAsSet(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Set) { return (Set<V>) col; } return new HashSet<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static Mul...
@Test public void testGetValuesAsSet() { assertNull(MultiMapUtils.getValuesAsList(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); map.put("key1", val); } Set<String> set = M...
MultiMapUtils { public static <K, V> Bag<V> getValuesAsBag(final MultiValuedMap<K, V> map, final K key) { if (map != null) { Collection<V> col = map.get(key); if (col instanceof Bag) { return (Bag<V>) col; } return new HashBag<V>(col); } return null; } private MultiMapUtils(); @SuppressWarnings("unchecked") static Mul...
@Test public void testGetValuesAsBag() { assertNull(MultiMapUtils.getValuesAsBag(null, "key1")); String values[] = { "v1", "v2", "v3" }; final MultiValuedMap<String, String> map = new ArrayListValuedHashMap<String, String>(); for (String val : values) { map.put("key1", val); map.put("key1", val); } Bag<String> bag = Mu...
SetUtils { public static <E> Set<E> predicatedSet(final Set<E> set, final Predicate<? super E> predicate) { return PredicatedSet.predicatedSet(set, predicate); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set...
@Test public void testpredicatedSet() { final Predicate<Object> predicate = new Predicate<Object>() { @Override public boolean evaluate(final Object o) { return o instanceof String; } }; Set<Object> set = SetUtils.predicatedSet(new HashSet<Object>(), predicate); assertTrue("returned object should be a PredicatedSet", s...
SetUtils { public static <T> Set<T> emptyIfNull(final Set<T> set) { return set == null ? Collections.<T>emptySet() : set; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set); sta...
@Test public void testEmptyIfNull() { assertTrue(SetUtils.emptyIfNull(null).isEmpty()); final Set<Long> set = new HashSet<Long>(); assertSame(set, SetUtils.emptyIfNull(set)); }
SetUtils { public static boolean isEqualSet(final Collection<?> set1, final Collection<?> set2) { if (set1 == set2) { return true; } if (set1 == null || set2 == null || set1.size() != set2.size()) { return false; } return set1.containsAll(set2); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchec...
@Test public void testEquals() { final Collection<String> data = Arrays.asList("a", "b", "c"); final Set<String> a = new HashSet<String>(data); final Set<String> b = new HashSet<String>(data); assertEquals(true, a.equals(b)); assertEquals(true, SetUtils.isEqualSet(a, b)); a.clear(); assertEquals(false, SetUtils.isEqual...
SetUtils { public static <T> int hashCodeForSet(final Collection<T> set) { if (set == null) { return 0; } int hashCode = 0; for (final T obj : set) { if (obj != null) { hashCode += obj.hashCode(); } } return hashCode; } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for...
@Test public void testHashCode() { final Collection<String> data = Arrays.asList("a", "b", "c"); final Set<String> a = new HashSet<String>(data); final Set<String> b = new HashSet<String>(data); assertEquals(true, a.hashCode() == b.hashCode()); assertEquals(true, a.hashCode() == SetUtils.hashCodeForSet(a)); assertEqual...
SetUtils { public static <E> Set<E> newIdentityHashSet() { return Collections.newSetFromMap(new IdentityHashMap<E, Boolean>()); } private SetUtils(); static Set<E> emptySet(); @SuppressWarnings("unchecked") // empty set is OK for any type static SortedSet<E> emptySortedSet(); static Set<T> emptyIfNull(final Set<T> set...
@Test public void testNewIdentityHashSet() { Set<String> set = SetUtils.newIdentityHashSet(); String a = new String("a"); set.add(a); set.add(new String("b")); set.add(a); assertEquals(2, set.size()); set.add(new String("a")); assertEquals(3, set.size()); set.remove(a); assertEquals(2, set.size()); }
SetUtils { public static <E> SetView<E> union(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Override public boolean contains(Object o) { return a.cont...
@Test public void union() { final SetView<Integer> set = SetUtils.union(setA, setB); assertEquals(7, set.size()); assertTrue(set.containsAll(setA)); assertTrue(set.containsAll(setB)); final Set<Integer> set2 = SetUtils.union(setA, SetUtils.<Integer>emptySet()); assertEquals(setA, set2); try { SetUtils.union(setA, null)...
SetUtils { public static <E> SetView<E> difference(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> notContainedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return !b.contains(ob...
@Test public void difference() { final SetView<Integer> set = SetUtils.difference(setA, setB); assertEquals(2, set.size()); assertTrue(set.contains(1)); assertTrue(set.contains(2)); for (Integer i : setB) { assertFalse(set.contains(i)); } final Set<Integer> set2 = SetUtils.difference(setA, SetUtils.<Integer>emptySet())...
SetUtils { public static <E> SetView<E> intersection(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final Predicate<E> containedInB = new Predicate<E>() { @Override public boolean evaluate(E object) { return b.contains(obje...
@Test public void intersection() { final SetView<Integer> set = SetUtils.intersection(setA, setB); assertEquals(3, set.size()); assertTrue(set.contains(3)); assertTrue(set.contains(4)); assertTrue(set.contains(5)); assertFalse(set.contains(1)); assertFalse(set.contains(2)); assertFalse(set.contains(6)); assertFalse(set...
SetUtils { public static <E> SetView<E> disjunction(final Set<? extends E> a, final Set<? extends E> b) { if (a == null || b == null) { throw new NullPointerException("Sets must not be null."); } final SetView<E> aMinusB = difference(a, b); final SetView<E> bMinusA = difference(b, a); return new SetView<E>() { @Overrid...
@Test public void disjunction() { final SetView<Integer> set = SetUtils.disjunction(setA, setB); assertEquals(4, set.size()); assertTrue(set.contains(1)); assertTrue(set.contains(2)); assertTrue(set.contains(6)); assertTrue(set.contains(7)); assertFalse(set.contains(3)); assertFalse(set.contains(4)); assertFalse(set.co...
FactoryUtils { public static <T> Factory<T> exceptionFactory() { return ExceptionFactory.<T>exceptionFactory(); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T protot...
@Test public void testExceptionFactory() { assertNotNull(FactoryUtils.exceptionFactory()); assertSame(FactoryUtils.exceptionFactory(), FactoryUtils.exceptionFactory()); try { FactoryUtils.exceptionFactory().create(); } catch (final FunctorException ex) { try { FactoryUtils.exceptionFactory().create(); } catch (final Fu...
FactoryUtils { public static <T> Factory<T> nullFactory() { return ConstantFactory.<T>constantFactory(null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> prototypeFactory(final T prototype...
@Test public void testNullFactory() { final Factory<Object> factory = FactoryUtils.nullFactory(); assertNotNull(factory); final Object created = factory.create(); assertNull(created); }
FactoryUtils { public static <T> Factory<T> constantFactory(final T constantToReturn) { return ConstantFactory.constantFactory(constantToReturn); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<...
@Test public void testConstantFactoryNull() { final Factory<Object> factory = FactoryUtils.constantFactory(null); assertNotNull(factory); final Object created = factory.create(); assertNull(created); } @Test public void testConstantFactoryConstant() { final Integer constant = Integer.valueOf(9); final Factory<Integer> ...
FactoryUtils { public static <T> Factory<T> prototypeFactory(final T prototype) { return PrototypeFactory.<T>prototypeFactory(prototype); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T constantToReturn); static Factory<T> proto...
@Test public void testPrototypeFactoryNull() { assertSame(ConstantFactory.NULL_INSTANCE, FactoryUtils.prototypeFactory(null)); } @Test public void testPrototypeFactoryPublicCloneMethod() throws Exception { final Date proto = new Date(); final Factory<Date> factory = FactoryUtils.prototypeFactory(proto); assertNotNull(f...
FactoryUtils { public static <T> Factory<T> instantiateFactory(final Class<T> classToInstantiate) { return InstantiateFactory.instantiateFactory(classToInstantiate, null, null); } private FactoryUtils(); static Factory<T> exceptionFactory(); static Factory<T> nullFactory(); static Factory<T> constantFactory(final T co...
@Test(expected=NullPointerException.class) public void instantiateFactoryNull() { FactoryUtils.instantiateFactory(null); } @Test public void instantiateFactorySimple() { final Factory<Mock3> factory = FactoryUtils.instantiateFactory(Mock3.class); assertNotNull(factory); Mock3 created = factory.create(); assertEquals(0,...
ComparatorUtils { public static Comparator<Boolean> booleanComparator(final boolean trueFirst) { return BooleanComparator.booleanComparator(trueFirst); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> naturalComparator(); static Comparator<E> chainedComparator(final Comparator<E>... com...
@Test public void booleanComparator() { Comparator<Boolean> comp = ComparatorUtils.booleanComparator(true); assertTrue(comp.compare(Boolean.TRUE, Boolean.FALSE) < 0); assertTrue(comp.compare(Boolean.TRUE, Boolean.TRUE) == 0); assertTrue(comp.compare(Boolean.FALSE, Boolean.TRUE) > 0); comp = ComparatorUtils.booleanCompa...
ComparatorUtils { public static <E> Comparator<E> chainedComparator(final Comparator<E>... comparators) { final ComparatorChain<E> chain = new ComparatorChain<E>(); for (final Comparator<E> comparator : comparators) { if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } chain.addComp...
@Test public void chainedComparator() { Comparator<Integer> comp = ComparatorUtils.chainedComparator(ComparatorUtils.<Integer>naturalComparator(), ComparatorUtils.<Integer>naturalComparator()); assertTrue(comp.compare(1, 2) < 0); assertTrue(comp.compare(1, 1) == 0); assertTrue(comp.compare(2, 1) > 0); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E max(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c > 0 ? o1 : o2; } private ComparatorUtils(); @SuppressWarnings("unchecked") static ...
@Test public void max() { Comparator<Integer> reversed = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); assertEquals(Integer.valueOf(10), ComparatorUtils.max(1, 10, null)); assertEquals(Integer.valueOf(10), ComparatorUtils.max(10, -10, null)); assertEquals(Integer.valueOf(1), Comparat...
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> E min(final E o1, final E o2, Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } final int c = comparator.compare(o1, o2); return c < 0 ? o1 : o2; } private ComparatorUtils(); @SuppressWarnings("unchecked") static ...
@Test public void min() { Comparator<Integer> reversed = ComparatorUtils.reversedComparator(ComparatorUtils.<Integer>naturalComparator()); assertEquals(Integer.valueOf(1), ComparatorUtils.min(1, 10, null)); assertEquals(Integer.valueOf(-10), ComparatorUtils.min(10, -10, null)); assertEquals(Integer.valueOf(10), Compara...
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullLowComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, false); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> n...
@Test public void nullLowComparator() { Comparator<Integer> comp = ComparatorUtils.nullLowComparator(null); assertTrue(comp.compare(null, 10) < 0); assertTrue(comp.compare(null, null) == 0); assertTrue(comp.compare(10, null) > 0); }
ComparatorUtils { @SuppressWarnings("unchecked") public static <E> Comparator<E> nullHighComparator(Comparator<E> comparator) { if (comparator == null) { comparator = NATURAL_COMPARATOR; } return new NullComparator<E>(comparator, true); } private ComparatorUtils(); @SuppressWarnings("unchecked") static Comparator<E> n...
@Test public void nullHighComparator() { Comparator<Integer> comp = ComparatorUtils.nullHighComparator(null); assertTrue(comp.compare(null, 10) > 0); assertTrue(comp.compare(null, null) == 0); assertTrue(comp.compare(10, null) < 0); }
IteratorUtils { public static <E> Iterable<E> asIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, false); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static Resett...
@Test public void testAsIterable() { final List<Integer> list = new ArrayList<Integer>(); list.add(Integer.valueOf(0)); list.add(Integer.valueOf(1)); list.add(Integer.valueOf(2)); final Iterator<Integer> iterator = list.iterator(); final Iterable<Integer> iterable = IteratorUtils.asIterable(iterator); int expected = 0;...
IteratorUtils { public static <E> Iterable<E> asMultipleUseIterable(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } return new IteratorIterable<E>(iterator, true); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); sta...
@Test public void testAsMultipleIterable() { final List<Integer> list = new ArrayList<Integer>(); list.add(Integer.valueOf(0)); list.add(Integer.valueOf(1)); list.add(Integer.valueOf(2)); final Iterator<Integer> iterator = list.iterator(); final Iterable<Integer> iterable = IteratorUtils.asMultipleUseIterable(iterator)...
IteratorUtils { public static <E> List<E> toList(final Iterator<? extends E> iterator) { return toList(iterator, 10); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterator<K, V>...
@Test public void testToList() { final List<Object> list = new ArrayList<Object>(); list.add(Integer.valueOf(1)); list.add("Two"); list.add(null); final List<Object> result = IteratorUtils.toList(list.iterator()); assertEquals(list, result); }
IteratorUtils { public static Object[] toArray(final Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } final List<?> list = toList(iterator, 100); return list.toArray(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static Resettab...
@Test public void testToArray() { final List<Object> list = new ArrayList<Object>(); list.add(Integer.valueOf(1)); list.add("Two"); list.add(null); final Object[] result = IteratorUtils.toArray(list.iterator()); assertEquals(list, Arrays.asList(result)); } @Test public void testToArray2() { final List<String> list = ne...
IteratorUtils { public static <E> ResettableIterator<E> arrayIterator(final E... array) { return new ObjectArrayIterator<E>(array); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static Map...
@Test public void testArrayIterator() { final Object[] objArray = {"a", "b", "c"}; ResettableIterator<Object> iterator = IteratorUtils.arrayIterator(objArray); assertTrue(iterator.next().equals("a")); assertTrue(iterator.next().equals("b")); iterator.reset(); assertTrue(iterator.next().equals("a")); try { iterator = It...
IteratorUtils { public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<E>(array); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator()...
@Test public void testArrayListIterator() { final Object[] objArray = {"a", "b", "c", "d"}; ResettableListIterator<Object> iterator = IteratorUtils.arrayListIterator(objArray); assertTrue(!iterator.hasPrevious()); assertTrue(iterator.previousIndex() == -1); assertTrue(iterator.nextIndex() == 0); assertTrue(iterator.nex...
IteratorUtils { public static <E> ResettableIterator<E> emptyIterator() { return EmptyIterator.<E>resettableEmptyIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterato...
@Test public void testEmptyIterator() { assertSame(EmptyIterator.INSTANCE, IteratorUtils.EMPTY_ITERATOR); assertSame(EmptyIterator.RESETTABLE_INSTANCE, IteratorUtils.EMPTY_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_ITERATOR instanceof Resettab...
IteratorUtils { public static <E> ResettableListIterator<E> emptyListIterator() { return EmptyListIterator.<E>resettableEmptyListIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); s...
@Test public void testEmptyListIterator() { assertSame(EmptyListIterator.INSTANCE, IteratorUtils.EMPTY_LIST_ITERATOR); assertSame(EmptyListIterator.RESETTABLE_INSTANCE, IteratorUtils.EMPTY_LIST_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_LIST_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_L...
IteratorUtils { public static <K, V> MapIterator<K, V> emptyMapIterator() { return EmptyMapIterator.<K, V>emptyMapIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static MapIterat...
@Test @SuppressWarnings("unchecked") public void testEmptyMapIterator() { assertSame(EmptyMapIterator.INSTANCE, IteratorUtils.EMPTY_MAP_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_MAP_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_MAP_ITERATOR instanceof MapIterator); assertEquals(true, Ite...
IteratorUtils { public static <E> OrderedIterator<E> emptyOrderedIterator() { return EmptyOrderedIterator.<E>emptyOrderedIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrderedIterator(); static Ma...
@Test @SuppressWarnings("unchecked") public void testEmptyOrderedIterator() { assertSame(EmptyOrderedIterator.INSTANCE, IteratorUtils.EMPTY_ORDERED_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_ITERATOR instanceof OrderedIterator)...
IteratorUtils { public static <K, V> OrderedMapIterator<K, V> emptyOrderedMapIterator() { return EmptyOrderedMapIterator.<K, V>emptyOrderedMapIterator(); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator<E> emptyListIterator(); static OrderedIterator<E> emptyOrdered...
@Test @SuppressWarnings("unchecked") public void testEmptyOrderedMapIterator() { assertSame(EmptyOrderedMapIterator.INSTANCE, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceof Iterator); assertEquals(true, IteratorUtils.EMPTY_ORDERED_MAP_ITERATOR instanceo...
IteratorUtils { public static NodeListIterator nodeListIterator(final NodeList nodeList) { if (nodeList == null) { throw new NullPointerException("NodeList must not be null"); } return new NodeListIterator(nodeList); } private IteratorUtils(); static ResettableIterator<E> emptyIterator(); static ResettableListIterator...
@Test public void testNodeListIterator() { final Node[] nodes = createNodes(); final NodeList nodeList = createNodeList(nodes); final Iterator<Node> iterator = IteratorUtils.nodeListIterator(nodeList); int expectedNodeIndex = 0; for (final Node actual : IteratorUtils.asIterable(iterator)) { assertEquals(nodes[expectedN...
IteratorUtils { public static <E> Iterator<E> collatedIterator(final Comparator<? super E> comparator, final Iterator<? extends E> iterator1, final Iterator<? extends E> iterator2) { @SuppressWarnings("unchecked") final Comparator<E> comp = comparator == null ? ComparatorUtils.NATURAL_COMPARATOR : (Comparator<E>) compa...
@Test public void testCollatedIterator() { try { IteratorUtils.collatedIterator(null, collectionOdd.iterator(), null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } try { IteratorUtils.collatedIterator(null, null, collectionEven.iterator()); fail("expecting NullPointerException"); } cat...
IteratorUtils { public static <E> void forEach(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); closure.execute(element); } } } priv...
@Test public void forEach() { final List<Integer> listA = new ArrayList<Integer>(); listA.add(1); final List<Integer> listB = new ArrayList<Integer>(); listB.add(2); final Closure<List<Integer>> testClosure = ClosureUtils.invokerClosure("clear"); final Collection<List<Integer>> col = new ArrayList<List<Integer>>(); col...
IteratorUtils { public static <E> E forEachButLast(final Iterator<E> iterator, final Closure<? super E> closure) { if (closure == null) { throw new NullPointerException("Closure must not be null."); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (iterator.hasNext()) { closu...
@Test public void forEachButLast() { final List<Integer> listA = new ArrayList<Integer>(); listA.add(1); final List<Integer> listB = new ArrayList<Integer>(); listB.add(2); final Closure<List<Integer>> testClosure = ClosureUtils.invokerClosure("clear"); final Collection<List<Integer>> col = new ArrayList<List<Integer>>...
IteratorUtils { public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { while (iterator.hasNext()) { final E element = iterator.next(); if (predicate.evaluate(element)) {...
@Test public void find() { Predicate<Number> testPredicate = equalPredicate((Number) 4); Integer test = IteratorUtils.find(iterableA.iterator(), testPredicate); assertTrue(test.equals(4)); testPredicate = equalPredicate((Number) 45); test = IteratorUtils.find(iterableA.iterator(), testPredicate); assertTrue(test == nul...
IteratorUtils { public static <E> int indexOf(final Iterator<E> iterator, final Predicate<? super E> predicate) { if (predicate == null) { throw new NullPointerException("Predicate must not be null"); } if (iterator != null) { for(int index = 0; iterator.hasNext(); index++) { final E element = iterator.next(); if (pred...
@Test public void indexOf() { Predicate<Number> testPredicate = equalPredicate((Number) 4); int index = IteratorUtils.indexOf(iterableA.iterator(), testPredicate); assertEquals(6, index); testPredicate = equalPredicate((Number) 45); index = IteratorUtils.indexOf(iterableA.iterator(), testPredicate); assertEquals(-1, in...
IteratorUtils { public static <E> E get(final Iterator<E> iterator, final int index) { int i = index; CollectionUtils.checkIndexBounds(i); while (iterator.hasNext()) { i--; if (i == -1) { return iterator.next(); } iterator.next(); } throw new IndexOutOfBoundsException("Entry does not exist: " + i); } private IteratorU...
@Test public void getFromIterator() throws Exception { Iterator<Integer> iterator = iterableA.iterator(); assertEquals(1, (int) IteratorUtils.get(iterator, 0)); iterator = iterableA.iterator(); assertEquals(2, (int) IteratorUtils.get(iterator, 1)); try { IteratorUtils.get(iterator, 10); fail("Expecting IndexOutOfBounds...
CollectionUtils { public static <O> Map<O, Integer> getCardinalityMap(final Iterable<? extends O> coll) { final Map<O, Integer> count = new HashMap<O, Integer>(); for (final O obj : coll) { final Integer c = count.get(obj); if (c == null) { count.put(obj, Integer.valueOf(1)); } else { count.put(obj, Integer.valueOf(c.i...
@Test public void getCardinalityMap() { final Map<Number, Integer> freqA = CollectionUtils.<Number>getCardinalityMap(iterableA); assertEquals(1, (int) freqA.get(1)); assertEquals(2, (int) freqA.get(2)); assertEquals(3, (int) freqA.get(3)); assertEquals(4, (int) freqA.get(4)); assertNull(freqA.get(5)); final Map<Long, I...
CollectionUtils { @Deprecated public static <O> int cardinality(final O obj, final Iterable<? super O> coll) { if (coll == null) { throw new NullPointerException("coll must not be null."); } return IterableUtils.frequency(coll, obj); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection i...
@Test @Deprecated public void cardinality() { assertEquals(1, CollectionUtils.cardinality(1, iterableA)); assertEquals(2, CollectionUtils.cardinality(2, iterableA)); assertEquals(3, CollectionUtils.cardinality(3, iterableA)); assertEquals(4, CollectionUtils.cardinality(4, iterableA)); assertEquals(0, CollectionUtils.ca...
CollectionUtils { public static boolean containsAll(final Collection<?> coll1, final Collection<?> coll2) { if (coll2.isEmpty()) { return true; } else { final Iterator<?> it = coll1.iterator(); final Set<Object> elementsAlreadySeen = new HashSet<Object>(); for (final Object nextElement : coll2) { if (elementsAlreadySee...
@Test public void containsAll() { final Collection<String> empty = new ArrayList<String>(0); final Collection<String> one = new ArrayList<String>(1); one.add("1"); final Collection<String> two = new ArrayList<String>(1); two.add("2"); final Collection<String> three = new ArrayList<String>(1); three.add("3"); final Coll...
CollectionUtils { public static boolean containsAny(final Collection<?> coll1, final Collection<?> coll2) { if (coll1.size() < coll2.size()) { for (final Object aColl1 : coll1) { if (coll2.contains(aColl1)) { return true; } } } else { for (final Object aColl2 : coll2) { if (coll1.contains(aColl2)) { return true; } } } ...
@Test public void containsAny() { final Collection<String> empty = new ArrayList<String>(0); final Collection<String> one = new ArrayList<String>(1); one.add("1"); final Collection<String> two = new ArrayList<String>(1); two.add("2"); final Collection<String> three = new ArrayList<String>(1); three.add("3"); final Coll...
CollectionUtils { public static <O> Collection<O> union(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj)); } return helper.list(); } private ...
@Test public void union() { final Collection<Integer> col = CollectionUtils.union(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertEquals(Integer.valueOf(1), freq.get(1)); assertEquals(Integer.valueOf(4), freq.get(2)); assertEquals(Integer.valueOf(3), freq.get(3));...
CollectionUtils { public static <O> Collection<O> intersection(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.min(obj)); } return helper.list(); } p...
@Test public void intersection() { final Collection<Integer> col = CollectionUtils.intersection(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertNull(freq.get(1)); assertEquals(Integer.valueOf(2), freq.get(2)); assertEquals(Integer.valueOf(3), freq.get(3)); assertE...
CollectionUtils { public static <O> Collection<O> disjunction(final Iterable<? extends O> a, final Iterable<? extends O> b) { final SetOperationCardinalityHelper<O> helper = new SetOperationCardinalityHelper<O>(a, b); for (final O obj : helper) { helper.setCardinality(obj, helper.max(obj) - helper.min(obj)); } return h...
@Test public void disjunction() { final Collection<Integer> col = CollectionUtils.disjunction(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertEquals(Integer.valueOf(1), freq.get(1)); assertEquals(Integer.valueOf(2), freq.get(2)); assertNull(freq.get(3)); assertEqu...
CollectionUtils { public static <O> Collection<O> subtract(final Iterable<? extends O> a, final Iterable<? extends O> b) { final Predicate<O> p = TruePredicate.truePredicate(); return subtract(a, b, p); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type stat...
@Test public void testSubtract() { final Collection<Integer> col = CollectionUtils.subtract(iterableA, iterableC); final Map<Integer, Integer> freq = CollectionUtils.getCardinalityMap(col); assertEquals(Integer.valueOf(1), freq.get(1)); assertNull(freq.get(2)); assertNull(freq.get(3)); assertEquals(Integer.valueOf(2), ...
CollectionUtils { public static boolean isSubCollection(final Collection<?> a, final Collection<?> b) { final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); for (final Object obj : a) { if (helper.freqA(obj) > helper.freqB(obj)) { return false; } } return true; } private CollectionUtils(); @Su...
@Test public void testIsSubCollectionOfSelf() { assertTrue(CollectionUtils.isSubCollection(collectionA, collectionA)); assertTrue(CollectionUtils.isSubCollection(collectionB, collectionB)); } @Test public void testIsSubCollection() { assertTrue(!CollectionUtils.isSubCollection(collectionA, collectionC)); assertTrue(!Co...
CollectionUtils { public static boolean isEqualCollection(final Collection<?> a, final Collection<?> b) { if(a.size() != b.size()) { return false; } final CardinalityHelper<Object> helper = new CardinalityHelper<Object>(a, b); if(helper.cardinalityA.size() != helper.cardinalityB.size()) { return false; } for( final Obj...
@Test public void testIsEqualCollectionToSelf() { assertTrue(CollectionUtils.isEqualCollection(collectionA, collectionA)); assertTrue(CollectionUtils.isEqualCollection(collectionB, collectionB)); } @Test public void testIsEqualCollection() { assertTrue(!CollectionUtils.isEqualCollection(collectionA, collectionC)); asse...
CollectionUtils { public static boolean isProperSubCollection(final Collection<?> a, final Collection<?> b) { return a.size() < b.size() && CollectionUtils.isSubCollection(a, b); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCo...
@Test public void testIsProperSubCollection() { final Collection<String> a = new ArrayList<String>(); final Collection<String> b = new ArrayList<String>(); assertTrue(!CollectionUtils.isProperSubCollection(a, b)); b.add("1"); assertTrue(CollectionUtils.isProperSubCollection(a, b)); assertTrue(!CollectionUtils.isProperS...
CollectionUtils { @Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate) { return predicate != null ? IterableUtils.find(collection, predicate) : null; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type stati...
@Test @Deprecated public void find() { Predicate<Number> testPredicate = equalPredicate((Number) 4); Integer test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test.equals(4)); testPredicate = equalPredicate((Number) 45); test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test == null)...
CollectionUtils { @Deprecated public static <T, C extends Closure<? super T>> C forAllDo(final Iterable<T> collection, final C closure) { if (closure != null) { IterableUtils.forEach(collection, closure); } return closure; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatibl...
@Test(expected = FunctorException.class) @Deprecated public void forAllDoFailure() { final Closure<String> testClosure = ClosureUtils.invokerClosure("clear"); final Collection<String> col = new ArrayList<String>(); col.add("x"); CollectionUtils.forAllDo(col, testClosure); }
QueryOperator extends AbstractOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return execute(context, stat); } QueryOperator(ASTRootNode rootNode, MethodDescriptor md, Config config); @Override Object e...
@Test public void testQueryObject() throws Exception { TypeToken<User> t = TypeToken.of(User.class); String srcSql = "select * from user where id=:1.id and name=:1.name"; AbstractOperator operator = getOperator(t, t, srcSql, new ArrayList<Annotation>()); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Overrid...
CollectionUtils { @Deprecated public static <T> T get(final Iterator<T> iterator, final int index) { return IteratorUtils.get(iterator, index); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unch...
@Test public void getFromMap() { final Map<String, String> expected = new HashMap<String, String>(); expected.put("zeroKey", "zero"); expected.put("oneKey", "one"); final Map<String, String> found = new HashMap<String, String>(); Map.Entry<String, String> entry = CollectionUtils.get(expected, 0); found.put(entry.getKey...
CollectionUtils { public static int size(final Object object) { if (object == null) { return 0; } int total = 0; if (object instanceof Map<?,?>) { total = ((Map<?, ?>) object).size(); } else if (object instanceof Collection<?>) { total = ((Collection<?>) object).size(); } else if (object instanceof Iterable<?>) { total...
@Test public void testSize_List() { List<String> list = null; assertEquals(0, CollectionUtils.size(list)); list = new ArrayList<String>(); assertEquals(0, CollectionUtils.size(list)); list.add("a"); assertEquals(1, CollectionUtils.size(list)); list.add("b"); assertEquals(2, CollectionUtils.size(list)); } @Test public v...
CollectionUtils { public static boolean sizeIsEmpty(final Object object) { if (object == null) { return true; } else if (object instanceof Collection<?>) { return ((Collection<?>) object).isEmpty(); } else if (object instanceof Iterable<?>) { return IterableUtils.isEmpty((Iterable<?>) object); } else if (object instanc...
@Test public void testSizeIsEmpty_Null() { assertEquals(true, CollectionUtils.sizeIsEmpty(null)); } @Test public void testSizeIsEmpty_List() { final List<String> list = new ArrayList<String>(); assertEquals(true, CollectionUtils.sizeIsEmpty(list)); list.add("a"); assertEquals(false, CollectionUtils.sizeIsEmpty(list)); ...
TypeToken extends TypeCapture<T> implements Serializable { Set<TypeToken<?>> getTypes() { Set<TypeToken<?>> tokens = new HashSet<TypeToken<?>>(); tokens.add(this); TypeToken<?> superclass = getGenericSuperclass(); if (superclass != null) { tokens.add(superclass); tokens.addAll(superclass.getTypes()); } List<TypeToken<?...
@Test public void testGetTypes() throws Exception { TypeToken<HashMap<String, Integer>> t = new TypeToken<HashMap<String, Integer>>() { }; Set<TypeToken<?>> types = t.getTypes(); assertThat(types.size(), equalTo(6)); types.contains(new TypeToken<Map<String, Integer>>() { }); types.contains(new TypeToken<HashMap<String,...
CollectionUtils { public static boolean isEmpty(final Collection<?> coll) { return coll == null || coll.isEmpty(); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collecti...
@Test public void testIsEmptyWithEmptyCollection() { final Collection<Object> coll = new ArrayList<Object>(); assertEquals(true, CollectionUtils.isEmpty(coll)); } @Test public void testIsEmptyWithNonEmptyCollection() { final Collection<String> coll = new ArrayList<String>(); coll.add("item"); assertEquals(false, Collec...
CollectionUtils { public static boolean isNotEmpty(final Collection<?> coll) { return !isEmpty(coll); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, empty collection is compati...
@Test public void testIsNotEmptyWithEmptyCollection() { final Collection<Object> coll = new ArrayList<Object>(); assertEquals(false, CollectionUtils.isNotEmpty(coll)); } @Test public void testIsNotEmptyWithNonEmptyCollection() { final Collection<String> coll = new ArrayList<String>(); coll.add("item"); assertEquals(tru...
CollectionUtils { public static <T> boolean filter(final Iterable<T> collection, final Predicate<? super T> predicate) { boolean result = false; if (collection != null && predicate != null) { for (final Iterator<T> it = collection.iterator(); it.hasNext();) { if (!predicate.evaluate(it.next())) { it.remove(); result = ...
@Test public void filter() { final List<Integer> ints = new ArrayList<Integer>(); ints.add(1); ints.add(2); ints.add(3); ints.add(3); final Iterable<Integer> iterable = ints; assertTrue(CollectionUtils.filter(iterable, EQUALS_TWO)); assertEquals(1, ints.size()); assertEquals(2, (int) ints.get(0)); }
CollectionUtils { public static <T> boolean filterInverse(final Iterable<T> collection, final Predicate<? super T> predicate) { return filter(collection, predicate == null ? null : PredicateUtils.notPredicate(predicate)); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible...
@Test public void filterInverse() { final List<Integer> ints = new ArrayList<Integer>(); ints.add(1); ints.add(2); ints.add(3); ints.add(3); final Iterable<Integer> iterable = ints; assertTrue(CollectionUtils.filterInverse(iterable, EQUALS_TWO)); assertEquals(3, ints.size()); assertEquals(1, (int) ints.get(0)); assertE...
CollectionUtils { @Deprecated public static <C> int countMatches(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? 0 : (int) IterableUtils.countMatches(input, predicate); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any...
@Test @Deprecated public void countMatches() { assertEquals(4, CollectionUtils.countMatches(iterableB, EQUALS_TWO)); assertEquals(0, CollectionUtils.countMatches(iterableA, null)); assertEquals(0, CollectionUtils.countMatches(null, EQUALS_TWO)); assertEquals(0, CollectionUtils.countMatches(null, null)); }
CollectionUtils { @Deprecated public static <C> boolean exists(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAny(input, predicate); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type ...
@Test @Deprecated public void exists() { final List<Integer> list = new ArrayList<Integer>(); assertFalse(CollectionUtils.exists(null, null)); assertFalse(CollectionUtils.exists(list, null)); assertFalse(CollectionUtils.exists(null, EQUALS_TWO)); assertFalse(CollectionUtils.exists(list, EQUALS_TWO)); list.add(1); list....
CollectionUtils { public static <O> Collection<O> select(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return select(inputCollec...
@Test public void select() { final List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); list.add(4); final Collection<Integer> output1 = CollectionUtils.select(list, EQUALS_TWO); final Collection<Number> output2 = CollectionUtils.<Number>select(list, EQUALS_TWO); final HashSet<Number> o...
CollectionUtils { public static <O> Collection<O> selectRejected(final Iterable<? extends O> inputCollection, final Predicate<? super O> predicate) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return selectReje...
@Test public void selectRejected() { final List<Long> list = new ArrayList<Long>(); list.add(1L); list.add(2L); list.add(3L); list.add(4L); final Collection<Long> output1 = CollectionUtils.selectRejected(list, EQUALS_TWO); final Collection<? extends Number> output2 = CollectionUtils.selectRejected(list, EQUALS_TWO); fi...
CollectionUtils { public static <I, O> Collection<O> collect(final Iterable<I> inputCollection, final Transformer<? super I, ? extends O> transformer) { final Collection<O> answer = inputCollection instanceof Collection<?> ? new ArrayList<O>(((Collection<?>) inputCollection).size()) : new ArrayList<O>(); return collect...
@Test public void collect() { final Transformer<Number, Long> transformer = TransformerUtils.constantTransformer(2L); Collection<Number> collection = CollectionUtils.<Integer, Number>collect(iterableA, transformer); assertTrue(collection.size() == collectionA.size()); assertCollectResult(collection); ArrayList<Number> ...
CollectionUtils { public static <T> boolean addIgnoreNull(final Collection<T> collection, final T object) { if (collection == null) { throw new NullPointerException("The collection must not be null"); } return object != null && collection.add(object); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, ...
@Test public void addIgnoreNull() { final Set<String> set = new HashSet<String>(); set.add("1"); set.add("2"); set.add("3"); assertFalse(CollectionUtils.addIgnoreNull(set, null)); assertEquals(3, set.size()); assertFalse(CollectionUtils.addIgnoreNull(set, "1")); assertEquals(3, set.size()); assertEquals(true, Collectio...
CollectionUtils { public static <C> Collection<C> predicatedCollection(final Collection<C> collection, final Predicate<? super C> predicate) { return PredicatedCollection.predicatedCollection(collection, predicate); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with ...
@Test public void predicatedCollection() { final Predicate<Object> predicate = PredicateUtils.instanceofPredicate(Integer.class); Collection<Number> collection = CollectionUtils.predicatedCollection(new ArrayList<Number>(), predicate); assertTrue("returned object should be a PredicatedCollection", collection instanceof...
CollectionUtils { public static boolean isFull(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).isFull(); } try { final BoundedCollection<?> bcoll = Unmodifiab...
@Test public void isFull() { final Set<String> set = new HashSet<String>(); set.add("1"); set.add("2"); set.add("3"); try { CollectionUtils.isFull(null); fail(); } catch (final NullPointerException ex) { } assertFalse(CollectionUtils.isFull(set)); final CircularFifoQueue<String> buf = new CircularFifoQueue<String>(set)...
CollectionUtils { public static int maxSize(final Collection<? extends Object> coll) { if (coll == null) { throw new NullPointerException("The collection must not be null"); } if (coll instanceof BoundedCollection) { return ((BoundedCollection<?>) coll).maxSize(); } try { final BoundedCollection<?> bcoll = Unmodifiable...
@Test public void maxSize() { final Set<String> set = new HashSet<String>(); set.add("1"); set.add("2"); set.add("3"); try { CollectionUtils.maxSize(null); fail(); } catch (final NullPointerException ex) { } assertEquals(-1, CollectionUtils.maxSize(set)); final Queue<String> buf = new CircularFifoQueue<String>(set); as...
CollectionUtils { public static <C> Collection<C> retainAll(final Collection<C> collection, final Collection<?> retain) { return ListUtils.retainAll(collection, retain); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(...
@Test public void testRetainAll() { final List<String> base = new ArrayList<String>(); base.add("A"); base.add("B"); base.add("C"); final List<Object> sub = new ArrayList<Object>(); sub.add("A"); sub.add("C"); sub.add("X"); final Collection<String> result = CollectionUtils.retainAll(base, sub); assertEquals(2, result.s...
CollectionUtils { public static <E> Collection<E> removeAll(final Collection<E> collection, final Collection<?> remove) { return ListUtils.removeAll(collection, remove); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(...
@Test public void testRemoveAll() { final List<String> base = new ArrayList<String>(); base.add("A"); base.add("B"); base.add("C"); final List<String> sub = new ArrayList<String>(); sub.add("A"); sub.add("C"); sub.add("X"); final Collection<String> result = CollectionUtils.removeAll(base, sub); assertEquals(1, result.s...
CollectionUtils { public static <E> Collection<E> transformingCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer) { return TransformedCollection.transformingCollection(collection, transformer); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collec...
@Test public void testTransformedCollection() { final Transformer<Object, Object> transformer = TransformerUtils.nopTransformer(); Collection<Object> collection = CollectionUtils.transformingCollection(new ArrayList<Object>(), transformer); assertTrue("returned object should be a TransformedCollection", collection inst...
CollectionUtils { @Deprecated public static <C> Collection<C> synchronizedCollection(final Collection<C> collection) { return SynchronizedCollection.synchronizedCollection(collection); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> e...
@Test @Deprecated public void testSynchronizedCollection() { Collection<Object> col = CollectionUtils.synchronizedCollection(new ArrayList<Object>()); assertTrue("Returned object should be a SynchronizedCollection.", col instanceof SynchronizedCollection); try { CollectionUtils.synchronizedCollection(null); fail("Expec...
CollectionUtils { @Deprecated public static <C> Collection<C> unmodifiableCollection(final Collection<? extends C> collection) { return UnmodifiableCollection.unmodifiableCollection(collection); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Colle...
@Test @Deprecated public void testUnmodifiableCollection() { Collection<Object> col = CollectionUtils.unmodifiableCollection(new ArrayList<Object>()); assertTrue("Returned object should be a UnmodifiableCollection.", col instanceof UnmodifiableCollection); try { CollectionUtils.unmodifiableCollection(null); fail("Expec...
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyCollection() { return EMPTY_COLLECTION; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> emptyCollection(); @SuppressWarnings("unchecked") // OK, emp...
@Test public void emptyCollection() throws Exception { final Collection<Number> coll = CollectionUtils.emptyCollection(); assertEquals(CollectionUtils.EMPTY_COLLECTION, coll); }
CollectionUtils { @SuppressWarnings("unchecked") public static <T> Collection<T> emptyIfNull(final Collection<T> collection) { return collection == null ? EMPTY_COLLECTION : collection; } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type static Collection<T> ...
@Test public void emptyIfNull() { assertTrue(CollectionUtils.emptyIfNull(null).isEmpty()); final Collection<Object> collection = new ArrayList<Object>(); assertSame(collection, CollectionUtils.emptyIfNull(collection)); }
CollectionUtils { public static <C> boolean addAll(final Collection<C> collection, final Iterable<? extends C> iterable) { if (iterable instanceof Collection<?>) { return collection.addAll((Collection<? extends C>) iterable); } return addAll(collection, iterable.iterator()); } private CollectionUtils(); @SuppressWarni...
@Test public void addAllForIterable() { final Collection<Integer> inputCollection = createMock(Collection.class); final Iterable<Integer> inputIterable = inputCollection; final Iterable<Long> iterable = createMock(Iterable.class); final Iterator<Long> iterator = createMock(Iterator.class); final Collection<Number> c = ...
CollectionUtils { public static <E> E extractSingleton(final Collection<E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null."); } if (collection.size() != 1) { throw new IllegalArgumentException("Can extract singleton only when collection size == 1"); } return collecti...
@Test public void extractSingleton() { ArrayList<String> coll = null; try { CollectionUtils.extractSingleton(coll); fail("expected NullPointerException from extractSingleton(null)"); } catch (final NullPointerException e) { } coll = new ArrayList<String>(); try { CollectionUtils.extractSingleton(coll); fail("expected I...
CollectionUtils { public static <O extends Comparable<? super O>> List<O> collate(Iterable<? extends O> a, Iterable<? extends O> b) { return collate(a, b, ComparatorUtils.<O>naturalComparator(), true); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any type stati...
@Test(expected=NullPointerException.class) public void collateException1() { CollectionUtils.collate(collectionA, null); } @Test(expected=NullPointerException.class) public void collateException2() { CollectionUtils.collate(collectionA, collectionC, null); } @Test public void testCollate() { List<Integer> result = Coll...
CollectionUtils { public static <E> Collection<List<E>> permutations(final Collection<E> collection) { final PermutationIterator<E> it = new PermutationIterator<E>(collection); final Collection<List<E>> result = new LinkedList<List<E>>(); while (it.hasNext()) { result.add(it.next()); } return result; } private Collect...
@Test(expected=NullPointerException.class) public void testPermutationsWithNullCollection() { CollectionUtils.permutations(null); } @Test public void testPermutations() { List<Integer> sample = collectionA.subList(0, 5); Collection<List<Integer>> permutations = CollectionUtils.permutations(sample); int collSize = sampl...
CollectionUtils { @Deprecated public static <C> boolean matchesAll(final Iterable<C> input, final Predicate<? super C> predicate) { return predicate == null ? false : IterableUtils.matchesAll(input, predicate); } private CollectionUtils(); @SuppressWarnings("unchecked") // OK, empty collection is compatible with any t...
@Test @Deprecated public void testMatchesAll() { assertFalse(CollectionUtils.matchesAll(null, null)); assertFalse(CollectionUtils.matchesAll(collectionA, null)); Predicate<Integer> lessThanFive = new Predicate<Integer>() { @Override public boolean evaluate(Integer object) { return object < 5; } }; assertTrue(Collection...
LazySortedMap extends LazyMap<K,V> implements SortedMap<K,V> { public static <K, V> LazySortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { return new LazySortedMap<K,V>(map, factory); } protected LazySortedMap(final SortedMap<K,V> map, final Factory<? extends V> factory); pr...
@Test public void mapGet() { Map<Integer, Number> map = lazySortedMap(new TreeMap<Integer,Number>(), oneFactory); assertEquals(0, map.size()); final Number i1 = map.get(5); assertEquals(1, i1); assertEquals(1, map.size()); map = lazySortedMap(new TreeMap<Integer,Number>(), FactoryUtils.<Number>nullFactory()); final Num...
TransformerUtils { public static <I, O> Transformer<I, O> exceptionTransformer() { return ExceptionTransformer.exceptionTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer...
@Test public void testExceptionTransformer() { assertNotNull(TransformerUtils.exceptionTransformer()); assertSame(TransformerUtils.exceptionTransformer(), TransformerUtils.exceptionTransformer()); try { TransformerUtils.exceptionTransformer().transform(null); } catch (final FunctorException ex) { try { TransformerUtils...
TransformerUtils { public static <I, O> Transformer<I, O> nullTransformer() { return ConstantTransformer.nullTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> clon...
@Test public void testNullTransformer() { assertNotNull(TransformerUtils.nullTransformer()); assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer()); assertEquals(null, TransformerUtils.nullTransformer().transform(null)); assertEquals(null, TransformerUtils.nullTransformer().transform(cObject...
TransformerUtils { public static <T> Transformer<T, T> nopTransformer() { return NOPTransformer.nopTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransform...
@Test public void testNopTransformer() { assertNotNull(TransformerUtils.nullTransformer()); assertSame(TransformerUtils.nullTransformer(), TransformerUtils.nullTransformer()); assertEquals(null, TransformerUtils.nopTransformer().transform(null)); assertEquals(cObject, TransformerUtils.nopTransformer().transform(cObject...
TransformerUtils { public static <I, O> Transformer<I, O> constantTransformer(final O constantToReturn) { return ConstantTransformer.constantTransformer(constantToReturn); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T>...
@Test public void testConstantTransformer() { assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(null)); assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cObject)); assertEquals(cObject, TransformerUtils.constantTransformer(cObject).transform(cString)); assertEqua...
LocalCacheHandler extends SimpleCacheHandler { public Object get(String key) { return get(key, null); } LocalCacheHandler(); LocalCacheHandler(Ticker ticker); Object get(String key); Map<String, Object> getBulk(Set<String> keys); @Override Object get(String key, Type type); @Override Map<String, Object> getBulk(Set<St...
@Test public void testGet() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; cache.set(key, value, seconds); assertThat((String) cache.get(key), equalTo(value)); t.addSeconds(seconds + 1); assertThat(...
TransformerUtils { public static <T> Transformer<T, T> cloneTransformer() { return CloneTransformer.cloneTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTra...
@Test public void testCloneTransformer() { assertEquals(null, TransformerUtils.cloneTransformer().transform(null)); assertEquals(cString, TransformerUtils.cloneTransformer().transform(cString)); assertEquals(cInteger, TransformerUtils.cloneTransformer().transform(cInteger)); try { assertEquals(cObject, TransformerUtils...
TransformerUtils { public static <I, O> Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map) { return MapTransformer.mapTransformer(map); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer...
@Test @SuppressWarnings("boxing") public void testMapTransformer() { final Map<Object, Integer> map = new HashMap<Object, Integer>(); map.put(null, 0); map.put(cObject, 1); map.put(cString, 2); assertEquals(Integer.valueOf(0), TransformerUtils.mapTransformer(map).transform(null)); assertEquals(Integer.valueOf(1), Trans...
TransformerUtils { public static <T> Transformer<T, T> asTransformer(final Closure<? super T> closure) { return ClosureTransformer.closureTransformer(closure); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransfor...
@Test public void testExecutorTransformer() { assertEquals(null, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(null)); assertEquals(cObject, TransformerUtils.asTransformer(ClosureUtils.nopClosure()).transform(cObject)); assertEquals(cString, TransformerUtils.asTransformer(ClosureUtils.nopClosure()...
TransformerUtils { public static <T> Transformer<T, T> chainedTransformer( final Transformer<? super T, ? extends T>... transformers) { return ChainedTransformer.chainedTransformer(transformers); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); ...
@Test @SuppressWarnings("unchecked") public void testChainedTransformer() { final Transformer<Object, Object> a = TransformerUtils.<Object, Object>constantTransformer("A"); final Transformer<Object, Object> b = TransformerUtils.constantTransformer((Object) "B"); assertEquals("A", TransformerUtils.chainedTransformer(b, ...
TransformerUtils { public static <T> Transformer<T, T> ifTransformer(final Predicate<? super T> predicate, final Transformer<? super T, ? extends T> trueTransformer) { return IfTransformer.ifTransformer(predicate, trueTransformer); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static T...
@Test public void testIfTransformer() { final Transformer<Object, String> a = TransformerUtils.constantTransformer("A"); final Transformer<Object, String> b = TransformerUtils.constantTransformer("B"); final Transformer<Object, String> c = TransformerUtils.constantTransformer("C"); assertEquals("A", TransformerUtils.if...