src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
|---|---|
TransformerUtils { @SuppressWarnings("unchecked") @Deprecated public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? super I> predicate, final Transformer<? super I, ? extends O> trueTransformer, final Transformer<? super I, ? extends O> falseTransformer) { return SwitchTransformer.switchTransformer(new Predicate[] { predicate }, new Transformer[] { trueTransformer }, falseTransformer); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Transformer<T, String> stringValueTransformer(); }
|
@Test @SuppressWarnings("unchecked") public void testSwitchTransformer() { final Transformer<String, String> a = TransformerUtils.constantTransformer("A"); final Transformer<String, String> b = TransformerUtils.constantTransformer("B"); final Transformer<String, String> c = TransformerUtils.constantTransformer("C"); assertEquals("A", TransformerUtils.switchTransformer(TruePredicate.truePredicate(), a, b).transform(null)); assertEquals("B", TransformerUtils.switchTransformer(FalsePredicate.falsePredicate(), a, b).transform(null)); assertEquals(null, TransformerUtils.<Object, String>switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }).transform("WELL")); assertEquals("A", TransformerUtils.switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }).transform("HELLO")); assertEquals("B", TransformerUtils.switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }).transform("THERE")); assertEquals("C", TransformerUtils.switchTransformer( new Predicate[] { EqualPredicate.equalPredicate("HELLO"), EqualPredicate.equalPredicate("THERE") }, new Transformer[] { a, b }, c).transform("WELL")); Map<Predicate<String>, Transformer<String, String>> map = new HashMap<Predicate<String>, Transformer<String,String>>(); map.put(EqualPredicate.equalPredicate("HELLO"), a); map.put(EqualPredicate.equalPredicate("THERE"), b); assertEquals(null, TransformerUtils.switchTransformer(map).transform("WELL")); assertEquals("A", TransformerUtils.switchTransformer(map).transform("HELLO")); assertEquals("B", TransformerUtils.switchTransformer(map).transform("THERE")); map.put(null, c); assertEquals("C", TransformerUtils.switchTransformer(map).transform("WELL")); assertEquals(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchTransformer(new Predicate[0], new Transformer[0])); assertEquals(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchTransformer(new HashMap<Predicate<Object>, Transformer<Object, Object>>())); map = new HashMap<Predicate<String>, Transformer<String, String>>(); map.put(null, null); assertEquals(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchTransformer(map)); try { TransformerUtils.switchTransformer(null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer((Predicate[]) null, (Transformer[]) null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer((Map<Predicate<Object>, Transformer<Object, Object>>) null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer(new Predicate[2], new Transformer[2]); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.switchTransformer( new Predicate[] { TruePredicate.truePredicate() }, new Transformer[] { a, b }); fail(); } catch (final IllegalArgumentException ex) {} }
|
TransformerUtils { @SuppressWarnings("unchecked") public static <I, O> Transformer<I, O> switchMapTransformer( final Map<I, Transformer<I, O>> objectsAndTransformers) { if (objectsAndTransformers == null) { throw new NullPointerException("The object and transformer map must not be null"); } final Transformer<? super I, ? extends O> def = objectsAndTransformers.remove(null); final int size = objectsAndTransformers.size(); final Transformer<? super I, ? extends O>[] trs = new Transformer[size]; final Predicate<I>[] preds = new Predicate[size]; int i = 0; for (final Map.Entry<I, Transformer<I, O>> entry : objectsAndTransformers.entrySet()) { preds[i] = EqualPredicate.<I>equalPredicate(entry.getKey()); trs[i++] = entry.getValue(); } return TransformerUtils.switchTransformer(preds, trs, def); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Transformer<T, String> stringValueTransformer(); }
|
@Test public void testSwitchMapTransformer() { final Transformer<String, String> a = TransformerUtils.constantTransformer("A"); final Transformer<String, String> b = TransformerUtils.constantTransformer("B"); final Transformer<String, String> c = TransformerUtils.constantTransformer("C"); Map<String, Transformer<String, String>> map = new HashMap<String, Transformer<String,String>>(); map.put("HELLO", a); map.put("THERE", b); assertEquals(null, TransformerUtils.switchMapTransformer(map).transform("WELL")); assertEquals("A", TransformerUtils.switchMapTransformer(map).transform("HELLO")); assertEquals("B", TransformerUtils.switchMapTransformer(map).transform("THERE")); map.put(null, c); assertEquals("C", TransformerUtils.switchMapTransformer(map).transform("WELL")); assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchMapTransformer(new HashMap<Object, Transformer<Object, Object>>())); map = new HashMap<String, Transformer<String, String>>(); map.put(null, null); assertSame(ConstantTransformer.NULL_INSTANCE, TransformerUtils.switchMapTransformer(map)); try { TransformerUtils.switchMapTransformer(null); fail(); } catch (final NullPointerException ex) {} }
|
TransformerUtils { public static <I, O> Transformer<I, O> invokerTransformer(final String methodName) { return InvokerTransformer.invokerTransformer(methodName, null, null); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Transformer<T, String> stringValueTransformer(); }
|
@Test public void testInvokerTransformer() { final List<Object> list = new ArrayList<Object>(); assertEquals(Integer.valueOf(0), TransformerUtils.invokerTransformer("size").transform(list)); list.add(new Object()); assertEquals(Integer.valueOf(1), TransformerUtils.invokerTransformer("size").transform(list)); assertEquals(null, TransformerUtils.invokerTransformer("size").transform(null)); try { TransformerUtils.invokerTransformer(null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.invokerTransformer("noSuchMethod").transform(new Object()); fail(); } catch (final FunctorException ex) {} }
@Test public void testInvokerTransformer2() { final List<Object> list = new ArrayList<Object>(); assertEquals(Boolean.FALSE, TransformerUtils.invokerTransformer("contains", new Class[] { Object.class }, new Object[] { cString }).transform(list)); list.add(cString); assertEquals(Boolean.TRUE, TransformerUtils.invokerTransformer("contains", new Class[] { Object.class }, new Object[] { cString }).transform(list)); assertEquals(null, TransformerUtils.invokerTransformer("contains", new Class[] { Object.class }, new Object[] { cString }).transform(null)); try { TransformerUtils.invokerTransformer(null, null, null); fail(); } catch (final NullPointerException ex) {} try { TransformerUtils.invokerTransformer("noSuchMethod", new Class[] { Object.class }, new Object[] { cString }).transform(new Object()); fail(); } catch (final FunctorException ex) {} try { TransformerUtils.invokerTransformer("badArgs", null, new Object[] { cString }); fail(); } catch (final IllegalArgumentException ex) {} try { TransformerUtils.invokerTransformer("badArgs", new Class[] { Object.class }, null); fail(); } catch (final IllegalArgumentException ex) {} try { TransformerUtils.invokerTransformer("badArgs", new Class[] {}, new Object[] { cString }); fail(); } catch (final IllegalArgumentException ex) {} }
|
LocalCacheHandler extends SimpleCacheHandler { public Map<String, Object> getBulk(Set<String> keys) { return getBulk(keys, 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<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
|
@Test public void testGetBulk() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; int seconds2 = 200; String key2 = "key2"; String value2 = "value2"; cache.set(key, value, seconds); cache.set(key2, value2, seconds2); Set<String> keys = Sets.newHashSet(key, key2); Map<String, Object> map = cache.getBulk(keys); assertThat(map.size(), equalTo(2)); assertThat((String) map.get(key), equalTo(value)); assertThat((String) map.get(key2), equalTo(value2)); t.addSeconds(seconds + 1); map = cache.getBulk(keys); assertThat(map.size(), equalTo(1)); assertThat((String) map.get(key2), equalTo(value2)); t.reset(); t.addSeconds(seconds2 + 1); map = cache.getBulk(keys); assertThat(map.size(), equalTo(0)); }
|
TransformerUtils { public static <T> Transformer<T, String> stringValueTransformer() { return StringValueTransformer.stringValueTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Transformer<T, String> stringValueTransformer(); }
|
@Test public void testStringValueTransformer() { assertNotNull( "StringValueTransformer should NEVER return a null value.", TransformerUtils.stringValueTransformer().transform(null)); assertEquals( "StringValueTransformer should return \"null\" when given a null argument.", "null", TransformerUtils.stringValueTransformer().transform(null)); assertEquals( "StringValueTransformer should return toString value", "6", TransformerUtils.stringValueTransformer().transform(Integer.valueOf(6))); }
@Test public void testSingletonPatternInSerialization() { final Object[] singletones = new Object[] { ExceptionTransformer.INSTANCE, NOPTransformer.INSTANCE, StringValueTransformer.stringValueTransformer(), }; for (final Object original : singletones) { TestUtils.assertSameAfterSerialization("Singleton pattern broken for " + original.getClass(), original); } }
|
TransformerUtils { public static <T> Transformer<Class<? extends T>, T> instantiateTransformer() { return InstantiateTransformer.instantiateTransformer(); } private TransformerUtils(); static Transformer<I, O> exceptionTransformer(); static Transformer<I, O> nullTransformer(); static Transformer<T, T> nopTransformer(); static Transformer<T, T> cloneTransformer(); static Transformer<I, O> constantTransformer(final O constantToReturn); static Transformer<T, T> asTransformer(final Closure<? super T> closure); static Transformer<T, Boolean> asTransformer(final Predicate<? super T> predicate); static Transformer<I, O> asTransformer(final Factory<? extends O> factory); static Transformer<T, T> chainedTransformer(
final Transformer<? super T, ? extends T>... transformers); static Transformer<T, T> chainedTransformer(
final Collection<? extends Transformer<? super T, ? extends T>> transformers); static Transformer<T, T> ifTransformer(final Predicate<? super T> predicate,
final Transformer<? super T, ? extends T> trueTransformer); static Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); @SuppressWarnings("unchecked") @Deprecated static Transformer<I, O> switchTransformer(final Predicate<? super I> predicate,
final Transformer<? super I, ? extends O> trueTransformer,
final Transformer<? super I, ? extends O> falseTransformer); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers); static Transformer<I, O> switchTransformer(final Predicate<? super I>[] predicates,
final Transformer<? super I, ? extends O>[] transformers,
final Transformer<? super I, ? extends O> defaultTransformer); static Transformer<I, O> switchTransformer(
final Map<Predicate<I>, Transformer<I, O>> predicatesAndTransformers); @SuppressWarnings("unchecked") static Transformer<I, O> switchMapTransformer(
final Map<I, Transformer<I, O>> objectsAndTransformers); static Transformer<Class<? extends T>, T> instantiateTransformer(); static Transformer<Class<? extends T>, T> instantiateTransformer(
final Class<?>[] paramTypes, final Object[] args); static Transformer<I, O> mapTransformer(final Map<? super I, ? extends O> map); static Transformer<I, O> invokerTransformer(final String methodName); static Transformer<I, O> invokerTransformer(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Transformer<T, String> stringValueTransformer(); }
|
@Test public void testInstantiateTransformerNull() { try { TransformerUtils.instantiateTransformer(null, new Object[] { "str" }); fail(); } catch (final IllegalArgumentException ex) {} try { TransformerUtils.instantiateTransformer(new Class[] {}, new Object[] { "str" }); fail(); } catch (final IllegalArgumentException ex) {} Transformer<Class<?>, Object> trans = TransformerUtils.instantiateTransformer(new Class[] { Long.class }, new Object[] { null }); try { trans.transform(String.class); fail(); } catch (final FunctorException ex) {} trans = TransformerUtils.instantiateTransformer(); assertEquals("", trans.transform(String.class)); trans = TransformerUtils.instantiateTransformer(new Class[] { Long.TYPE }, new Object[] { new Long(1000L) }); assertEquals(new Date(1000L), trans.transform(Date.class)); }
|
PredicateUtils { public static <T> Predicate<T> exceptionPredicate() { return ExceptionPredicate.exceptionPredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testExceptionPredicate() { assertNotNull(PredicateUtils.exceptionPredicate()); assertSame(PredicateUtils.exceptionPredicate(), PredicateUtils.exceptionPredicate()); try { PredicateUtils.exceptionPredicate().evaluate(null); } catch (final FunctorException ex) { try { PredicateUtils.exceptionPredicate().evaluate(cString); } catch (final FunctorException ex2) { return; } } fail(); }
|
PredicateUtils { public static <T> Predicate<T> notNullPredicate() { return NotNullPredicate.notNullPredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testIsNotNullPredicate() { assertNotNull(PredicateUtils.notNullPredicate()); assertSame(PredicateUtils.notNullPredicate(), PredicateUtils.notNullPredicate()); assertEquals(false, PredicateUtils.notNullPredicate().evaluate(null)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cObject)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cString)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cInteger)); }
|
PredicateUtils { public static <T> Predicate<T> identityPredicate(final T value) { return IdentityPredicate.identityPredicate(value); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testIdentityPredicate() { assertSame(nullPredicate(), PredicateUtils.identityPredicate(null)); assertNotNull(PredicateUtils.identityPredicate(Integer.valueOf(6))); assertEquals(false, PredicateUtils.identityPredicate(Integer.valueOf(6)).evaluate(null)); assertEquals(false, PredicateUtils.<Object>identityPredicate(Integer.valueOf(6)).evaluate(cObject)); assertEquals(false, PredicateUtils.<Object>identityPredicate(Integer.valueOf(6)).evaluate(cString)); assertEquals(false, PredicateUtils.identityPredicate(new Integer(6)).evaluate(cInteger)); assertEquals(true, PredicateUtils.identityPredicate(cInteger).evaluate(cInteger)); }
|
PredicateUtils { public static <T> Predicate<T> truePredicate() { return TruePredicate.truePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testTruePredicate() { assertNotNull(TruePredicate.truePredicate()); assertSame(TruePredicate.truePredicate(), TruePredicate.truePredicate()); assertEquals(true, TruePredicate.truePredicate().evaluate(null)); assertEquals(true, TruePredicate.truePredicate().evaluate(cObject)); assertEquals(true, TruePredicate.truePredicate().evaluate(cString)); assertEquals(true, TruePredicate.truePredicate().evaluate(cInteger)); }
|
PredicateUtils { public static <T> Predicate<T> falsePredicate() { return FalsePredicate.falsePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testFalsePredicate() { assertNotNull(FalsePredicate.falsePredicate()); assertSame(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()); assertEquals(false, FalsePredicate.falsePredicate().evaluate(null)); assertEquals(false, FalsePredicate.falsePredicate().evaluate(cObject)); assertEquals(false, FalsePredicate.falsePredicate().evaluate(cString)); assertEquals(false, FalsePredicate.falsePredicate().evaluate(cInteger)); }
|
PredicateUtils { public static <T> Predicate<T> notPredicate(final Predicate<? super T> predicate) { return NotPredicate.notPredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testNotPredicate() { assertNotNull(PredicateUtils.notPredicate(TruePredicate.truePredicate())); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cObject)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cString)); assertEquals(false, PredicateUtils.notPredicate(TruePredicate.truePredicate()).evaluate(cInteger)); }
@Test(expected=NullPointerException.class) public void testNotPredicateEx() { PredicateUtils.notPredicate(null); }
|
LocalCacheHandler extends SimpleCacheHandler { @Override public void delete(String key) { cache.remove(key); } 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<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
|
@Test public void testDelete() 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)); cache.delete(key); assertThat(cache.get(key), nullValue()); }
|
PredicateUtils { public static <T> Predicate<T> andPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return AndPredicate.andPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testAndPredicate() { assertEquals(true, PredicateUtils.andPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); }
@Test(expected=NullPointerException.class) public void testAndPredicateEx() { PredicateUtils.andPredicate(null, null); }
|
PredicateUtils { public static <T> Predicate<T> allPredicate(final Predicate<? super T>... predicates) { return AllPredicate.allPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@SuppressWarnings("unchecked") @Test public void testAllPredicate() { assertTrue(AllPredicate.allPredicate(new Predicate[] {}), null); assertEquals(true, AllPredicate.allPredicate(new Predicate[] { TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, AllPredicate.allPredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, AllPredicate.allPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, AllPredicate.allPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(TruePredicate.truePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); assertEquals(false, AllPredicate.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); assertFalse(AllPredicate.allPredicate(coll), null); coll.clear(); coll.add(TruePredicate.truePredicate()); assertTrue(AllPredicate.allPredicate(coll), null); coll.clear(); assertTrue(AllPredicate.allPredicate(coll), null); }
@Test(expected=NullPointerException.class) public void testAllPredicateEx1() { AllPredicate.allPredicate((Predicate<Object>[]) null); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAllPredicateEx2() { AllPredicate.<Object>allPredicate(new Predicate[] { null }); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAllPredicateEx3() { AllPredicate.allPredicate(new Predicate[] { null, null }); }
@Test(expected=NullPointerException.class) public void testAllPredicateEx4() { AllPredicate.allPredicate((Collection<Predicate<Object>>) null); }
@Test public void testAllPredicateEx5() { AllPredicate.allPredicate(Collections.<Predicate<Object>>emptyList()); }
@Test(expected=NullPointerException.class) public void testAllPredicateEx6() { final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(null); coll.add(null); AllPredicate.allPredicate(coll); }
|
LocalCacheHandler extends SimpleCacheHandler { @Override public void add(String key, Object value, int exptimeSeconds) { long now = ticker.read(); Entry entry = new Entry(value, now + TimeUnit.SECONDS.toNanos(exptimeSeconds)); cache.putIfAbsent(key, entry); } 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<String> keys, Type type); @Override void set(String key, Object value, int exptimeSeconds); @Override void delete(String key); @Override void add(String key, Object value, int exptimeSeconds); }
|
@Test public void testAdd() throws Exception { Ticker4Test t = new Ticker4Test(); LocalCacheHandler cache = new LocalCacheHandler(t); int seconds = 100; String key = "key"; String value = "value"; int seconds2 = 200; String key2 = "key2"; String value2 = "value2"; cache.set(key, value, seconds); cache.add(key, value2, seconds); cache.add(key2, value2, seconds2); assertThat((String) cache.get(key), equalTo(value)); assertThat((String) cache.get(key2), equalTo(value2)); }
|
PredicateUtils { public static <T> Predicate<T> orPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { return OrPredicate.orPredicate(predicate1, predicate2); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testOrPredicate() { assertEquals(true, PredicateUtils.orPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.orPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.orPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); }
@Test(expected=NullPointerException.class) public void testOrPredicateEx() { PredicateUtils.orPredicate(null, null); }
|
PredicateUtils { public static <T> Predicate<T> anyPredicate(final Predicate<? super T>... predicates) { return AnyPredicate.anyPredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@SuppressWarnings("unchecked") @Test public void testAnyPredicate() { assertFalse(PredicateUtils.anyPredicate(new Predicate[] {}), null); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.anyPredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(TruePredicate.truePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); assertEquals(false, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); assertFalse(PredicateUtils.anyPredicate(coll), null); coll.clear(); coll.add(TruePredicate.truePredicate()); assertTrue(PredicateUtils.anyPredicate(coll), null); coll.clear(); assertFalse(PredicateUtils.anyPredicate(coll), null); }
@Test(expected=NullPointerException.class) public void testAnyPredicateEx1() { PredicateUtils.anyPredicate((Predicate<Object>[]) null); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAnyPredicateEx2() { PredicateUtils.anyPredicate(new Predicate[] {null}); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testAnyPredicateEx3() { PredicateUtils.anyPredicate(new Predicate[] {null, null}); }
@Test(expected=NullPointerException.class) public void testAnyPredicateEx4() { PredicateUtils.anyPredicate((Collection<Predicate<Object>>) null); }
@Test public void testAnyPredicateEx5() { PredicateUtils.anyPredicate(Collections.<Predicate<Object>>emptyList()); }
@Test(expected=NullPointerException.class) public void testAnyPredicateEx6() { final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(null); coll.add(null); PredicateUtils.anyPredicate(coll); }
|
PredicateUtils { public static <T> Predicate<T> eitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { @SuppressWarnings("unchecked") final Predicate<T> onePredicate = PredicateUtils.onePredicate(predicate1, predicate2); return onePredicate; } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testEitherPredicate() { assertEquals(false, PredicateUtils.eitherPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.eitherPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.eitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); }
@Test(expected=NullPointerException.class) public void testEitherPredicateEx() { PredicateUtils.eitherPredicate(null, null); }
|
CacheableQueryOperator extends QueryOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); return driver.isUseMultipleKeys() ? multipleKeysCache(context, rowMapper.getMappedClass(), driver.getOnlyCacheByClass(), stat) : singleKeyCache(context, stat); } CacheableQueryOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
|
@Test public void testQuerySingleKeyHit() throws Exception { TypeToken<Integer> pt = TypeToken.of(Integer.class); TypeToken<User> rt = TypeToken.of(User.class); String srcSql = "select * from user where id=:1"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Object get(String key, Type type, Class<?> daoClass) { assertThat(key, Matchers.equalTo("user_1")); return new User(); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter()); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{1}, stat); assertThat(stat.getHitCount(), Matchers.equalTo(1L)); }
@Test public void testQuerySingleKeyMiss() throws Exception { TypeToken<Integer> pt = TypeToken.of(Integer.class); TypeToken<User> rt = TypeToken.of(User.class); String srcSql = "select * from user where id=:1"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Object get(String key, Type type, Class<?> daoClass) { assertThat(key, Matchers.equalTo("user_1")); return null; } @Override public void set(String key, Object value, int expires, Class<?> daoClass) { assertThat(key, Matchers.equalTo("user_1")); assertThat(expires, Matchers.equalTo((int) TimeUnit.DAYS.toSeconds(1))); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> T queryForObject(DataSource ds, BoundSql boundSql, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id=?"; assertThat(sql, Matchers.equalTo(descSql)); assertThat(args.length, Matchers.equalTo(1)); assertThat(args[0], Matchers.equalTo((Object) 1)); return (T) new User(); } }); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{1}, stat); assertThat(stat.getMissCount(), Matchers.equalTo(1L)); }
@Test public void testQueryMultiKeyAllHit() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<List<User>> rt = new TypeToken<List<User>>() { }; String srcSql = "select * from user where id in (:1)"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Map<String, Object> getBulk(Set<String> keys, Type type, Class<?> daoClass) { Map<String, Object> map = new HashMap<String, Object>(); map.put("user_1", new User()); map.put("user_2", new User()); map.put("user_3", new User()); assertThat(keys, Matchers.equalTo(map.keySet())); return map; } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter()); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{Arrays.asList(1, 2, 3)}, stat); assertThat(stat.getHitCount(), equalTo(3L)); assertThat(((CacheableQueryOperator) operator).propertyOfMapperInvoker.getName(), equalTo("id")); }
@Test public void testQueryMultiKeyAllMiss() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<List<User>> rt = new TypeToken<List<User>>() { }; String srcSql = "select * from user where id in (:1)"; final Set<String> keys = new HashSet<String>(); final Set<String> setKeys = new HashSet<String>(); keys.add("user_1"); keys.add("user_2"); keys.add("user_3"); AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Map<String, Object> getBulk(Set<String> keys, Type type, Class<?> daoClass) { assertThat(keys, Matchers.equalTo(keys)); return null; } @Override public void set(String key, Object value, int expires, Class<?> daoClass) { setKeys.add(key); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> List<T> queryForList(DataSource ds, BoundSql boundSql, ListSupplier listSupplier, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id in (?,?,?)"; assertThat(sql, Matchers.equalTo(descSql)); assertThat(args.length, Matchers.equalTo(3)); assertThat(args[0], Matchers.equalTo((Object) 1)); assertThat(args[1], Matchers.equalTo((Object) 2)); assertThat(args[2], Matchers.equalTo((Object) 3)); List<T> users = new ArrayList<T>(); users.add((T) new User(1, "1")); users.add((T) new User(2, "2")); users.add((T) new User(3, "3")); return users; } }); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{Arrays.asList(1, 2, 3)}, stat); assertThat(stat.getMissCount(), Matchers.equalTo(3L)); assertThat(keys, Matchers.equalTo(setKeys)); }
@Test public void testQueryMultiKey() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<List<User>> rt = new TypeToken<List<User>>() { }; String srcSql = "select * from user where id in (:1)"; final Set<String> keys = new HashSet<String>(); final Set<String> setKeys = new HashSet<String>(); keys.add("user_1"); keys.add("user_2"); keys.add("user_3"); AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public Map<String, Object> getBulk(Set<String> keys, Type type, Class<?> daoClass) { assertThat(keys, Matchers.equalTo(keys)); Map<String, Object> map = new HashMap<String, Object>(); map.put("user_2", new User()); return map; } @Override public void set(String key, Object value, int expires, Class<?> daoClass) { setKeys.add(key); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public <T> List<T> queryForList(DataSource ds, BoundSql boundSql, ListSupplier listSupplier, RowMapper<T> rowMapper) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "select * from user where id in (?,?)"; assertThat(sql, Matchers.equalTo(descSql)); assertThat(args.length, Matchers.equalTo(2)); assertThat(args[0], Matchers.equalTo((Object) 1)); assertThat(args[1], Matchers.equalTo((Object) 3)); List<T> users = new ArrayList<T>(); users.add((T) new User(1, "1")); users.add((T) new User(3, "3")); return users; } }); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{Arrays.asList(1, 2, 3)}, stat); assertThat(stat.getHitCount(), Matchers.equalTo(1L)); assertThat(stat.getMissCount(), Matchers.equalTo(2L)); keys.remove("user_2"); assertThat(keys, Matchers.equalTo(setKeys)); }
|
PredicateUtils { public static <T> Predicate<T> onePredicate(final Predicate<? super T>... predicates) { return OnePredicate.onePredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@SuppressWarnings("unchecked") @Test public void testOnePredicate() { assertFalse(PredicateUtils.onePredicate((Predicate<Object>[]) new Predicate[] {}), null); assertEquals(false, PredicateUtils.onePredicate(new Predicate[] { TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.onePredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.onePredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.onePredicate(new Predicate[] { FalsePredicate.falsePredicate(), TruePredicate.truePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.onePredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.onePredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()}).evaluate(null)); final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null)); coll.clear(); coll.add(TruePredicate.truePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(true, PredicateUtils.onePredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); assertFalse(PredicateUtils.onePredicate(coll), null); coll.clear(); coll.add(TruePredicate.truePredicate()); assertTrue(PredicateUtils.onePredicate(coll), null); coll.clear(); assertFalse(PredicateUtils.onePredicate(coll), null); }
@Test(expected=NullPointerException.class) public void testOnePredicateEx1() { PredicateUtils.onePredicate((Predicate<Object>[]) null); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testOnePredicateEx2() { PredicateUtils.onePredicate(new Predicate[] {null}); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testOnePredicateEx3() { PredicateUtils.onePredicate(new Predicate[] {null, null}); }
@Test(expected=NullPointerException.class) public void testOnePredicateEx4() { PredicateUtils.onePredicate((Collection<Predicate<Object>>) null); }
@SuppressWarnings("unchecked") @Test public void testOnePredicateEx5() { PredicateUtils.onePredicate(Collections.EMPTY_LIST); }
@Test(expected=NullPointerException.class) public void testOnePredicateEx6() { final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(null); coll.add(null); PredicateUtils.onePredicate(coll); }
|
PredicateUtils { public static <T> Predicate<T> neitherPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2) { @SuppressWarnings("unchecked") final Predicate<T> nonePredicate = PredicateUtils.nonePredicate(predicate1, predicate2); return nonePredicate; } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testNeitherPredicate() { assertEquals(false, PredicateUtils.neitherPredicate(TruePredicate.truePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.neitherPredicate(TruePredicate.truePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), TruePredicate.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.neitherPredicate(FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate()).evaluate(null)); }
@Test(expected=NullPointerException.class) public void testNeitherPredicateEx() { PredicateUtils.neitherPredicate(null, null); }
|
DynamicTokens { public static <E> TypeToken<Collection<E>> collectionToken(TypeToken<E> entityToken) { return new TypeToken<Collection<E>>() {} .where(new TypeParameter<E>() {}, entityToken); } static TypeToken<Collection<E>> collectionToken(TypeToken<E> entityToken); static TypeToken<List<E>> listToken(TypeToken<E> entityToken); }
|
@Test public void testCollectionToken() throws Exception { TypeToken<Collection<String>> token = DynamicTokens.collectionToken(TypeToken.of(String.class)); Type expectedType = DynamicTokensTest.class.getMethod("func").getGenericReturnType(); assertThat(token.getType(), equalTo(expectedType)); }
|
PredicateUtils { public static <T> Predicate<T> nonePredicate(final Predicate<? super T>... predicates) { return NonePredicate.nonePredicate(predicates); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@SuppressWarnings("unchecked") @Test public void testNonePredicate() { assertTrue(PredicateUtils.nonePredicate(new Predicate[] {}), null); assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] { TruePredicate.truePredicate(), TruePredicate.truePredicate(), TruePredicate.truePredicate() }).evaluate(null)); assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] { TruePredicate.truePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate() }).evaluate(null)); assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), TruePredicate.truePredicate() }).evaluate(null)); assertEquals(true, PredicateUtils.nonePredicate(new Predicate[] { FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate(), FalsePredicate.falsePredicate() }).evaluate(null)); final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(TruePredicate.truePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(TruePredicate.truePredicate()); assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); coll.add(FalsePredicate.falsePredicate()); assertEquals(true, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(FalsePredicate.falsePredicate()); assertTrue(PredicateUtils.nonePredicate(coll), null); coll.clear(); coll.add(TruePredicate.truePredicate()); assertFalse(PredicateUtils.nonePredicate(coll), null); coll.clear(); assertTrue(PredicateUtils.nonePredicate(coll), null); }
@Test(expected=NullPointerException.class) public void testNonePredicateEx1() { PredicateUtils.nonePredicate((Predicate<Object>[]) null); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testNonePredicateEx2() { PredicateUtils.nonePredicate(new Predicate[] {null}); }
@SuppressWarnings("unchecked") @Test(expected=NullPointerException.class) public void testNonePredicateEx3() { PredicateUtils.nonePredicate(new Predicate[] {null, null}); }
@Test(expected=NullPointerException.class) public void testNonePredicateEx4() { PredicateUtils.nonePredicate((Collection<Predicate<Object>>) null); }
@Test public void testNonePredicateEx5() { PredicateUtils.nonePredicate(Collections.<Predicate<Object>>emptyList()); }
@Test(expected=NullPointerException.class) public void testNonePredicateEx6() { final Collection<Predicate<Object>> coll = new ArrayList<Predicate<Object>>(); coll.add(null); coll.add(null); PredicateUtils.nonePredicate(coll); }
|
PredicateUtils { public static Predicate<Object> instanceofPredicate(final Class<?> type) { return InstanceofPredicate.instanceOfPredicate(type); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testInstanceOfPredicate() { assertNotNull(PredicateUtils.instanceofPredicate(String.class)); assertEquals(false, PredicateUtils.instanceofPredicate(String.class).evaluate(null)); assertEquals(false, PredicateUtils.instanceofPredicate(String.class).evaluate(cObject)); assertEquals(true, PredicateUtils.instanceofPredicate(String.class).evaluate(cString)); assertEquals(false, PredicateUtils.instanceofPredicate(String.class).evaluate(cInteger)); }
|
PredicateUtils { public static <T> Predicate<T> uniquePredicate() { return UniquePredicate.uniquePredicate(); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testUniquePredicate() { final Predicate<Object> p = PredicateUtils.uniquePredicate(); assertEquals(true, p.evaluate(new Object())); assertEquals(true, p.evaluate(new Object())); assertEquals(true, p.evaluate(new Object())); assertEquals(true, p.evaluate(cString)); assertEquals(false, p.evaluate(cString)); assertEquals(false, p.evaluate(cString)); }
|
PredicateUtils { public static <T> Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer) { return TransformerPredicate.transformerPredicate(transformer); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testAsPredicateTransformer() { assertEquals(false, PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(false)); assertEquals(true, PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(true)); }
@Test(expected=NullPointerException.class) public void testAsPredicateTransformerEx1() { PredicateUtils.asPredicate(null); }
@Test(expected=FunctorException.class) public void testAsPredicateTransformerEx2() { PredicateUtils.asPredicate(TransformerUtils.<Boolean>nopTransformer()).evaluate(null); }
|
PredicateUtils { public static <T> Predicate<T> invokerPredicate(final String methodName) { return asPredicate(InvokerTransformer.<Object, Boolean>invokerTransformer(methodName)); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testInvokerPredicate() { final List<Object> list = new ArrayList<Object>(); assertEquals(true, PredicateUtils.invokerPredicate("isEmpty").evaluate(list)); list.add(new Object()); assertEquals(false, PredicateUtils.invokerPredicate("isEmpty").evaluate(list)); }
@Test(expected=NullPointerException.class) public void testInvokerPredicateEx1() { PredicateUtils.invokerPredicate(null); }
@Test(expected=FunctorException.class) public void testInvokerPredicateEx2() { PredicateUtils.invokerPredicate("isEmpty").evaluate(null); }
@Test(expected=FunctorException.class) public void testInvokerPredicateEx3() { PredicateUtils.invokerPredicate("noSuchMethod").evaluate(new Object()); }
@Test public void testInvokerPredicate2() { final List<String> list = new ArrayList<String>(); assertEquals(false, PredicateUtils.invokerPredicate( "contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list)); list.add(cString); assertEquals(true, PredicateUtils.invokerPredicate( "contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(list)); }
@Test(expected=NullPointerException.class) public void testInvokerPredicate2Ex1() { PredicateUtils.invokerPredicate(null, null, null); }
@Test(expected=FunctorException.class) public void testInvokerPredicate2Ex2() { PredicateUtils.invokerPredicate("contains", new Class[] {Object.class}, new Object[] {cString}).evaluate(null); }
@Test(expected=FunctorException.class) public void testInvokerPredicate2Ex3() { PredicateUtils.invokerPredicate( "noSuchMethod", new Class[] {Object.class}, new Object[] {cString}).evaluate(new Object()); }
|
PredicateUtils { public static <T> Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate){ return NullIsExceptionPredicate.nullIsExceptionPredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test(expected=FunctorException.class) public void testNullIsExceptionPredicate() { assertEquals(true, PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(new Object())); PredicateUtils.nullIsExceptionPredicate(TruePredicate.truePredicate()).evaluate(null); }
@Test(expected=NullPointerException.class) public void testNullIsExceptionPredicateEx1() { PredicateUtils.nullIsExceptionPredicate(null); }
|
PredicateUtils { public static <T> Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate){ return NullIsTruePredicate.nullIsTruePredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testNullIsTruePredicate() { assertEquals(true, PredicateUtils.nullIsTruePredicate(TruePredicate.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.nullIsTruePredicate(TruePredicate.truePredicate()).evaluate(new Object())); assertEquals(false, PredicateUtils.nullIsTruePredicate(FalsePredicate.falsePredicate()).evaluate(new Object())); }
@Test(expected=NullPointerException.class) public void testNullIsTruePredicateEx1() { PredicateUtils.nullIsTruePredicate(null); }
|
PredicateUtils { public static <T> Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate){ return NullIsFalsePredicate.nullIsFalsePredicate(predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testNullIsFalsePredicate() { assertEquals(false, PredicateUtils.nullIsFalsePredicate(TruePredicate.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.nullIsFalsePredicate(TruePredicate.truePredicate()).evaluate(new Object())); assertEquals(false, PredicateUtils.nullIsFalsePredicate(FalsePredicate.falsePredicate()).evaluate(new Object())); }
@Test(expected=NullPointerException.class) public void testNullIsFalsePredicateEx1() { PredicateUtils.nullIsFalsePredicate(null); }
|
PredicateUtils { public static <T> Predicate<T> transformedPredicate( final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate) { return TransformedPredicate.transformedPredicate(transformer, predicate); } private PredicateUtils(); static Predicate<T> exceptionPredicate(); static Predicate<T> truePredicate(); static Predicate<T> falsePredicate(); static Predicate<T> nullPredicate(); static Predicate<T> notNullPredicate(); static Predicate<T> equalPredicate(final T value); static Predicate<T> identityPredicate(final T value); static Predicate<Object> instanceofPredicate(final Class<?> type); static Predicate<T> uniquePredicate(); static Predicate<T> invokerPredicate(final String methodName); static Predicate<T> invokerPredicate(final String methodName, final Class<?>[] paramTypes,
final Object[] args); static Predicate<T> andPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> orPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> anyPredicate(final Predicate<? super T>... predicates); static Predicate<T> anyPredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> eitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> onePredicate(final Predicate<? super T>... predicates); static Predicate<T> onePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> neitherPredicate(final Predicate<? super T> predicate1,
final Predicate<? super T> predicate2); static Predicate<T> nonePredicate(final Predicate<? super T>... predicates); static Predicate<T> nonePredicate(final Collection<? extends Predicate<? super T>> predicates); static Predicate<T> notPredicate(final Predicate<? super T> predicate); static Predicate<T> asPredicate(final Transformer<? super T, Boolean> transformer); static Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate); static Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate); static Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate); }
|
@Test public void testTransformedPredicate() { assertEquals(true, PredicateUtils.transformedPredicate( TransformerUtils.nopTransformer(), TruePredicate.truePredicate()).evaluate(new Object())); final Map<Object, Object> map = new HashMap<Object, Object>(); map.put(Boolean.TRUE, "Hello"); final Transformer<Object, Object> t = TransformerUtils.mapTransformer(map); final Predicate<Object> p = EqualPredicate.<Object>equalPredicate("Hello"); assertEquals(false, PredicateUtils.transformedPredicate(t, p).evaluate(null)); assertEquals(true, PredicateUtils.transformedPredicate(t, p).evaluate(Boolean.TRUE)); try { PredicateUtils.transformedPredicate(null, null); fail(); } catch (final NullPointerException ex) {} }
|
ComparatorPredicate implements Predicate<T>, Serializable { public static <T> Predicate<T> comparatorPredicate(final T object, final Comparator<T> comparator) { return comparatorPredicate(object, comparator, Criterion.EQUAL); } ComparatorPredicate(final T object, final Comparator<T> comparator, final Criterion criterion); static Predicate<T> comparatorPredicate(final T object, final Comparator<T> comparator); static Predicate<T> comparatorPredicate(final T object, final Comparator<T> comparator,
final Criterion criterion); boolean evaluate(final T target); }
|
@Test public void compareEquals() { final Integer value = Integer.valueOf(10); final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>()); assertFalse(p, Integer.valueOf(value.intValue() - 1)); assertTrue(p, Integer.valueOf(value.intValue())); assertFalse(p, Integer.valueOf(value.intValue() + 1)); }
@Test public void compareGreater() { final Integer value = Integer.valueOf(10); final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.GREATER); assertTrue(p, Integer.valueOf(value.intValue() - 1)); assertFalse(p, Integer.valueOf(value.intValue())); assertFalse(p, Integer.valueOf(value.intValue() + 1)); }
@Test public void compareLess() { final Integer value = Integer.valueOf(10); final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.LESS); assertFalse(p, Integer.valueOf(value.intValue() - 1)); assertFalse(p, Integer.valueOf(value.intValue())); assertTrue(p, Integer.valueOf(value.intValue() + 1)); }
@Test public void compareGreaterOrEqual() { final Integer value = Integer.valueOf(10); final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.GREATER_OR_EQUAL); assertTrue(p, Integer.valueOf(value.intValue() - 1)); assertTrue(p, Integer.valueOf(value.intValue())); assertFalse(p, Integer.valueOf(value.intValue() + 1)); }
@Test public void compareLessOrEqual() { final Integer value = Integer.valueOf(10); final Predicate<Integer> p = comparatorPredicate(value, new TestComparator<Integer>(), Criterion.LESS_OR_EQUAL); assertFalse(p, Integer.valueOf(value.intValue() - 1)); assertTrue(p, Integer.valueOf(value.intValue())); assertTrue(p, Integer.valueOf(value.intValue() + 1)); }
|
NullPredicate implements Predicate<T>, Serializable { @SuppressWarnings("unchecked") public static <T> Predicate<T> nullPredicate() { return (Predicate<T>) INSTANCE; } private NullPredicate(); @SuppressWarnings("unchecked") static Predicate<T> nullPredicate(); boolean evaluate(final T object); @SuppressWarnings("rawtypes")
static final Predicate INSTANCE; }
|
@Test public void testNullPredicate() { assertSame(NullPredicate.nullPredicate(), NullPredicate.nullPredicate()); assertTrue(nullPredicate(), null); }
@Test public void ensurePredicateCanBeTypedWithoutWarning() throws Exception { final Predicate<String> predicate = NullPredicate.nullPredicate(); assertFalse(predicate, cString); }
|
CatchAndRethrowClosure implements Closure<E> { public void execute(final E input) { try { executeAndThrow(input); } catch (final RuntimeException ex) { throw ex; } catch (final Throwable t) { throw new FunctorException(t); } } void execute(final E input); }
|
@Test public void testThrowingClosure() { Closure<Integer> closure = generateNoExceptionClosure(); try { closure.execute(Integer.valueOf(0)); } catch (final FunctorException ex) { Assert.fail(); } catch (final RuntimeException ex) { Assert.fail(); } closure = generateIOExceptionClosure(); try { closure.execute(Integer.valueOf(0)); Assert.fail(); } catch (final FunctorException ex) { Assert.assertTrue(ex.getCause() instanceof IOException); } catch (final RuntimeException ex) { Assert.fail(); } closure = generateNullPointerExceptionClosure(); try { closure.execute(Integer.valueOf(0)); Assert.fail(); } catch (final FunctorException ex) { Assert.fail(); } catch (final RuntimeException ex) { Assert.assertTrue(ex instanceof NullPointerException); } }
|
EqualPredicate implements Predicate<T>, Serializable { public static <T> Predicate<T> equalPredicate(final T object) { if (object == null) { return NullPredicate.nullPredicate(); } return new EqualPredicate<T>(object); } EqualPredicate(final T object); EqualPredicate(final T object, final Equator<T> equator); static Predicate<T> equalPredicate(final T object); static Predicate<T> equalPredicate(final T object, final Equator<T> equator); boolean evaluate(final T object); Object getValue(); }
|
@Test public void testNullArgumentEqualsNullPredicate() throws Exception { assertSame(nullPredicate(), equalPredicate(null)); }
@Test public void objectFactoryUsesEqualsForTest() throws Exception { final Predicate<EqualsTestObject> predicate = equalPredicate(FALSE_OBJECT); assertFalse(predicate, FALSE_OBJECT); assertTrue(equalPredicate(TRUE_OBJECT), TRUE_OBJECT); }
@SuppressWarnings("boxing") @Test public void testPredicateTypeCanBeSuperClassOfObject() throws Exception { final Predicate<Number> predicate = equalPredicate((Number) 4); assertTrue(predicate, 4); }
|
AllPredicate extends AbstractQuantifierPredicate<T> { public boolean evaluate(final T object) { for (final Predicate<? super T> iPredicate : iPredicates) { if (!iPredicate.evaluate(object)) { return false; } } return true; } AllPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Predicate<? super T>... predicates); static Predicate<T> allPredicate(final Collection<? extends Predicate<? super T>> predicates); boolean evaluate(final T object); }
|
@SuppressWarnings({"unchecked"}) @Test public void emptyArrayToGetInstance() { assertTrue("empty array not true", getPredicateInstance(new Predicate[] {}).evaluate(null)); }
@Test public void emptyCollectionToGetInstance() { final Predicate<Integer> allPredicate = getPredicateInstance( Collections.<Predicate<Integer>>emptyList()); assertTrue("empty collection not true", allPredicate.evaluate(getTestValue())); }
@Test public void allTrue() { assertTrue("multiple true predicates evaluated to false", getPredicateInstance(true, true).evaluate(getTestValue())); assertTrue("multiple true predicates evaluated to false", getPredicateInstance(true, true, true).evaluate(getTestValue())); }
@Test public void trueAndFalseCombined() { assertFalse("false predicate evaluated to true", getPredicateInstance(false, null).evaluate(getTestValue())); assertFalse("false predicate evaluated to true", getPredicateInstance(false, null, null).evaluate(getTestValue())); assertFalse("false predicate evaluated to true", getPredicateInstance(true, false, null).evaluate(getTestValue())); assertFalse("false predicate evaluated to true", getPredicateInstance(true, true, false).evaluate(getTestValue())); assertFalse("false predicate evaluated to true", getPredicateInstance(true, true, false, null).evaluate(getTestValue())); }
|
CacheableBatchUpdateOperator extends BatchUpdateOperator { @Override public Object execute(Object[] values, InvocationStat stat) { Iterables iterables = getIterables(values); if (iterables.isEmpty()) { return transformer.transform(new int[]{}); } Set<String> keys = new HashSet<String>(iterables.size() * 2); Map<DataSource, Group> groupMap = new HashMap<DataSource, Group>(); int t = 0; for (Object obj : iterables) { InvocationContext context = invocationContextFactory.newInvocationContext(new Object[]{obj}); keys.add(driver.getCacheKey(context)); group(context, groupMap, t++); } int[] ints = executeDb(groupMap, t, stat); if (logger.isDebugEnabled()) { logger.debug("Cache delete for multiple keys {}", keys); } driver.batchDeleteFromCache(keys, stat); return transformer.transform(ints); } CacheableBatchUpdateOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
|
@Test public void testBatchUpdate() throws Exception { TypeToken<List<User>> pt = new TypeToken<List<User>>() { }; TypeToken<int[]> rt = TypeToken.of(int[].class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public void batchDelete(Set<String> keys, Class<?> daoClass) { Set<String> set = new HashSet<String>(); set.add("user_100"); set.add("user_200"); assertThat(keys, equalTo(set)); } }, new MockCacheBy("id")); final int[] expectedInts = new int[]{1, 2}; operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int[] batchUpdate(DataSource ds, List<BoundSql> boundSqls) throws DataAccessException { String descSql = "update user set name=? where id=?"; assertThat(boundSqls.get(0).getSql(), equalTo(descSql)); assertThat(boundSqls.size(), equalTo(2)); assertThat(boundSqls.get(0).getArgs().get(0), equalTo((Object) "ash")); assertThat(boundSqls.get(0).getArgs().get(1), equalTo((Object) 100)); assertThat(boundSqls.get(1).getArgs().get(0), equalTo((Object) "lucy")); assertThat(boundSqls.get(1).getArgs().get(1), equalTo((Object) 200)); return expectedInts; } }); List<User> users = Arrays.asList(new User(100, "ash"), new User(200, "lucy")); InvocationStat stat = InvocationStat.create(); int[] actualInts = (int[]) operator.execute(new Object[]{users}, stat); assertThat(Arrays.toString(actualInts), equalTo(Arrays.toString(expectedInts))); assertThat(stat.getCacheBatchDeleteSuccessCount(), equalTo(1L)); }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> collate(final Iterable<? extends E> other) { return of(IterableUtils.collatedIterable(iterable, other)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void collate() { List<Integer> result = FluentIterable.of(iterableOdd).collate(iterableEven).toList(); List<Integer> combinedList = new ArrayList<Integer>(); CollectionUtils.addAll(combinedList, iterableOdd); CollectionUtils.addAll(combinedList, iterableEven); Collections.sort(combinedList); assertEquals(combinedList, result); try { FluentIterable.of(iterableOdd).collate(null).toList(); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> filter(final Predicate<? super E> predicate) { return of(IterableUtils.filteredIterable(iterable, predicate)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void filter() { Predicate<Integer> smallerThan3 = new Predicate<Integer>() { @Override public boolean evaluate(Integer object) { return object.intValue() < 3; } }; List<Integer> result = FluentIterable.of(iterableA).filter(smallerThan3).toList(); assertEquals(3, result.size()); assertEquals(Arrays.asList(1, 2, 2), result); result = FluentIterable.of(emptyIterable).filter(smallerThan3).toList(); assertEquals(0, result.size()); try { FluentIterable.of(iterableA).filter(null).toList(); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { public void forEach(final Closure<? super E> closure) { IterableUtils.forEach(iterable, closure); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void forEach() { final AtomicInteger sum = new AtomicInteger(0); Closure<Integer> closure = new Closure<Integer>() { @Override public void execute(Integer input) { sum.addAndGet(input); } }; FluentIterable.of(iterableA).forEach(closure); int expectedSum = 0; for (Integer i : iterableA) { expectedSum += i; } assertEquals(expectedSum, sum.get()); try { FluentIterable.of(iterableA).forEach((Closure<Integer>) null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> limit(final long maxSize) { return of(IterableUtils.boundedIterable(iterable, maxSize)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void limit() { List<Integer> result = FluentIterable.of(iterableA).limit(3).toList(); assertEquals(3, result.size()); assertEquals(Arrays.asList(1, 2, 2), result); result = FluentIterable.of(iterableA).limit(100).toList(); List<Integer> expected = IterableUtils.toList(iterableA); assertEquals(expected.size(), result.size()); assertEquals(expected, result); result = FluentIterable.of(iterableA).limit(0).toList(); assertEquals(0, result.size()); result = FluentIterable.of(emptyIterable).limit(3).toList(); assertEquals(0, result.size()); try { FluentIterable.of(iterableA).limit(-2).toList(); fail("expecting IllegalArgumentException"); } catch (IllegalArgumentException iae) { } }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> reverse() { return of(IterableUtils.reversedIterable(iterable)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void reverse() { List<Integer> result = FluentIterable.of(iterableA).reverse().toList(); List<Integer> expected = IterableUtils.toList(iterableA); Collections.reverse(expected); assertEquals(expected, result); result = FluentIterable.of(emptyIterable).reverse().toList(); assertEquals(0, result.size()); }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> skip(final long elementsToSkip) { return of(IterableUtils.skippingIterable(iterable, elementsToSkip)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void skip() { List<Integer> result = FluentIterable.of(iterableA).skip(4).toList(); assertEquals(6, result.size()); assertEquals(Arrays.asList(3, 3, 4, 4, 4, 4), result); result = FluentIterable.of(iterableA).skip(100).toList(); assertEquals(0, result.size()); result = FluentIterable.of(iterableA).skip(0).toList(); List<Integer> expected = IterableUtils.toList(iterableA); assertEquals(expected.size(), result.size()); assertEquals(expected, result); result = FluentIterable.of(emptyIterable).skip(3).toList(); assertEquals(0, result.size()); try { FluentIterable.of(iterableA).skip(-4).toList(); fail("expecting IllegalArgumentException"); } catch (IllegalArgumentException iae) { } }
|
FluentIterable implements Iterable<E> { public <O> FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer) { return of(IterableUtils.transformedIterable(iterable, transformer)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void transform() { Transformer<Integer, Integer> squared = new Transformer<Integer, Integer>() { @Override public Integer transform(Integer object) { return object * object; } }; List<Integer> result = FluentIterable.of(iterableA).transform(squared).toList(); assertEquals(10, result.size()); assertEquals(Arrays.asList(1, 4, 4, 9, 9, 9, 16, 16, 16, 16), result); result = FluentIterable.of(emptyIterable).transform(squared).toList(); assertEquals(0, result.size()); try { FluentIterable.of(iterableA).transform(null).toList(); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> unique() { return of(IterableUtils.uniqueIterable(iterable)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void unique() { List<Integer> result = FluentIterable.of(iterableA).unique().toList(); assertEquals(4, result.size()); assertEquals(Arrays.asList(1, 2, 3, 4), result); result = FluentIterable.of(emptyIterable).unique().toList(); assertEquals(0, result.size()); }
|
CacheableUpdateOperator extends UpdateOperator { @Override public Object execute(Object[] values, InvocationStat stat) { InvocationContext context = invocationContextFactory.newInvocationContext(values); Object r = execute(context, stat); if (driver.isUseMultipleKeys()) { Set<String> keys = driver.getCacheKeys(context); if (!keys.isEmpty()) { if (logger.isDebugEnabled()) { logger.debug("Cache delete for multiple keys {}", keys); } driver.batchDeleteFromCache(keys, stat); } } else { String key = driver.getCacheKey(context); if (logger.isDebugEnabled()) { logger.debug("Cache delete for single key [{}]", key); } driver.deleteFromCache(key, stat); } return r; } CacheableUpdateOperator(ASTRootNode rootNode, MethodDescriptor md, CacheDriver cacheDriver, Config config); @Override Object execute(Object[] values, InvocationStat stat); }
|
@Test public void testUpdate() throws Exception { TypeToken<User> pt = TypeToken.of(User.class); TypeToken<Integer> rt = TypeToken.of(int.class); String srcSql = "update user set name=:1.name where id=:1.id"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public void delete(String key, Class<?> daoClass) { assertThat(key, equalTo("user_100")); } }, new MockCacheBy("id")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "update user set name=? where id=?"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(2)); assertThat(args[0], equalTo((Object) "ash")); assertThat(args[1], equalTo((Object) 100)); return 1; } }); User user = new User(); user.setId(100); user.setName("ash"); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{user}, stat); assertThat(stat.getCacheDeleteSuccessCount(), equalTo(1L)); }
@Test public void testUpdateWithIn() throws Exception { TypeToken<List<Integer>> pt = new TypeToken<List<Integer>>() { }; TypeToken<Integer> rt = TypeToken.of(int.class); String srcSql = "update user set name=ash where id in (:1)"; AbstractOperator operator = getOperator(pt, rt, srcSql, new CacheHandlerAdapter() { @Override public void batchDelete(Set<String> keys, Class<?> daoClass) { Set<String> set = new HashSet<String>(); set.add("user_100"); set.add("user_200"); assertThat(keys, equalTo(set)); } }, new MockCacheBy("")); operator.setJdbcOperations(new JdbcOperationsAdapter() { @Override public int update(DataSource ds, BoundSql boundSql) { String sql = boundSql.getSql(); Object[] args = boundSql.getArgs().toArray(); String descSql = "update user set name=ash where id in (?,?)"; assertThat(sql, equalTo(descSql)); assertThat(args.length, equalTo(2)); assertThat(args[0], equalTo((Object) 100)); assertThat(args[1], equalTo((Object) 200)); return 1; } }); List<Integer> ids = Arrays.asList(100, 200); InvocationStat stat = InvocationStat.create(); operator.execute(new Object[]{ids}, stat); assertThat(stat.getCacheBatchDeleteSuccessCount(), equalTo(1L)); }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> unmodifiable() { return of(IterableUtils.unmodifiableIterable(iterable)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void unmodifiable() { FluentIterable<Integer> iterable1 = FluentIterable.of(iterableA).unmodifiable(); Iterator<Integer> it = iterable1.iterator(); assertEquals(1, it.next().intValue()); try { it.remove(); fail("expecting UnsupportedOperationException"); } catch (UnsupportedOperationException ise) { } FluentIterable<Integer> iterable2 = iterable1.unmodifiable(); assertSame(iterable1, iterable2); }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> zip(final Iterable<? extends E> other) { return of(IterableUtils.zippingIterable(iterable, other)); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@SuppressWarnings("unchecked") @Test public void zip() { List<Integer> result = FluentIterable.of(iterableOdd).zip(iterableEven).toList(); List<Integer> combinedList = new ArrayList<Integer>(); CollectionUtils.addAll(combinedList, iterableOdd); CollectionUtils.addAll(combinedList, iterableEven); Collections.sort(combinedList); assertEquals(combinedList, result); try { FluentIterable.of(iterableOdd).zip((Iterable<Integer>) null).toList(); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } result = FluentIterable .of(Arrays.asList(1, 4, 7)) .zip(Arrays.asList(2, 5, 8), Arrays.asList(3, 6, 9)) .toList(); combinedList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9); assertEquals(combinedList, result); }
|
FluentIterable implements Iterable<E> { public Enumeration<E> asEnumeration() { return IteratorUtils.asEnumeration(iterator()); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void asEnumeration() { Enumeration<Long> enumeration = FluentIterable.of(iterableB).asEnumeration(); List<Long> result = EnumerationUtils.toList(enumeration); assertEquals(iterableB, result); enumeration = FluentIterable.<Long>empty().asEnumeration(); assertFalse(enumeration.hasMoreElements()); }
|
FluentIterable implements Iterable<E> { public boolean allMatch(final Predicate<? super E> predicate) { return IterableUtils.matchesAll(iterable, predicate); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void allMatch() { assertTrue(FluentIterable.of(iterableEven).allMatch(EVEN)); assertFalse(FluentIterable.of(iterableOdd).allMatch(EVEN)); assertFalse(FluentIterable.of(iterableA).allMatch(EVEN)); try { FluentIterable.of(iterableEven).allMatch(null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { public boolean anyMatch(final Predicate<? super E> predicate) { return IterableUtils.matchesAny(iterable, predicate); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void anyMatch() { assertTrue(FluentIterable.of(iterableEven).anyMatch(EVEN)); assertFalse(FluentIterable.of(iterableOdd).anyMatch(EVEN)); assertTrue(FluentIterable.of(iterableA).anyMatch(EVEN)); try { FluentIterable.of(iterableEven).anyMatch(null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { public boolean isEmpty() { return IterableUtils.isEmpty(iterable); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void isEmpty() { assertTrue(FluentIterable.of(emptyIterable).isEmpty()); assertFalse(FluentIterable.of(iterableOdd).isEmpty()); }
|
FluentIterable implements Iterable<E> { public int size() { return IterableUtils.size(iterable); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void size() { try { FluentIterable.of((Iterable<?>) null).size(); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } assertEquals(0, FluentIterable.of(emptyIterable).size()); assertEquals(IterableUtils.toList(iterableOdd).size(), FluentIterable.of(iterableOdd).size()); }
|
FluentIterable implements Iterable<E> { public FluentIterable<E> eval() { return of(toList()); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void eval() { List<Integer> listNumbers = new ArrayList<Integer>(); listNumbers.addAll(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); FluentIterable<Integer> iterable = FluentIterable.of(listNumbers).filter(EVEN); FluentIterable<Integer> materialized = iterable.eval(); listNumbers.addAll(Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20)); assertEquals(5, materialized.size()); assertEquals(10, iterable.size()); assertEquals(Arrays.asList(2, 4, 6, 8, 10), materialized.toList()); assertEquals(Arrays.asList(2, 4, 6, 8, 10, 12, 14, 16, 18, 20), iterable.toList()); }
|
FluentIterable implements Iterable<E> { public boolean contains(final Object object) { return IterableUtils.contains(iterable, object); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void contains() { assertTrue(FluentIterable.of(iterableEven).contains(2)); assertFalse(FluentIterable.of(iterableEven).contains(1)); assertFalse(FluentIterable.of(iterableEven).contains(null)); assertTrue(FluentIterable.of(iterableEven).append((Integer) null).contains(null)); }
|
FluentIterable implements Iterable<E> { public void copyInto(final Collection<? super E> collection) { if (collection == null) { throw new NullPointerException("Collection must not be null"); } CollectionUtils.addAll(collection, iterable); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void copyInto() { List<Integer> result = new ArrayList<Integer>(); FluentIterable.of(iterableA).copyInto(result); List<Integer> expected = IterableUtils.toList(iterableA); assertEquals(expected.size(), result.size()); assertEquals(expected, result); result = new ArrayList<Integer>(); result.add(10); result.add(9); result.add(8); FluentIterable.of(iterableA).copyInto(result); expected = new ArrayList<Integer>(); expected.addAll(Arrays.asList(10, 9, 8)); expected.addAll(IterableUtils.toList(iterableA)); assertEquals(expected.size(), result.size()); assertEquals(expected, result); try { FluentIterable.of(iterableA).copyInto(null); fail("expecting NullPointerException"); } catch (NullPointerException npe) { } }
|
FluentIterable implements Iterable<E> { @Override public Iterator<E> iterator() { return iterable.iterator(); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void iterator() { Iterator<Integer> iterator = FluentIterable.of(iterableA).iterator(); assertTrue(iterator.hasNext()); iterator = FluentIterable.<Integer>empty().iterator(); assertFalse(iterator.hasNext()); }
|
FluentIterable implements Iterable<E> { public E get(final int position) { return IterableUtils.get(iterable, position); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void get() { assertEquals(2, FluentIterable.of(iterableEven).get(0).intValue()); try { FluentIterable.of(iterableEven).get(-1); fail("expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ioe) { } try { FluentIterable.of(iterableEven).get(IterableUtils.size(iterableEven)); fail("expecting IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException ioe) { } }
|
FluentIterable implements Iterable<E> { public E[] toArray(final Class<E> arrayClass) { return IteratorUtils.toArray(iterator(), arrayClass); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void toArray() { Long[] arr = new Long[] {1L, 2L, 3L, 4L, 5L}; Long[] result = FluentIterable.of(arr).toArray(Long.class); assertNotNull(result); assertArrayEquals(arr, result); try { FluentIterable.of(arr).toArray((Class) String.class); } catch (ArrayStoreException ase) { } }
|
FluentIterable implements Iterable<E> { @Override public String toString() { return IterableUtils.toString(iterable); } FluentIterable(); private FluentIterable(final Iterable<E> iterable); @SuppressWarnings("unchecked") static FluentIterable<T> empty(); static FluentIterable<T> of(final T singleton); static FluentIterable<T> of(final T... elements); static FluentIterable<T> of(final Iterable<T> iterable); FluentIterable<E> append(final E... elements); FluentIterable<E> append(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other); FluentIterable<E> collate(final Iterable<? extends E> other,
final Comparator<? super E> comparator); FluentIterable<E> eval(); FluentIterable<E> filter(final Predicate<? super E> predicate); FluentIterable<E> limit(final long maxSize); FluentIterable<E> loop(); FluentIterable<E> reverse(); FluentIterable<E> skip(final long elementsToSkip); FluentIterable<O> transform(final Transformer<? super E, ? extends O> transformer); FluentIterable<E> unique(); FluentIterable<E> unmodifiable(); FluentIterable<E> zip(final Iterable<? extends E> other); FluentIterable<E> zip(final Iterable<? extends E>... others); @Override Iterator<E> iterator(); Enumeration<E> asEnumeration(); boolean allMatch(final Predicate<? super E> predicate); boolean anyMatch(final Predicate<? super E> predicate); boolean isEmpty(); boolean contains(final Object object); void forEach(final Closure<? super E> closure); E get(final int position); int size(); void copyInto(final Collection<? super E> collection); E[] toArray(final Class<E> arrayClass); List<E> toList(); @Override String toString(); }
|
@Test public void testToString() { String result = FluentIterable.of(iterableA).toString(); assertEquals(iterableA.toString(), result); result = FluentIterable.empty().toString(); assertEquals("[]", result); }
|
Charsets { public static Charset toCharset(final Charset charset) { return charset == null ? Charset.defaultCharset() : charset; } static Charset toCharset(final Charset charset); static Charset toCharset(final String charset); @Deprecated
static final Charset ISO_8859_1; @Deprecated
static final Charset US_ASCII; @Deprecated
static final Charset UTF_16; @Deprecated
static final Charset UTF_16BE; @Deprecated
static final Charset UTF_16LE; @Deprecated
static final Charset UTF_8; }
|
@Test public void testToCharset() { Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null)); Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null)); Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset())); Assert.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8"))); }
|
StringEncoderComparator implements Comparator { @Override public int compare(final Object o1, final Object o2) { int compareCode = 0; try { @SuppressWarnings("unchecked") final Comparable<Comparable<?>> s1 = (Comparable<Comparable<?>>) this.stringEncoder.encode(o1); final Comparable<?> s2 = (Comparable<?>) this.stringEncoder.encode(o2); compareCode = s1.compareTo(s2); } catch (final EncoderException ee) { compareCode = 0; } return compareCode; } @Deprecated StringEncoderComparator(); StringEncoderComparator(final StringEncoder stringEncoder); @Override int compare(final Object o1, final Object o2); }
|
@Test public void testComparatorWithSoundex() throws Exception { final StringEncoderComparator sCompare = new StringEncoderComparator( new Soundex() ); assertTrue( "O'Brien and O'Brian didn't come out with " + "the same Soundex, something must be wrong here", 0 == sCompare.compare( "O'Brien", "O'Brian" ) ); }
@Test public void testComparatorWithDoubleMetaphoneAndInvalidInput() throws Exception { final StringEncoderComparator sCompare = new StringEncoderComparator( new DoubleMetaphone() ); final int compare = sCompare.compare(new Double(3.0), Long.valueOf(3)); assertEquals( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code", 0, compare); }
|
UnixCrypt { public static String crypt(final byte[] original) { return crypt(original, null); } static String crypt(final byte[] original); static String crypt(final byte[] original, String salt); static String crypt(final String original); static String crypt(final String original, final String salt); }
|
@Test public void testUnixCryptStrings() { assertEquals("xxWAum7tHdIUw", Crypt.crypt("secret", "xx")); assertEquals("12UFlHxel6uMM", Crypt.crypt("", "12")); assertEquals("12FJgqDtVOg7Q", Crypt.crypt("secret", "12")); assertEquals("12FJgqDtVOg7Q", Crypt.crypt("secret", "12345678")); }
@Test public void testUnixCryptBytes() { assertEquals("12UFlHxel6uMM", Crypt.crypt(new byte[0], "12")); assertEquals("./287bds2PjVw", Crypt.crypt("t\u00e4st", "./")); assertEquals("./bLIFNqo9XKQ", Crypt.crypt("t\u00e4st".getBytes(Charsets.ISO_8859_1), "./")); assertEquals("./bLIFNqo9XKQ", Crypt.crypt(new byte[]{(byte) 0x74, (byte) 0xe4, (byte) 0x73, (byte) 0x74}, "./")); }
@Test public void testUnixCryptExplicitCall() { assertTrue(UnixCrypt.crypt("secret".getBytes()).matches("^[a-zA-Z0-9./]{13}$")); assertTrue(UnixCrypt.crypt("secret".getBytes(), null).matches("^[a-zA-Z0-9./]{13}$")); }
@Test(expected = IllegalArgumentException.class) public void testUnixCryptWithHalfSalt() { UnixCrypt.crypt("secret", "x"); }
@Test(expected = IllegalArgumentException.class) public void testUnicCryptInvalidSalt() { UnixCrypt.crypt("secret", "$a"); }
@Test(expected = NullPointerException.class) public void testUnixCryptNullData() { UnixCrypt.crypt((byte[]) null); }
@Test(expected = IllegalArgumentException.class) public void testUnixCryptWithEmptySalt() { UnixCrypt.crypt("secret", ""); }
@Test public void testUnixCryptWithoutSalt() { final String hash = UnixCrypt.crypt("foo"); assertTrue(hash.matches("^[a-zA-Z0-9./]{13}$")); final String hash2 = UnixCrypt.crypt("foo"); assertNotSame(hash, hash2); }
|
TransactionTemplate { public static void execute( Mango mango, String dataSourceFactoryName, TransactionIsolationLevel level, TransactionAction action) throws TransactionException { execute(TransactionFactory.newTransaction(mango, dataSourceFactoryName, level), action); } static void execute(
Mango mango, String dataSourceFactoryName, TransactionIsolationLevel level,
TransactionAction action); static void execute(Mango mango, String dataSourceFactoryName, TransactionAction action); static void execute(String dataSourceFactoryName, TransactionIsolationLevel level, TransactionAction action); static void execute(String dataSourceFactoryName, TransactionAction action); static void execute(TransactionIsolationLevel level, TransactionAction action); static void execute(TransactionAction action); }
|
@Test public void testCommit() throws Exception { final Account x = new Account(1, 1000); final Account y = new Account(2, 1000); final Account z = new Account(3, 1000); dao.insert(x); dao.insert(y); dao.insert(z); TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { x.add(50); dao.update(x); TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { z.sub(30); dao.update(z); } }); y.sub(20); dao.update(y); } }); } }); assertThat(dao.getAccount(1), equalTo(x)); assertThat(dao.getAccount(2), equalTo(y)); assertThat(dao.getAccount(3), equalTo(z)); }
@Test public void testRollback() throws Exception { final Account x = new Account(1, 1000); final Account y = new Account(2, 2000); final Account z = new Account(3, 3000); dao.insert(x); dao.insert(y); dao.insert(z); TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { x.add(50); dao.update(x); TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { z.sub(30); dao.update(z); status.setRollbackOnly(true); } }); y.sub(20); dao.update(y); } }); } }); assertThat(dao.getAccount(1).getBalance(), equalTo(1000)); assertThat(dao.getAccount(2).getBalance(), equalTo(2000)); assertThat(dao.getAccount(3).getBalance(), equalTo(3000)); }
@Test public void testRollback2() throws Exception { thrown.expect(RuntimeException.class); final Account x = new Account(1, 1000); final Account y = new Account(2, 2000); final Account z = new Account(3, 3000); dao.insert(x); dao.insert(y); dao.insert(z); TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { x.add(50); dao.update(x); TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { TransactionTemplate.execute(mango, AbstractDataSourceFactory.DEFULT_NAME, new TransactionAction() { @Override public void doInTransaction(TransactionStatus status) { z.sub(30); dao.update(z); throw new RuntimeException(); } }); y.sub(20); dao.update(y); } }); } }); assertThat(dao.getAccount(1).getBalance(), equalTo(1000)); assertThat(dao.getAccount(2).getBalance(), equalTo(2000)); assertThat(dao.getAccount(3).getBalance(), equalTo(3000)); }
|
B64 { static void b64from24bit(final byte b2, final byte b1, final byte b0, final int outLen, final StringBuilder buffer) { int w = ((b2 << 16) & 0x00ffffff) | ((b1 << 8) & 0x00ffff) | (b0 & 0xff); int n = outLen; while (n-- > 0) { buffer.append(B64T.charAt(w & 0x3f)); w >>= 6; } } }
|
@Test public void testB64from24bit() { final StringBuilder buffer = new StringBuilder(""); B64.b64from24bit((byte) 8, (byte) 16, (byte) 64, 2, buffer); B64.b64from24bit((byte) 7, (byte) 77, (byte) 120, 4, buffer); assertEquals("./spo/", buffer.toString()); }
|
DigestUtils { public static MessageDigest getDigest(final String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (final NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test(expected=IllegalArgumentException.class) public void testInternalNoSuchAlgorithmException() { DigestUtils.getDigest("Bogus Bogus"); }
|
DigestUtils { public static String md2Hex(final byte[] data) { return Hex.encodeHexString(md2(data)); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testMd2Hex() throws IOException { assertEquals("8350e5a3e24c153df2275c9f80692773", DigestUtils.md2Hex("")); assertEquals("32ec01ec4a6dac72c0ab96fb34c0b5d1", DigestUtils.md2Hex("a")); assertEquals("da853b0d3f88d99b30283a69e6ded6bb", DigestUtils.md2Hex("abc")); assertEquals("ab4f496bfb2a530b219ff33031fe06b0", DigestUtils.md2Hex("message digest")); assertEquals("4e8ddff3650292ab5a4108c3aa47940b", DigestUtils.md2Hex("abcdefghijklmnopqrstuvwxyz")); assertEquals( "da33def2a42df13975352846c30338cd", DigestUtils.md2Hex("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789")); assertEquals( "d5976f79d83d3a0dc9806c3c66f3efd8", DigestUtils.md2Hex("1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890")); assertEquals(DigestUtils.md2Hex(testData), DigestUtils.md2Hex(new ByteArrayInputStream(testData))); }
@Test public void testMd2HexLength() { String hashMe = "this is some string that is longer than 32 characters"; String hash = DigestUtils.md2Hex(getBytesUtf8(hashMe)); assertEquals(32, hash.length()); hashMe = "length < 32"; hash = DigestUtils.md2Hex(getBytesUtf8(hashMe)); assertEquals(32, hash.length()); }
|
DigestUtils { public static byte[] md2(final byte[] data) { return getMd2Digest().digest(data); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testMd2Length() { String hashMe = "this is some string that is longer than 16 characters"; byte[] hash = DigestUtils.md2(getBytesUtf8(hashMe)); assertEquals(16, hash.length); hashMe = "length < 16"; hash = DigestUtils.md2(getBytesUtf8(hashMe)); assertEquals(16, hash.length); }
|
DigestUtils { public static String md5Hex(final byte[] data) { return Hex.encodeHexString(md5(data)); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testMd5Hex() throws IOException { assertEquals("d41d8cd98f00b204e9800998ecf8427e", DigestUtils.md5Hex("")); assertEquals("0cc175b9c0f1b6a831c399e269772661", DigestUtils.md5Hex("a")); assertEquals("900150983cd24fb0d6963f7d28e17f72", DigestUtils.md5Hex("abc")); assertEquals("f96b697d7cb7938d525a2f31aaf161d0", DigestUtils.md5Hex("message digest")); assertEquals("c3fcd3d76192e4007dfb496cca67e13b", DigestUtils.md5Hex("abcdefghijklmnopqrstuvwxyz")); assertEquals( "d174ab98d277d9f5a5611c2c9f419d9f", DigestUtils.md5Hex("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789")); assertEquals( "57edf4a22be3c955ac49da2e2107b67a", DigestUtils.md5Hex("1234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890")); assertEquals(DigestUtils.md5Hex(testData), DigestUtils.md5Hex(new ByteArrayInputStream(testData))); }
@Test public void testMd5HexLength() { String hashMe = "this is some string that is longer than 32 characters"; String hash = DigestUtils.md5Hex(getBytesUtf8(hashMe)); assertEquals(32, hash.length()); hashMe = "length < 32"; hash = DigestUtils.md5Hex(getBytesUtf8(hashMe)); assertEquals(32, hash.length()); }
|
DigestUtils { public static byte[] md5(final byte[] data) { return getMd5Digest().digest(data); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testMd5Length() { String hashMe = "this is some string that is longer than 16 characters"; byte[] hash = DigestUtils.md5(getBytesUtf8(hashMe)); assertEquals(16, hash.length); hashMe = "length < 16"; hash = DigestUtils.md5(getBytesUtf8(hashMe)); assertEquals(16, hash.length); }
|
DigestUtils { public static String sha1Hex(final byte[] data) { return Hex.encodeHexString(sha1(data)); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testSha1Hex() throws IOException { assertEquals("a9993e364706816aba3e25717850c26c9cd0d89d", DigestUtils.sha1Hex("abc")); assertEquals("a9993e364706816aba3e25717850c26c9cd0d89d", DigestUtils.sha1Hex(getBytesUtf8("abc"))); assertEquals( "84983e441c3bd26ebaae4aa1f95129e5e54670f1", DigestUtils.sha1Hex("abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq")); assertEquals(DigestUtils.sha1Hex(testData), DigestUtils.sha1Hex(new ByteArrayInputStream(testData))); }
|
DigestUtils { public static byte[] sha256(final byte[] data) { return getSha256Digest().digest(data); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testSha256() throws IOException { assertEquals("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", DigestUtils.sha256Hex("abc")); assertEquals("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", DigestUtils.sha256Hex(getBytesUtf8("abc"))); assertEquals("248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", DigestUtils.sha256Hex("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")); assertEquals(DigestUtils.sha256Hex(testData), DigestUtils.sha256Hex(new ByteArrayInputStream(testData))); }
|
DigestUtils { public static byte[] sha384(final byte[] data) { return getSha384Digest().digest(data); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testSha384() throws IOException { assertEquals("cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed" + "8086072ba1e7cc2358baeca134c825a7", DigestUtils.sha384Hex("abc")); assertEquals("cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed" + "8086072ba1e7cc2358baeca134c825a7", DigestUtils.sha384Hex(getBytesUtf8("abc"))); assertEquals("09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712" + "fcc7c71a557e2db966c3e9fa91746039", DigestUtils.sha384Hex("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")); assertEquals(DigestUtils.sha384Hex(testData), DigestUtils.sha384Hex(new ByteArrayInputStream(testData))); }
|
DigestUtils { public static byte[] sha512(final byte[] data) { return getSha512Digest().digest(data); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@Test public void testSha512() throws IOException { assertEquals("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", DigestUtils.sha512Hex("abc")); assertEquals("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", DigestUtils.sha512Hex(getBytesUtf8("abc"))); assertEquals("8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018" + "501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909", DigestUtils.sha512Hex("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")); assertEquals(DigestUtils.sha512Hex(testData), DigestUtils.sha512Hex(new ByteArrayInputStream(testData))); }
|
DigestUtils { @Deprecated public static String shaHex(final byte[] data) { return sha1Hex(data); } static MessageDigest getDigest(final String algorithm); static MessageDigest getMd2Digest(); static MessageDigest getMd5Digest(); static MessageDigest getSha1Digest(); static MessageDigest getSha256Digest(); static MessageDigest getSha384Digest(); static MessageDigest getSha512Digest(); @Deprecated static MessageDigest getShaDigest(); static byte[] md2(final byte[] data); static byte[] md2(final InputStream data); static byte[] md2(final String data); static String md2Hex(final byte[] data); static String md2Hex(final InputStream data); static String md2Hex(final String data); static byte[] md5(final byte[] data); static byte[] md5(final InputStream data); static byte[] md5(final String data); static String md5Hex(final byte[] data); static String md5Hex(final InputStream data); static String md5Hex(final String data); @Deprecated static byte[] sha(final byte[] data); @Deprecated static byte[] sha(final InputStream data); @Deprecated static byte[] sha(final String data); static byte[] sha1(final byte[] data); static byte[] sha1(final InputStream data); static byte[] sha1(final String data); static String sha1Hex(final byte[] data); static String sha1Hex(final InputStream data); static String sha1Hex(final String data); static byte[] sha256(final byte[] data); static byte[] sha256(final InputStream data); static byte[] sha256(final String data); static String sha256Hex(final byte[] data); static String sha256Hex(final InputStream data); static String sha256Hex(final String data); static byte[] sha384(final byte[] data); static byte[] sha384(final InputStream data); static byte[] sha384(final String data); static String sha384Hex(final byte[] data); static String sha384Hex(final InputStream data); static String sha384Hex(final String data); static byte[] sha512(final byte[] data); static byte[] sha512(final InputStream data); static byte[] sha512(final String data); static String sha512Hex(final byte[] data); static String sha512Hex(final InputStream data); static String sha512Hex(final String data); @Deprecated static String shaHex(final byte[] data); @Deprecated static String shaHex(final InputStream data); @Deprecated static String shaHex(final String data); static MessageDigest updateDigest(final MessageDigest messageDigest, final byte[] valueToDigest); static MessageDigest updateDigest(final MessageDigest digest, final InputStream data); static MessageDigest updateDigest(final MessageDigest messageDigest, final String valueToDigest); }
|
@SuppressWarnings("deprecation") @Test public void testShaHex() throws IOException { assertEquals("a9993e364706816aba3e25717850c26c9cd0d89d", DigestUtils.shaHex("abc")); assertEquals("a9993e364706816aba3e25717850c26c9cd0d89d", DigestUtils.shaHex(getBytesUtf8("abc"))); assertEquals( "84983e441c3bd26ebaae4aa1f95129e5e54670f1", DigestUtils.shaHex("abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq")); assertEquals(DigestUtils.shaHex(testData), DigestUtils.shaHex(new ByteArrayInputStream(testData))); }
|
HmacUtils { public static Mac getHmacMd5(final byte[] key) { return getInitializedMac(HmacAlgorithms.HMAC_MD5, key); } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testEmptyKey() { HmacUtils.getHmacMd5(new byte[] {}); }
@Test(expected = IllegalArgumentException.class) public void testNullKey() { HmacUtils.getHmacMd5(null); }
|
HmacUtils { public static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest) { return Hex.encodeHexString(hmacMd5(key, valueToDigest)); } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test public void testHmacMd5Hex() throws IOException { assertEquals("80070713463e7749b90c2dc24911e275", HmacUtils.hmacMd5Hex(STANDARD_KEY_STRING, "The quick brown fox jumps over the lazy dog")); assertEquals("750c783e6ab0b503eaa86e310a5db738", HmacUtils.hmacMd5Hex("Jefe", "what do ya want for nothing?")); assertEquals( "750c783e6ab0b503eaa86e310a5db738", HmacUtils.hmacMd5Hex("Jefe".getBytes(), new ByteArrayInputStream("what do ya want for nothing?".getBytes()))); }
|
HmacUtils { public static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest) { return Hex.encodeHexString(hmacSha1(key, valueToDigest)); } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test public void testHmacSha1Hex() throws IOException { assertEquals(STANDARD_SHA1_RESULT_STRING, HmacUtils.hmacSha1Hex(STANDARD_KEY_STRING, STANDARD_PHRASE_STRING)); assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", HmacUtils.hmacSha1Hex(STANDARD_KEY_STRING, "")); assertEquals("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79", HmacUtils.hmacSha1Hex("Jefe", "what do ya want for nothing?")); assertEquals( "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79", HmacUtils.hmacSha1Hex("Jefe".getBytes(), new ByteArrayInputStream("what do ya want for nothing?".getBytes()))); }
|
HmacUtils { public static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key) { return getInitializedMac(algorithm.toString(), key); } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testInitializedMacNullAlgo() throws IOException { HmacUtils.getInitializedMac((String) null, STANDARD_KEY_BYTES); }
@Test(expected = IllegalArgumentException.class) public void testInitializedMacNullKey() throws IOException { HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, null); }
@Test(expected = IllegalArgumentException.class) public void testInternalNoSuchAlgorithmException() { HmacUtils.getInitializedMac("Bogus Bogus", StringUtils.getBytesUtf8("akey")); }
|
HmacUtils { public static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest) { try { return getHmacMd5(key).doFinal(valueToDigest); } catch (final IllegalStateException e) { throw new IllegalArgumentException(e); } } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testMd5HMacFail() throws IOException { HmacUtils.hmacMd5((byte[]) null, STANDARD_PHRASE_BYTES); }
|
HmacUtils { public static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest) { try { return getHmacSha1(key).doFinal(valueToDigest); } catch (final IllegalStateException e) { throw new IllegalArgumentException(e); } } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testSha1HMacFail() throws IOException { HmacUtils.hmacSha1((byte[]) null, STANDARD_PHRASE_BYTES); }
|
HmacUtils { public static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest) { try { return getHmacSha256(key).doFinal(valueToDigest); } catch (final IllegalStateException e) { throw new IllegalArgumentException(e); } } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testSha256HMacFail() throws IOException { HmacUtils.hmacSha256((byte[]) null, STANDARD_PHRASE_BYTES); }
|
HmacUtils { public static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest) { try { return getHmacSha384(key).doFinal(valueToDigest); } catch (final IllegalStateException e) { throw new IllegalArgumentException(e); } } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testSha384HMacFail() throws IOException { HmacUtils.hmacSha384((byte[]) null, STANDARD_PHRASE_BYTES); }
|
HmacUtils { public static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest) { try { return getHmacSha512(key).doFinal(valueToDigest); } catch (final IllegalStateException e) { throw new IllegalArgumentException(e); } } static Mac getHmacMd5(final byte[] key); static Mac getHmacSha1(final byte[] key); static Mac getHmacSha256(final byte[] key); static Mac getHmacSha384(final byte[] key); static Mac getHmacSha512(final byte[] key); static Mac getInitializedMac(final HmacAlgorithms algorithm, final byte[] key); static Mac getInitializedMac(final String algorithm, final byte[] key); static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest); static byte[] hmacMd5(final byte[] key, final InputStream valueToDigest); static byte[] hmacMd5(final String key, final String valueToDigest); static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest); static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest); static String hmacMd5Hex(final String key, final String valueToDigest); static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha1(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha1(final String key, final String valueToDigest); static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha1Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha1Hex(final String key, final String valueToDigest); static byte[] hmacSha256(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha256(final String key, final String valueToDigest); static String hmacSha256Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha256Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha256Hex(final String key, final String valueToDigest); static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha384(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha384(final String key, final String valueToDigest); static String hmacSha384Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha384Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha384Hex(final String key, final String valueToDigest); static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest); static byte[] hmacSha512(final byte[] key, final InputStream valueToDigest); static byte[] hmacSha512(final String key, final String valueToDigest); static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest); static String hmacSha512Hex(final byte[] key, final InputStream valueToDigest); static String hmacSha512Hex(final String key, final String valueToDigest); static Mac updateHmac(final Mac mac, final byte[] valueToDigest); static Mac updateHmac(final Mac mac, final InputStream valueToDigest); static Mac updateHmac(final Mac mac, final String valueToDigest); }
|
@Test(expected = IllegalArgumentException.class) public void testSha512HMacFail() throws IOException { HmacUtils.hmacSha512((byte[]) null, STANDARD_PHRASE_BYTES); }
|
MethodNameParser { public static MethodNameInfo parse(String str) { OrderUnit ou = parseOrderUnit(str); if (ou != null) { str = str.substring(0, str.length() - ou.getOrderStrSize()); } List<OpUnit> opUnits = new ArrayList<OpUnit>(); List<String> logics = new ArrayList<String>(); Pattern p = Pattern.compile(LOGIC_REGEX); Matcher m = p.matcher(str); int index = 0; while (m.find()) { opUnits.add(OpUnit.create(str.substring(index, m.start()))); logics.add(Strings.firstLetterToLowerCase(m.group())); index = m.end(); } opUnits.add(OpUnit.create(str.substring(index))); return new MethodNameInfo(opUnits, logics, ou); } static MethodNameInfo parse(String str); }
|
@Test public void parse() throws Exception { MethodNameInfo info = MethodNameParser.parse("EmailAddressAndLastnameLessThanOrIdOrderByUserIdDesc"); assertThat(info.getLogics(), equalTo(Arrays.asList("and", "or"))); OrderUnit ou = info.getOrderUnit(); assertThat(ou.getOrderType(), equalTo(OrderType.DESC)); assertThat(ou.getProperty(), equalTo("userId")); assertThat(ou.getOrderStrSize(), equalTo(17)); List<OpUnit> ous = info.getOpUnits(); assertThat(ous.size(), equalTo(3)); assertThat(ous.get(0).getOp(), equalTo((Op) new EqualsOp())); assertThat(ous.get(0).getProperty(), equalTo("emailAddress")); assertThat(ous.get(1).getOp(), equalTo((Op) new LessThanOp())); assertThat(ous.get(1).getProperty(), equalTo("lastname")); assertThat(ous.get(2).getOp(), equalTo((Op) new EqualsOp())); assertThat(ous.get(2).getProperty(), equalTo("id")); }
|
DynamicTokens { public static <E> TypeToken<List<E>> listToken(TypeToken<E> entityToken) { return new TypeToken<List<E>>() {} .where(new TypeParameter<E>() {}, entityToken); } static TypeToken<Collection<E>> collectionToken(TypeToken<E> entityToken); static TypeToken<List<E>> listToken(TypeToken<E> entityToken); }
|
@Test public void testListToken() throws Exception { TypeToken<List<String>> token = DynamicTokens.listToken(TypeToken.of(String.class)); Type expectedType = DynamicTokensTest.class.getMethod("func2").getGenericReturnType(); assertThat(token.getType(), equalTo(expectedType)); }
|
Crypt { public static String crypt(final byte[] keyBytes) { return crypt(keyBytes, null); } static String crypt(final byte[] keyBytes); static String crypt(final byte[] keyBytes, final String salt); static String crypt(final String key); static String crypt(final String key, final String salt); }
|
@Test public void testCrypt() { assertNotNull(new Crypt()); }
@Test public void testDefaultCryptVariant() { assertTrue(Crypt.crypt("secret").startsWith("$6$")); assertTrue(Crypt.crypt("secret", null).startsWith("$6$")); }
@Test public void testCryptWithBytes() { final byte[] keyBytes = new byte[] { 'b', 'y', 't', 'e' }; final String hash = Crypt.crypt(keyBytes); assertEquals(hash, Crypt.crypt("byte", hash)); }
@Test(expected = IllegalArgumentException.class) public void testCryptWithEmptySalt() { Crypt.crypt("secret", ""); }
|
Md5Crypt { public static String md5Crypt(final byte[] keyBytes) { return md5Crypt(keyBytes, MD5_PREFIX + B64.getRandomSalt(8)); } static String apr1Crypt(final byte[] keyBytes); static String apr1Crypt(final byte[] keyBytes, String salt); static String apr1Crypt(final String keyBytes); static String apr1Crypt(final String keyBytes, final String salt); static String md5Crypt(final byte[] keyBytes); static String md5Crypt(final byte[] keyBytes, final String salt); static String md5Crypt(final byte[] keyBytes, final String salt, final String prefix); }
|
@Test public void testMd5CryptExplicitCall() { assertTrue(Md5Crypt.md5Crypt("secret".getBytes()).matches("^\\$1\\$[a-zA-Z0-9./]{0,8}\\$.{1,}$")); assertTrue(Md5Crypt.md5Crypt("secret".getBytes(), null).matches("^\\$1\\$[a-zA-Z0-9./]{0,8}\\$.{1,}$")); }
@Test(expected = NullPointerException.class) public void testMd5CryptNullData() { Md5Crypt.md5Crypt((byte[]) null); }
@Test(expected = IllegalArgumentException.class) public void testMd5CryptWithEmptySalt() { Md5Crypt.md5Crypt("secret".getBytes(), ""); }
|
StringUtils { public static byte[] getBytesIso8859_1(final String string) { return getBytes(string, Charsets.ISO_8859_1); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesIso8859_1() throws UnsupportedEncodingException { final String charsetName = "ISO-8859-1"; testGetBytesUnchecked(charsetName); final byte[] expected = STRING_FIXTURE.getBytes(charsetName); final byte[] actual = StringUtils.getBytesIso8859_1(STRING_FIXTURE); Assert.assertTrue(Arrays.equals(expected, actual)); }
|
StringUtils { public static byte[] getBytesUsAscii(final String string) { return getBytes(string, Charsets.US_ASCII); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesUsAscii() throws UnsupportedEncodingException { final String charsetName = "US-ASCII"; testGetBytesUnchecked(charsetName); final byte[] expected = STRING_FIXTURE.getBytes(charsetName); final byte[] actual = StringUtils.getBytesUsAscii(STRING_FIXTURE); Assert.assertTrue(Arrays.equals(expected, actual)); }
|
StringUtils { public static byte[] getBytesUtf16(final String string) { return getBytes(string, Charsets.UTF_16); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesUtf16() throws UnsupportedEncodingException { final String charsetName = "UTF-16"; testGetBytesUnchecked(charsetName); final byte[] expected = STRING_FIXTURE.getBytes(charsetName); final byte[] actual = StringUtils.getBytesUtf16(STRING_FIXTURE); Assert.assertTrue(Arrays.equals(expected, actual)); }
|
MethodNameParser { @Nullable static OrderUnit parseOrderUnit(String str) { Pattern p = Pattern.compile(ORDER_BY_REGEX); Matcher m = p.matcher(str); if (m.find()) { String tailStr = Strings.firstLetterToLowerCase(str.substring(m.end() - 1)); int size = ORDER_BY.length() + tailStr.length(); String property; OrderType orderType; if (tailStr.endsWith(DESC)) { property = tailStr.substring(0, tailStr.length() - DESC.length()); orderType = OrderType.DESC; } else if (tailStr.endsWith(ASC)) { property = tailStr.substring(0, tailStr.length() - ASC.length()); orderType = OrderType.ASC; } else { property = tailStr; orderType = OrderType.NONE; } return new OrderUnit(property, orderType, size); } return null; } static MethodNameInfo parse(String str); }
|
@Test public void parseOrderUnit() throws Exception { OrderUnit ou = MethodNameParser.parseOrderUnit("AgeAndNameOrderByIdDesc"); assertThat(ou.getProperty(), equalTo("id")); assertThat(ou.getOrderType(), equalTo(OrderType.DESC)); assertThat(ou.getOrderStrSize(), equalTo("OrderByIdDesc".length())); ou = MethodNameParser.parseOrderUnit("AgeAndNameOrderByUserNameAsc"); assertThat(ou.getProperty(), equalTo("userName")); assertThat(ou.getOrderType(), equalTo(OrderType.ASC)); assertThat(ou.getOrderStrSize(), equalTo("OrderByUserNameAsc".length())); ou = MethodNameParser.parseOrderUnit("AgeAndNameOrderByAgeU"); assertThat(ou.getProperty(), equalTo("ageU")); assertThat(ou.getOrderType(), equalTo(OrderType.NONE)); assertThat(ou.getOrderStrSize(), equalTo("OrderByAgeU".length())); }
|
StringUtils { public static byte[] getBytesUtf16Be(final String string) { return getBytes(string, Charsets.UTF_16BE); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesUtf16Be() throws UnsupportedEncodingException { final String charsetName = "UTF-16BE"; testGetBytesUnchecked(charsetName); final byte[] expected = STRING_FIXTURE.getBytes(charsetName); final byte[] actual = StringUtils.getBytesUtf16Be(STRING_FIXTURE); Assert.assertTrue(Arrays.equals(expected, actual)); }
|
StringUtils { public static byte[] getBytesUtf16Le(final String string) { return getBytes(string, Charsets.UTF_16LE); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesUtf16Le() throws UnsupportedEncodingException { final String charsetName = "UTF-16LE"; testGetBytesUnchecked(charsetName); final byte[] expected = STRING_FIXTURE.getBytes(charsetName); final byte[] actual = StringUtils.getBytesUtf16Le(STRING_FIXTURE); Assert.assertTrue(Arrays.equals(expected, actual)); }
|
StringUtils { public static byte[] getBytesUtf8(final String string) { return getBytes(string, Charsets.UTF_8); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesUtf8() throws UnsupportedEncodingException { final String charsetName = "UTF-8"; testGetBytesUnchecked(charsetName); final byte[] expected = STRING_FIXTURE.getBytes(charsetName); final byte[] actual = StringUtils.getBytesUtf8(STRING_FIXTURE); Assert.assertTrue(Arrays.equals(expected, actual)); }
|
StringUtils { public static byte[] getBytesUnchecked(final String string, final String charsetName) { if (string == null) { return null; } try { return string.getBytes(charsetName); } catch (final UnsupportedEncodingException e) { throw StringUtils.newIllegalStateException(charsetName, e); } } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testGetBytesUncheckedBadName() { try { StringUtils.getBytesUnchecked(STRING_FIXTURE, "UNKNOWN"); Assert.fail("Expected " + IllegalStateException.class.getName()); } catch (final IllegalStateException e) { } }
@Test public void testGetBytesUncheckedNullInput() { Assert.assertNull(StringUtils.getBytesUnchecked(null, "UNKNOWN")); }
|
StringUtils { private static String newString(final byte[] bytes, final Charset charset) { return bytes == null ? null : new String(bytes, charset); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testNewStringBadEnc() { try { StringUtils.newString(BYTES_FIXTURE, "UNKNOWN"); Assert.fail("Expected " + IllegalStateException.class.getName()); } catch (final IllegalStateException e) { } }
@Test public void testNewStringNullInput() { Assert.assertNull(StringUtils.newString(null, "UNKNOWN")); }
|
StringUtils { public static String newStringIso8859_1(final byte[] bytes) { return new String(bytes, Charsets.ISO_8859_1); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testNewStringIso8859_1() throws UnsupportedEncodingException { final String charsetName = "ISO-8859-1"; testNewString(charsetName); final String expected = new String(BYTES_FIXTURE, charsetName); final String actual = StringUtils.newStringIso8859_1(BYTES_FIXTURE); Assert.assertEquals(expected, actual); }
|
StringUtils { public static String newStringUsAscii(final byte[] bytes) { return new String(bytes, Charsets.US_ASCII); } static boolean equals(final CharSequence cs1, final CharSequence cs2); static byte[] getBytesIso8859_1(final String string); static byte[] getBytesUnchecked(final String string, final String charsetName); static byte[] getBytesUsAscii(final String string); static byte[] getBytesUtf16(final String string); static byte[] getBytesUtf16Be(final String string); static byte[] getBytesUtf16Le(final String string); static byte[] getBytesUtf8(final String string); static String newString(final byte[] bytes, final String charsetName); static String newStringIso8859_1(final byte[] bytes); static String newStringUsAscii(final byte[] bytes); static String newStringUtf16(final byte[] bytes); static String newStringUtf16Be(final byte[] bytes); static String newStringUtf16Le(final byte[] bytes); static String newStringUtf8(final byte[] bytes); }
|
@Test public void testNewStringUsAscii() throws UnsupportedEncodingException { final String charsetName = "US-ASCII"; testNewString(charsetName); final String expected = new String(BYTES_FIXTURE, charsetName); final String actual = StringUtils.newStringUsAscii(BYTES_FIXTURE); Assert.assertEquals(expected, actual); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.