method2testcases
stringlengths 118
6.63k
|
---|
### Question:
BinaryPredicatePredicate implements Predicate<A> { public boolean test(A obj) { return predicate.test(obj, obj); } BinaryPredicatePredicate(BinaryPredicate<? super A, ? super A> predicate); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Predicate<A> adapt(BinaryPredicate<? super A, ? super A> predicate); }### Answer:
@Test public void testTestWhenTrue() throws Exception { Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsSame.INSTANCE); assertTrue(p.test(null)); }
@Test public void testTestWhenFalse() throws Exception { Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsNotSame.INSTANCE); assertFalse(p.test(null)); }
|
### Question:
BinaryPredicatePredicate implements Predicate<A> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BinaryPredicatePredicate<?>)) { return false; } BinaryPredicatePredicate<?> that = (BinaryPredicatePredicate<?>) obj; return this.predicate.equals(that.predicate); } BinaryPredicatePredicate(BinaryPredicate<? super A, ? super A> predicate); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Predicate<A> adapt(BinaryPredicate<? super A, ? super A> predicate); }### Answer:
@Test public void testEquals() throws Exception { Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsSame.INSTANCE); assertEquals(p, p); assertObjectsAreEqual(p, new BinaryPredicatePredicate<Object>(IsSame.INSTANCE)); assertObjectsAreNotEqual(p, Constant.truePredicate()); assertObjectsAreNotEqual(p, new BinaryPredicatePredicate<Object>(IsNotSame.INSTANCE)); }
|
### Question:
BinaryPredicatePredicate implements Predicate<A> { public static <A> Predicate<A> adapt(BinaryPredicate<? super A, ? super A> predicate) { return null == predicate ? null : new BinaryPredicatePredicate<A>(predicate); } BinaryPredicatePredicate(BinaryPredicate<? super A, ? super A> predicate); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Predicate<A> adapt(BinaryPredicate<? super A, ? super A> predicate); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BinaryPredicatePredicate.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(BinaryPredicatePredicate.adapt(Constant.TRUE)); }
|
### Question:
RightBoundFunction implements Function<A, T> { public T evaluate(A obj) { return function.evaluate(obj, param); } @SuppressWarnings("unchecked") <R> RightBoundFunction(BinaryFunction<? super A, ? super R, ? extends T> function, R arg); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static RightBoundFunction<L, T> bind(BinaryFunction<? super L, ? super R, ? extends T> function,
R arg); }### Answer:
@Test public void testEvaluate() throws Exception { Function<String, String> f = RightBoundFunction.bind(LeftIdentity.<String, String>function(),"foo"); assertEquals("xyzzy",f.evaluate("xyzzy")); }
|
### Question:
RightBoundFunction implements Function<A, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof RightBoundFunction<?, ?>)) { return false; } RightBoundFunction<?, ?> that = (RightBoundFunction<?, ?>) obj; return function.equals(that.function) && (null == param ? null == that.param : param.equals(that.param)); } @SuppressWarnings("unchecked") <R> RightBoundFunction(BinaryFunction<? super A, ? super R, ? extends T> function, R arg); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static RightBoundFunction<L, T> bind(BinaryFunction<? super L, ? super R, ? extends T> function,
R arg); }### Answer:
@Test public void testEquals() throws Exception { Function<Object, Object> f = RightBoundFunction.bind(LeftIdentity.FUNCTION,"xyzzy"); assertEquals(f,f); assertObjectsAreEqual(f,new RightBoundFunction<Object, Object>(LeftIdentity.FUNCTION,"xyzzy")); assertObjectsAreNotEqual(f,Constant.of("xyzzy")); assertObjectsAreNotEqual(f,new RightBoundFunction<Object, Object>(RightIdentity.FUNCTION,"xyzzy")); assertObjectsAreNotEqual(f,new RightBoundFunction<Object, Object>(LeftIdentity.FUNCTION,"bar")); assertObjectsAreNotEqual(f,new RightBoundFunction<Object, Object>(LeftIdentity.FUNCTION,null)); assertObjectsAreEqual(new RightBoundFunction<Object, Object>(LeftIdentity.FUNCTION,null),new RightBoundFunction<Object, Object>(LeftIdentity.FUNCTION,null)); assertTrue(!f.equals(null)); }
|
### Question:
RightBoundFunction implements Function<A, T> { public static <L, R, T> RightBoundFunction<L, T> bind(BinaryFunction<? super L, ? super R, ? extends T> function, R arg) { return null == function ? null : new RightBoundFunction<L, T>(function, arg); } @SuppressWarnings("unchecked") <R> RightBoundFunction(BinaryFunction<? super A, ? super R, ? extends T> function, R arg); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static RightBoundFunction<L, T> bind(BinaryFunction<? super L, ? super R, ? extends T> function,
R arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(RightBoundFunction.bind(null,"xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(RightBoundFunction.bind(LeftIdentity.FUNCTION,"xyzzy")); assertNotNull(RightBoundFunction.bind(LeftIdentity.FUNCTION,null)); }
|
### Question:
IgnoreRightProcedure implements BinaryProcedure<L, R> { public void run(L left, R right) { procedure.run(left); } IgnoreRightProcedure(Procedure<? super L> procedure); void run(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightProcedure<L, R> adapt(Procedure<? super L> procedure); }### Answer:
@Test public void testEvaluate() throws Exception { BinaryProcedure<Object, Object> p = new IgnoreRightProcedure<Object, Object>( new FunctionProcedure<Object>(Identity.INSTANCE)); p.run(Boolean.TRUE,null); }
|
### Question:
IgnoreRightProcedure implements BinaryProcedure<L, R> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IgnoreRightProcedure<?, ?>)) { return false; } IgnoreRightProcedure<?, ?> that = (IgnoreRightProcedure<?, ?>) obj; return this.procedure.equals(that.procedure); } IgnoreRightProcedure(Procedure<? super L> procedure); void run(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightProcedure<L, R> adapt(Procedure<? super L> procedure); }### Answer:
@Test public void testEquals() throws Exception { BinaryProcedure<Object, Object> p = new IgnoreRightProcedure<Object, Object>(NoOp.INSTANCE); assertEquals(p,p); assertObjectsAreEqual(p,new IgnoreRightProcedure<Object, Object>(NoOp.INSTANCE)); assertObjectsAreNotEqual(p,NoOp.INSTANCE); assertObjectsAreNotEqual(p,new IgnoreRightProcedure<Object, Object>(new Procedure<Object>() { public void run(Object obj) { } })); assertTrue(!p.equals(null)); }
|
### Question:
IgnoreRightProcedure implements BinaryProcedure<L, R> { public static <L, R> IgnoreRightProcedure<L, R> adapt(Procedure<? super L> procedure) { return null == procedure ? null : new IgnoreRightProcedure<L, R>(procedure); } IgnoreRightProcedure(Procedure<? super L> procedure); void run(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightProcedure<L, R> adapt(Procedure<? super L> procedure); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(IgnoreRightProcedure.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(IgnoreRightProcedure.adapt(NoOp.INSTANCE)); }
|
### Question:
BinaryProcedureBinaryFunction implements BinaryFunction<L, R, T> { public T evaluate(L left, R right) { procedure.run(left, right); return null; } BinaryProcedureBinaryFunction(BinaryProcedure<? super L, ? super R> procedure); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryProcedureBinaryFunction<L, R, T> adapt(
BinaryProcedure<? super L, ? super R> procedure); }### Answer:
@Test public void testEvaluate() throws Exception { BinaryFunction<Object, Object, Object> f = new BinaryProcedureBinaryFunction<Object, Object, Object>(NoOp.instance()); assertNull(f.evaluate(null,null)); }
|
### Question:
BinaryProcedureBinaryFunction implements BinaryFunction<L, R, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BinaryProcedureBinaryFunction<?, ?, ?>)) { return false; } BinaryProcedureBinaryFunction<?, ?, ?> that = (BinaryProcedureBinaryFunction<?, ?, ?>) obj; return this.procedure.equals(that.procedure); } BinaryProcedureBinaryFunction(BinaryProcedure<? super L, ? super R> procedure); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryProcedureBinaryFunction<L, R, T> adapt(
BinaryProcedure<? super L, ? super R> procedure); }### Answer:
@Test public void testEquals() throws Exception { BinaryFunction<Object, Object, Object> f = new BinaryProcedureBinaryFunction<Object, Object, Object>(new NoOp()); assertEquals(f,f); assertObjectsAreEqual(f,new BinaryProcedureBinaryFunction<Object, Object, Object>(new NoOp())); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f, new BinaryProcedureBinaryFunction<Object, Object, Object>( new BinaryProcedure<Object, Object>() { public void run(Object a, Object b) { } })); assertObjectsAreNotEqual(f,Constant.of(null)); }
|
### Question:
BinaryProcedureBinaryFunction implements BinaryFunction<L, R, T> { public static <L, R, T> BinaryProcedureBinaryFunction<L, R, T> adapt( BinaryProcedure<? super L, ? super R> procedure) { return null == procedure ? null : new BinaryProcedureBinaryFunction<L, R, T>(procedure); } BinaryProcedureBinaryFunction(BinaryProcedure<? super L, ? super R> procedure); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryProcedureBinaryFunction<L, R, T> adapt(
BinaryProcedure<? super L, ? super R> procedure); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BinaryProcedureBinaryFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(BinaryProcedureBinaryFunction.adapt(NoOp.instance())); }
|
### Question:
BoundNullaryProcedure implements NullaryProcedure { public void run() { procedure.run(param); } @SuppressWarnings("unchecked") <A> BoundNullaryProcedure(Procedure<? super A> procedure, A arg); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryProcedure bind(Procedure<? super A> procedure, A arg); }### Answer:
@Test public void testRun() throws Exception { NullaryProcedure p = new BoundNullaryProcedure(new FunctionProcedure<Object>(Identity.INSTANCE),Boolean.TRUE); p.run(); }
|
### Question:
BoundNullaryProcedure implements NullaryProcedure { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BoundNullaryProcedure)) { return false; } BoundNullaryProcedure that = (BoundNullaryProcedure) obj; return procedure.equals(that.procedure) && (null == param ? null == that.param : param.equals(that.param)); } @SuppressWarnings("unchecked") <A> BoundNullaryProcedure(Procedure<? super A> procedure, A arg); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryProcedure bind(Procedure<? super A> procedure, A arg); }### Answer:
@Test public void testEquals() throws Exception { NullaryProcedure f = new BoundNullaryProcedure(NoOp.INSTANCE,"xyzzy"); assertEquals(f,f); assertObjectsAreEqual(f,new BoundNullaryProcedure(NoOp.INSTANCE,"xyzzy")); assertObjectsAreNotEqual(f,NoOp.INSTANCE); assertObjectsAreNotEqual(f,new BoundNullaryProcedure(NoOp.INSTANCE,"foo")); assertObjectsAreNotEqual(f,new BoundNullaryProcedure(new FunctionProcedure<Object>(Identity.INSTANCE),"xyzzy")); assertObjectsAreNotEqual(f,new BoundNullaryProcedure(NoOp.INSTANCE,null)); assertObjectsAreEqual(new BoundNullaryProcedure(NoOp.INSTANCE,null),new BoundNullaryProcedure(NoOp.INSTANCE,null)); assertTrue(!f.equals(null)); }
|
### Question:
BoundNullaryProcedure implements NullaryProcedure { public static <A> BoundNullaryProcedure bind(Procedure<? super A> procedure, A arg) { return null == procedure ? null : new BoundNullaryProcedure(procedure, arg); } @SuppressWarnings("unchecked") <A> BoundNullaryProcedure(Procedure<? super A> procedure, A arg); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryProcedure bind(Procedure<? super A> procedure, A arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BoundNullaryProcedure.bind(null,"xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(BoundNullaryProcedure.bind(new NoOp(),"xyzzy")); assertNotNull(BoundNullaryProcedure.bind(new NoOp(),null)); }
|
### Question:
BinaryFunctionBinaryProcedure implements BinaryProcedure<L, R> { public void run(L left, R right) { function.evaluate(left, right); } BinaryFunctionBinaryProcedure(BinaryFunction<? super L, ? super R, ?> function); void run(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryFunctionBinaryProcedure<L, R> adapt(BinaryFunction<? super L, ? super R, ?> function); }### Answer:
@Test public void testRun() throws Exception { class EvaluateCounter implements BinaryFunction<Object, Object, Integer> { int count = 0; public Integer evaluate(Object a, Object b) { return Integer.valueOf(count++); } } EvaluateCounter counter = new EvaluateCounter(); BinaryProcedure<Object, Object> p = new BinaryFunctionBinaryProcedure<Object, Object>(counter); assertEquals(0,counter.count); p.run(null,null); assertEquals(1,counter.count); p.run("x","y"); assertEquals(2,counter.count); }
|
### Question:
BinaryFunctionBinaryProcedure implements BinaryProcedure<L, R> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BinaryFunctionBinaryProcedure<?, ?>)) { return false; } BinaryFunctionBinaryProcedure<?, ?> that = (BinaryFunctionBinaryProcedure<?, ?>) obj; return this.function.equals(that.function); } BinaryFunctionBinaryProcedure(BinaryFunction<? super L, ? super R, ?> function); void run(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryFunctionBinaryProcedure<L, R> adapt(BinaryFunction<? super L, ? super R, ?> function); }### Answer:
@Test public void testEquals() throws Exception { BinaryProcedure<Object, Object> p = new BinaryFunctionBinaryProcedure<Object, Object>(Constant.of("K")); assertEquals(p,p); assertObjectsAreEqual(p,new BinaryFunctionBinaryProcedure<Object, Object>(Constant.of("K"))); assertObjectsAreNotEqual(p,new NoOp()); assertObjectsAreNotEqual(p,new BinaryFunctionBinaryProcedure<Object, Object>(Constant.of("J"))); assertTrue(!p.equals(null)); }
|
### Question:
BinaryFunctionBinaryProcedure implements BinaryProcedure<L, R> { public static <L, R> BinaryFunctionBinaryProcedure<L, R> adapt(BinaryFunction<? super L, ? super R, ?> function) { return null == function ? null : new BinaryFunctionBinaryProcedure<L, R>(function); } BinaryFunctionBinaryProcedure(BinaryFunction<? super L, ? super R, ?> function); void run(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryFunctionBinaryProcedure<L, R> adapt(BinaryFunction<? super L, ? super R, ?> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BinaryFunctionBinaryProcedure.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(BinaryFunctionBinaryProcedure.adapt(Constant.of("K"))); }
|
### Question:
NullaryFunctionNullaryPredicate implements NullaryPredicate { public boolean test() { return function.evaluate().booleanValue(); } NullaryFunctionNullaryPredicate(NullaryFunction<Boolean> function); boolean test(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionNullaryPredicate adapt(NullaryFunction<Boolean> function); }### Answer:
@Test public void testTestWhenTrue() throws Exception { NullaryPredicate p = new NullaryFunctionNullaryPredicate(Constant.TRUE); assertTrue(p.test()); }
@Test public void testTestWhenFalse() throws Exception { NullaryPredicate p = new NullaryFunctionNullaryPredicate(Constant.FALSE); assertTrue(!p.test()); }
|
### Question:
NullaryFunctionNullaryPredicate implements NullaryPredicate { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof NullaryFunctionNullaryPredicate)) { return false; } NullaryFunctionNullaryPredicate that = (NullaryFunctionNullaryPredicate) obj; return this.function.equals(that.function); } NullaryFunctionNullaryPredicate(NullaryFunction<Boolean> function); boolean test(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionNullaryPredicate adapt(NullaryFunction<Boolean> function); }### Answer:
@Test public void testEquals() throws Exception { NullaryPredicate p = new NullaryFunctionNullaryPredicate(Constant.TRUE); assertEquals(p,p); assertObjectsAreEqual(p,new NullaryFunctionNullaryPredicate(Constant.TRUE)); assertObjectsAreNotEqual(p,Constant.TRUE); assertObjectsAreNotEqual(p,new NullaryFunctionNullaryPredicate(Constant.FALSE)); assertTrue(!p.equals(null)); }
|
### Question:
NullaryFunctionNullaryPredicate implements NullaryPredicate { public static NullaryFunctionNullaryPredicate adapt(NullaryFunction<Boolean> function) { return null == function ? null : new NullaryFunctionNullaryPredicate(function); } NullaryFunctionNullaryPredicate(NullaryFunction<Boolean> function); boolean test(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionNullaryPredicate adapt(NullaryFunction<Boolean> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(NullaryFunctionNullaryPredicate.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(NullaryFunctionNullaryPredicate.adapt(Constant.TRUE)); }
|
### Question:
NullaryPredicatePredicate implements Predicate<A> { public boolean test(Object obj) { return predicate.test(); } NullaryPredicatePredicate(NullaryPredicate predicate); boolean test(Object obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryPredicatePredicate<A> adapt(NullaryPredicate predicate); }### Answer:
@Test public void testEvaluate() throws Exception { Predicate<Object> p = new NullaryPredicatePredicate<Object>(Constant.TRUE); assertTrue(p.test(null)); }
|
### Question:
NullaryPredicatePredicate implements Predicate<A> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof NullaryPredicatePredicate<?>)) { return false; } NullaryPredicatePredicate<?> that = (NullaryPredicatePredicate<?>) obj; return this.predicate.equals(that.predicate); } NullaryPredicatePredicate(NullaryPredicate predicate); boolean test(Object obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryPredicatePredicate<A> adapt(NullaryPredicate predicate); }### Answer:
@Test public void testEquals() throws Exception { Predicate<Object> p = new NullaryPredicatePredicate<Object>(Constant.TRUE); assertEquals(p,p); assertObjectsAreEqual(p,new NullaryPredicatePredicate<Object>(Constant.TRUE)); assertObjectsAreNotEqual(p,Constant.TRUE); assertObjectsAreNotEqual(p,new NullaryPredicatePredicate<Object>(Constant.FALSE)); assertObjectsAreNotEqual(p,Constant.FALSE); assertTrue(!p.equals(null)); }
|
### Question:
NullaryPredicatePredicate implements Predicate<A> { public static <A> NullaryPredicatePredicate<A> adapt(NullaryPredicate predicate) { return null == predicate ? null : new NullaryPredicatePredicate<A>(predicate); } NullaryPredicatePredicate(NullaryPredicate predicate); boolean test(Object obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryPredicatePredicate<A> adapt(NullaryPredicate predicate); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(NullaryPredicatePredicate.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(NullaryPredicatePredicate.adapt(Constant.TRUE)); }
|
### Question:
IgnoreLeftFunction implements BinaryFunction<L, R, T> { public T evaluate(L left, R right) { return function.evaluate(right); } IgnoreLeftFunction(Function<? super R, ? extends T> function); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreLeftFunction<L, R, T> adapt(Function<? super R, ? extends T> function); }### Answer:
@Test public void testEvaluate() throws Exception { BinaryFunction<String, String, String> f = new IgnoreLeftFunction<String, String, String>(new Identity<String>()); assertNull(f.evaluate(null,null)); assertNull(f.evaluate("xyzzy",null)); assertEquals("xyzzy",f.evaluate(null,"xyzzy")); assertEquals("xyzzy",f.evaluate("abc","xyzzy")); }
|
### Question:
IgnoreLeftFunction implements BinaryFunction<L, R, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IgnoreLeftFunction<?, ?, ?>)) { return false; } IgnoreLeftFunction<?, ?, ?> that = (IgnoreLeftFunction<?, ?, ?>) obj; return this.function.equals(that.function); } IgnoreLeftFunction(Function<? super R, ? extends T> function); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreLeftFunction<L, R, T> adapt(Function<? super R, ? extends T> function); }### Answer:
@Test public void testEquals() throws Exception { BinaryFunction<Object, Object, String> f = new IgnoreLeftFunction<Object, Object, String>(Constant.of("xyzzy")); assertEquals(f,f); assertObjectsAreEqual(f,new IgnoreLeftFunction<Object, Object, String>(Constant.of("xyzzy"))); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f,new IgnoreLeftFunction<Object, Object, String>(Constant.<String>of(null))); assertObjectsAreNotEqual(f,Constant.of(null)); assertTrue(!f.equals(null)); }
|
### Question:
IgnoreLeftFunction implements BinaryFunction<L, R, T> { public static <L, R, T> IgnoreLeftFunction<L, R, T> adapt(Function<? super R, ? extends T> function) { return null == function ? null : new IgnoreLeftFunction<L, R, T>(function); } IgnoreLeftFunction(Function<? super R, ? extends T> function); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreLeftFunction<L, R, T> adapt(Function<? super R, ? extends T> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(IgnoreLeftFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(IgnoreLeftFunction.adapt(Constant.of("xyzzy"))); }
|
### Question:
BoundNullaryPredicate implements NullaryPredicate { public boolean test() { return predicate.test(param); } @SuppressWarnings("unchecked") <A> BoundNullaryPredicate(Predicate<? super A> predicate, A arg); boolean test(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryPredicate bind(Predicate<? super A> predicate, A arg); }### Answer:
@Test public void testTest() throws Exception { { NullaryPredicate p = new BoundNullaryPredicate(new FunctionPredicate<Boolean>(Identity.<Boolean>instance()),Boolean.TRUE); assertTrue(p.test()); } { NullaryPredicate p = new BoundNullaryPredicate(new FunctionPredicate<Boolean>(Identity.<Boolean>instance()),Boolean.FALSE); assertFalse(p.test()); } }
|
### Question:
BoundNullaryPredicate implements NullaryPredicate { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BoundNullaryPredicate)) { return false; } BoundNullaryPredicate that = (BoundNullaryPredicate) obj; return predicate.equals(that.predicate) && (null == param ? null == that.param : param.equals(that.param)); } @SuppressWarnings("unchecked") <A> BoundNullaryPredicate(Predicate<? super A> predicate, A arg); boolean test(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryPredicate bind(Predicate<? super A> predicate, A arg); }### Answer:
@Test public void testEquals() throws Exception { NullaryPredicate f = new BoundNullaryPredicate(Constant.TRUE,"xyzzy"); assertEquals(f,f); assertObjectsAreEqual(f,new BoundNullaryPredicate(Constant.TRUE,"xyzzy")); assertObjectsAreNotEqual(f,Constant.TRUE); assertObjectsAreNotEqual(f,new BoundNullaryPredicate(Constant.TRUE,"foo")); assertObjectsAreNotEqual(f,new BoundNullaryPredicate(Constant.FALSE,"xyzzy")); assertObjectsAreNotEqual(f,new BoundNullaryPredicate(Constant.TRUE,null)); assertObjectsAreEqual(new BoundNullaryPredicate(Constant.TRUE,null),new BoundNullaryPredicate(Constant.TRUE,null)); assertTrue(!f.equals(null)); }
|
### Question:
BoundNullaryPredicate implements NullaryPredicate { public static <A> BoundNullaryPredicate bind(Predicate<? super A> predicate, A arg) { return null == predicate ? null : new BoundNullaryPredicate(predicate, arg); } @SuppressWarnings("unchecked") <A> BoundNullaryPredicate(Predicate<? super A> predicate, A arg); boolean test(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryPredicate bind(Predicate<? super A> predicate, A arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BoundNullaryPredicate.bind(null,"xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(BoundNullaryPredicate.bind(Constant.TRUE,"xyzzy")); assertNotNull(BoundNullaryPredicate.bind(Constant.TRUE,null)); }
|
### Question:
ProcedureFunction implements Function<A, T> { public T evaluate(A obj) { procedure.run(obj); return null; } ProcedureFunction(Procedure<? super A> procedure); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static ProcedureFunction<A, T> adapt(Procedure<? super A> procedure); }### Answer:
@Test public void testEvaluate() throws Exception { Function<Object, Object> f = new ProcedureFunction<Object, Object>(NoOp.INSTANCE); assertNull(f.evaluate(null)); }
|
### Question:
ProcedureFunction implements Function<A, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ProcedureFunction<?, ?>)) { return false; } ProcedureFunction<?, ?> that = (ProcedureFunction<?, ?>) obj; return this.procedure.equals(that.procedure); } ProcedureFunction(Procedure<? super A> procedure); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static ProcedureFunction<A, T> adapt(Procedure<? super A> procedure); }### Answer:
@Test public void testEquals() throws Exception { Function<Object, Object> f = new ProcedureFunction<Object, Object>(NoOp.INSTANCE); assertEquals(f,f); assertObjectsAreEqual(f,new ProcedureFunction<Object, Object>(NoOp.INSTANCE)); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f, new ProcedureFunction<Object, Object>(new Procedure<Object>() { public void run(Object a) { } })); assertObjectsAreNotEqual(f,Constant.of(null)); assertTrue(!f.equals(null)); }
|
### Question:
ProcedureFunction implements Function<A, T> { public static <A, T> ProcedureFunction<A, T> adapt(Procedure<? super A> procedure) { return null == procedure ? null : new ProcedureFunction<A, T>(procedure); } ProcedureFunction(Procedure<? super A> procedure); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static ProcedureFunction<A, T> adapt(Procedure<? super A> procedure); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(ProcedureFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(ProcedureFunction.adapt(new NoOp())); }
|
### Question:
RightBoundPredicate implements Predicate<A> { public boolean test(A obj) { return predicate.test(obj, param); } @SuppressWarnings("unchecked") <R> RightBoundPredicate(BinaryPredicate<? super A, ? super R> predicate, R arg); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static RightBoundPredicate<L> bind(BinaryPredicate<? super L, ? super R> predicate, R arg); }### Answer:
@Test public void testTest() throws Exception { Predicate<Boolean> f = new RightBoundPredicate<Boolean>( new BinaryFunctionBinaryPredicate<Boolean, Object>(LeftIdentity.<Boolean, Object> function()), "foo"); assertTrue(f.test(Boolean.TRUE)); assertFalse(f.test(Boolean.FALSE)); }
|
### Question:
RightBoundPredicate implements Predicate<A> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof RightBoundPredicate<?>)) { return false; } RightBoundPredicate<?> that = (RightBoundPredicate<?>) obj; return this.predicate.equals(that.predicate) && (null == this.param ? null == that.param : this.param.equals(that.param)); } @SuppressWarnings("unchecked") <R> RightBoundPredicate(BinaryPredicate<? super A, ? super R> predicate, R arg); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static RightBoundPredicate<L> bind(BinaryPredicate<? super L, ? super R> predicate, R arg); }### Answer:
@Test public void testEquals() throws Exception { Predicate<Boolean> f = new RightBoundPredicate<Boolean>(Constant.TRUE, "xyzzy"); assertEquals(f, f); assertObjectsAreEqual(f, new RightBoundPredicate<Boolean>(Constant.TRUE, "xyzzy")); assertObjectsAreNotEqual(f, Constant.TRUE); assertObjectsAreNotEqual(f, new RightBoundPredicate<Boolean>(Constant.FALSE, "xyzzy")); assertObjectsAreNotEqual(f, new RightBoundPredicate<Boolean>(Constant.TRUE, "foo")); assertObjectsAreNotEqual(f, new RightBoundPredicate<Boolean>(Constant.TRUE, null)); assertObjectsAreEqual(new RightBoundPredicate<Boolean>(Constant.TRUE, null), new RightBoundPredicate<Boolean>(Constant.TRUE, null)); assertTrue(!f.equals(null)); }
|
### Question:
RightBoundPredicate implements Predicate<A> { public static <L, R> RightBoundPredicate<L> bind(BinaryPredicate<? super L, ? super R> predicate, R arg) { return null == predicate ? null : new RightBoundPredicate<L>(predicate, arg); } @SuppressWarnings("unchecked") <R> RightBoundPredicate(BinaryPredicate<? super A, ? super R> predicate, R arg); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static RightBoundPredicate<L> bind(BinaryPredicate<? super L, ? super R> predicate, R arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(RightBoundPredicate.bind(null, "xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(RightBoundPredicate.bind(Constant.FALSE, "xyzzy")); assertNotNull(RightBoundPredicate.bind(Constant.FALSE, null)); }
|
### Question:
NullaryProcedureNullaryFunction implements NullaryFunction<T> { public T evaluate() { procedure.run(); return null; } NullaryProcedureNullaryFunction(NullaryProcedure procedure); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryProcedureNullaryFunction<T> adapt(NullaryProcedure procedure); }### Answer:
@Test public void testEvaluate() throws Exception { NullaryFunction<Object> f = new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE); assertNull(f.evaluate()); }
|
### Question:
NullaryProcedureNullaryFunction implements NullaryFunction<T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof NullaryProcedureNullaryFunction<?>)) { return false; } NullaryProcedureNullaryFunction<?> that = (NullaryProcedureNullaryFunction<?>) obj; return this.procedure.equals(that.procedure); } NullaryProcedureNullaryFunction(NullaryProcedure procedure); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryProcedureNullaryFunction<T> adapt(NullaryProcedure procedure); }### Answer:
@Test public void testEquals() throws Exception { NullaryFunction<Object> f = new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE); assertEquals(f,f); assertObjectsAreEqual(f,new NullaryProcedureNullaryFunction<Object>(NoOp.INSTANCE)); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f,new NullaryProcedureNullaryFunction<Object>(new NullaryProcedure() { public void run() { } })); assertObjectsAreNotEqual(f,Constant.of(null)); assertTrue(!f.equals(null)); }
|
### Question:
NullaryProcedureNullaryFunction implements NullaryFunction<T> { public static <T> NullaryProcedureNullaryFunction<T> adapt(NullaryProcedure procedure) { return null == procedure ? null : new NullaryProcedureNullaryFunction<T>(procedure); } NullaryProcedureNullaryFunction(NullaryProcedure procedure); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryProcedureNullaryFunction<T> adapt(NullaryProcedure procedure); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(NullaryProcedureNullaryFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(NullaryProcedureNullaryFunction.adapt(new NoOp())); }
|
### Question:
LeftBoundFunction implements Function<A, T> { public T evaluate(A obj) { return function.evaluate(param, obj); } @SuppressWarnings("unchecked") <L> LeftBoundFunction(BinaryFunction<? super L, ? super A, ? extends T> function, L arg); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static LeftBoundFunction<R, T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L arg); }### Answer:
@Test public void testEvaluate() throws Exception { Function<Object, Object> f = new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"foo"); assertEquals("xyzzy",f.evaluate("xyzzy")); }
|
### Question:
LeftBoundFunction implements Function<A, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof LeftBoundFunction<?, ?>)) { return false; } LeftBoundFunction<?, ?> that = (LeftBoundFunction<?, ?>) obj; return this.function.equals(that.function) && (null == this.param ? null == that.param : this.param.equals(that.param)); } @SuppressWarnings("unchecked") <L> LeftBoundFunction(BinaryFunction<? super L, ? super A, ? extends T> function, L arg); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static LeftBoundFunction<R, T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L arg); }### Answer:
@Test public void testEquals() throws Exception { Function<Object, Object> f = new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"xyzzy"); assertEquals(f,f); assertObjectsAreEqual(f,new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"xyzzy")); assertObjectsAreNotEqual(f,Constant.of("xyzzy")); assertObjectsAreNotEqual(f,new LeftBoundFunction<Object, Object>(LeftIdentity.FUNCTION,"xyzzy")); assertObjectsAreNotEqual(f,new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,"bar")); assertObjectsAreNotEqual(f,new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION,null)); assertObjectsAreEqual(new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION, null),new LeftBoundFunction<Object, Object>(RightIdentity.FUNCTION, null)); assertTrue(!f.equals(null)); }
|
### Question:
LeftBoundFunction implements Function<A, T> { public static <L, R, T> LeftBoundFunction<R, T> bind( BinaryFunction<? super L, ? super R, ? extends T> function, L arg) { return null == function ? null : new LeftBoundFunction<R, T>(function, arg); } @SuppressWarnings("unchecked") <L> LeftBoundFunction(BinaryFunction<? super L, ? super A, ? extends T> function, L arg); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static LeftBoundFunction<R, T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(LeftBoundFunction.bind(null,"xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(LeftBoundFunction.bind(RightIdentity.FUNCTION,"xyzzy")); assertNotNull(LeftBoundFunction.bind(RightIdentity.FUNCTION,null)); }
|
### Question:
NullaryFunctionFunction implements Function<A, T> { public T evaluate(A obj) { return function.evaluate(); } NullaryFunctionFunction(NullaryFunction<? extends T> function); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionFunction<A, T> adapt(NullaryFunction<? extends T> function); }### Answer:
@Test public void testEvaluate() throws Exception { Function<Object, Object> f = new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy")); assertEquals("xyzzy",f.evaluate(null)); assertEquals("xyzzy",f.evaluate("abc")); }
|
### Question:
NullaryFunctionFunction implements Function<A, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof NullaryFunctionFunction<?, ?>)) { return false; } NullaryFunctionFunction<?, ?> that = (NullaryFunctionFunction<?, ?>) obj; return this.function.equals(that.function); } NullaryFunctionFunction(NullaryFunction<? extends T> function); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionFunction<A, T> adapt(NullaryFunction<? extends T> function); }### Answer:
@Test public void testEquals() throws Exception { Function<Object, Object> f = new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy")); assertEquals(f,f); assertObjectsAreEqual(f,new NullaryFunctionFunction<Object, Object>(Constant.of("xyzzy"))); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f,new NullaryFunctionFunction<Object, Object>(Constant.of(null))); assertObjectsAreNotEqual(f,Constant.of(null)); assertTrue(!f.equals(null)); }
|
### Question:
NullaryFunctionFunction implements Function<A, T> { public static <A, T> NullaryFunctionFunction<A, T> adapt(NullaryFunction<? extends T> function) { return null == function ? null : new NullaryFunctionFunction<A, T>(function); } NullaryFunctionFunction(NullaryFunction<? extends T> function); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionFunction<A, T> adapt(NullaryFunction<? extends T> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(NullaryFunctionFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(NullaryFunctionFunction.adapt(Constant.of("xyzzy"))); }
|
### Question:
NullaryFunctionNullaryProcedure implements NullaryProcedure { public void run() { function.evaluate(); } NullaryFunctionNullaryProcedure(NullaryFunction<?> function); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionNullaryProcedure adapt(NullaryFunction<?> function); }### Answer:
@Test public void testRun() throws Exception { class EvaluateCounter implements NullaryFunction<Integer> { int count = 0; public Integer evaluate() { return Integer.valueOf(count++); } } EvaluateCounter counter = new EvaluateCounter(); NullaryProcedure p = new NullaryFunctionNullaryProcedure(counter); assertEquals(0,counter.count); p.run(); assertEquals(1,counter.count); p.run(); assertEquals(2,counter.count); }
|
### Question:
NullaryFunctionNullaryProcedure implements NullaryProcedure { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof NullaryFunctionNullaryProcedure)) { return false; } NullaryFunctionNullaryProcedure that = (NullaryFunctionNullaryProcedure) obj; return this.function.equals(that.function); } NullaryFunctionNullaryProcedure(NullaryFunction<?> function); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionNullaryProcedure adapt(NullaryFunction<?> function); }### Answer:
@Test public void testEquals() throws Exception { NullaryProcedure p = new NullaryFunctionNullaryProcedure(Constant.of("K")); assertEquals(p,p); assertObjectsAreEqual(p,new NullaryFunctionNullaryProcedure(Constant.of("K"))); assertObjectsAreNotEqual(p,NoOp.INSTANCE); assertObjectsAreNotEqual(p,new NullaryFunctionNullaryProcedure(Constant.of("J"))); assertTrue(!p.equals(null)); }
|
### Question:
NullaryFunctionNullaryProcedure implements NullaryProcedure { public static NullaryFunctionNullaryProcedure adapt(NullaryFunction<?> function) { return null == function ? null : new NullaryFunctionNullaryProcedure(function); } NullaryFunctionNullaryProcedure(NullaryFunction<?> function); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryFunctionNullaryProcedure adapt(NullaryFunction<?> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(NullaryFunctionNullaryProcedure.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(NullaryFunctionNullaryProcedure.adapt(Constant.of("K"))); }
|
### Question:
FunctionProcedure implements Procedure<A> { public void run(A obj) { function.evaluate(obj); } FunctionProcedure(Function<? super A, ?> function); void run(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FunctionProcedure<A> adapt(Function<? super A, ?> function); }### Answer:
@Test public void testRun() throws Exception { class EvaluateCounter implements Function<Object, Integer> { int count = 0; public Integer evaluate(Object a) { return Integer.valueOf(count++); } } EvaluateCounter counter = new EvaluateCounter(); Procedure<Object> p = new FunctionProcedure<Object>(counter); assertEquals(0,counter.count); p.run(null); assertEquals(1,counter.count); p.run("x"); assertEquals(2,counter.count); }
|
### Question:
WhileGenerate extends LoopGenerator<E> { public void run(final Procedure<? super E> proc) { getWrappedGenerator().run(new Procedure<E>() { public void run(E obj) { if (!test.test(obj)) { WhileGenerate.this.stop(); } else { proc.run(obj); } } }); } WhileGenerate(Predicate<? super E> test, Generator<? extends E> wrapped); void run(final Procedure<? super E> proc); @Override boolean equals(Object obj); @Override int hashCode(); }### Answer:
@Test public void testGenerate() { final List<Integer> numbersMinorThanFive = new ArrayList<Integer>(); whileGenerate.run(new Procedure<Integer>() { public void run( Integer obj ) { numbersMinorThanFive.add(obj); } }); assertEquals(4, numbersMinorThanFive.size()); List<Integer> expected = Arrays.asList(1, 2, 3, 4); assertEquals(expected, numbersMinorThanFive); }
|
### Question:
FunctionProcedure implements Procedure<A> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof FunctionProcedure<?>)) { return false; } FunctionProcedure<?> that = (FunctionProcedure<?>) obj; return this.function.equals(that.function); } FunctionProcedure(Function<? super A, ?> function); void run(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FunctionProcedure<A> adapt(Function<? super A, ?> function); }### Answer:
@Test public void testEquals() throws Exception { Procedure<Object> p = new FunctionProcedure<Object>(Constant.of("K")); assertEquals(p,p); assertObjectsAreEqual(p,new FunctionProcedure<Object>(Constant.of("K"))); assertObjectsAreNotEqual(p,NoOp.INSTANCE); assertObjectsAreNotEqual(p,new FunctionProcedure<Object>(Constant.of("J"))); assertTrue(!p.equals(null)); }
|
### Question:
FunctionProcedure implements Procedure<A> { public static <A> FunctionProcedure<A> adapt(Function<? super A, ?> function) { return null == function ? null : new FunctionProcedure<A>(function); } FunctionProcedure(Function<? super A, ?> function); void run(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FunctionProcedure<A> adapt(Function<? super A, ?> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(FunctionProcedure.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(FunctionProcedure.adapt(Constant.of("K"))); }
|
### Question:
LeftBoundProcedure implements Procedure<A> { public void run(A obj) { procedure.run(param, obj); } @SuppressWarnings("unchecked") <L> LeftBoundProcedure(BinaryProcedure<? super L, ? super A> procedure, L arg); void run(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static LeftBoundProcedure<R> bind(BinaryProcedure<? super L, ? super R> procedure, L arg); }### Answer:
@Test public void testRun() throws Exception { Procedure<Object> p = new LeftBoundProcedure<Object>( new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "foo"); p.run(Boolean.TRUE); p.run(Boolean.FALSE); }
|
### Question:
LeftBoundProcedure implements Procedure<A> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof LeftBoundProcedure<?>)) { return false; } LeftBoundProcedure<?> that = (LeftBoundProcedure<?>) obj; return procedure.equals(that.procedure) && (null == param ? null == that.param : param.equals(that.param)); } @SuppressWarnings("unchecked") <L> LeftBoundProcedure(BinaryProcedure<? super L, ? super A> procedure, L arg); void run(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static LeftBoundProcedure<R> bind(BinaryProcedure<? super L, ? super R> procedure, L arg); }### Answer:
@Test public void testEquals() throws Exception { Procedure<Object> f = new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy"); assertEquals(f, f); assertObjectsAreEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy")); assertObjectsAreNotEqual(f, new NoOp()); assertObjectsAreNotEqual(f, new LeftBoundProcedure<Object>( new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "xyzzy")); assertObjectsAreNotEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, "foo")); assertObjectsAreNotEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, null)); assertObjectsAreEqual(new LeftBoundProcedure<Object>(NoOp.INSTANCE, null), new LeftBoundProcedure<Object>(NoOp.INSTANCE, null)); assertTrue(!f.equals(null)); }
|
### Question:
LeftBoundProcedure implements Procedure<A> { public static <L, R> LeftBoundProcedure<R> bind(BinaryProcedure<? super L, ? super R> procedure, L arg) { return null == procedure ? null : new LeftBoundProcedure<R>(procedure, arg); } @SuppressWarnings("unchecked") <L> LeftBoundProcedure(BinaryProcedure<? super L, ? super A> procedure, L arg); void run(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static LeftBoundProcedure<R> bind(BinaryProcedure<? super L, ? super R> procedure, L arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(LeftBoundProcedure.bind(null,"xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(LeftBoundProcedure.bind(new NoOp(),"xyzzy")); assertNotNull(LeftBoundProcedure.bind(new NoOp(),null)); }
|
### Question:
NullaryPredicateNullaryFunction implements NullaryFunction<Boolean> { public Boolean evaluate() { return Boolean.valueOf(predicate.test()); } NullaryPredicateNullaryFunction(NullaryPredicate predicate); Boolean evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryPredicateNullaryFunction adapt(NullaryPredicate predicate); }### Answer:
@Test public void testTestWhenTrue() throws Exception { NullaryFunction<Boolean> f = new NullaryPredicateNullaryFunction(Constant.TRUE); assertEquals(Boolean.TRUE,f.evaluate()); }
@Test public void testTestWhenFalse() throws Exception { NullaryFunction<Boolean> f = new NullaryPredicateNullaryFunction(Constant.FALSE); assertEquals(Boolean.FALSE,f.evaluate()); }
|
### Question:
NullaryPredicateNullaryFunction implements NullaryFunction<Boolean> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof NullaryPredicateNullaryFunction)) { return false; } NullaryPredicateNullaryFunction that = (NullaryPredicateNullaryFunction) obj; return this.predicate.equals(that.predicate); } NullaryPredicateNullaryFunction(NullaryPredicate predicate); Boolean evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryPredicateNullaryFunction adapt(NullaryPredicate predicate); }### Answer:
@Test public void testEquals() throws Exception { NullaryFunction<Boolean> f = new NullaryPredicateNullaryFunction(Constant.TRUE); assertEquals(f,f); assertObjectsAreEqual(f,new NullaryPredicateNullaryFunction(Constant.TRUE)); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f,new NullaryPredicateNullaryFunction(Constant.FALSE)); assertTrue(!f.equals(null)); }
|
### Question:
NullaryPredicateNullaryFunction implements NullaryFunction<Boolean> { public static NullaryPredicateNullaryFunction adapt(NullaryPredicate predicate) { return null == predicate ? null : new NullaryPredicateNullaryFunction(predicate); } NullaryPredicateNullaryFunction(NullaryPredicate predicate); Boolean evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static NullaryPredicateNullaryFunction adapt(NullaryPredicate predicate); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(NullaryPredicateNullaryFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(NullaryPredicateNullaryFunction.adapt(Constant.TRUE)); }
|
### Question:
IgnoreLeftPredicate implements BinaryPredicate<L, R> { public boolean test(L left, R right) { return predicate.test(right); } IgnoreLeftPredicate(Predicate<? super R> predicate); boolean test(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreLeftPredicate<L, R> adapt(Predicate<? super R> predicate); }### Answer:
@Test public void testEvaluate() throws Exception { BinaryPredicate<Object, Boolean> p = new IgnoreLeftPredicate<Object, Boolean>( new FunctionPredicate<Boolean>(Identity.<Boolean> instance())); assertTrue(p.test(null,Boolean.TRUE)); assertTrue(!p.test(null,Boolean.FALSE)); }
|
### Question:
IgnoreLeftPredicate implements BinaryPredicate<L, R> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IgnoreLeftPredicate<?, ?>)) { return false; } IgnoreLeftPredicate<?, ?> that = (IgnoreLeftPredicate<?, ?>) obj; return this.predicate.equals(that.predicate); } IgnoreLeftPredicate(Predicate<? super R> predicate); boolean test(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreLeftPredicate<L, R> adapt(Predicate<? super R> predicate); }### Answer:
@Test public void testEquals() throws Exception { BinaryPredicate<Object, Boolean> p = new IgnoreLeftPredicate<Object, Boolean>( new FunctionPredicate<Boolean>(Identity.<Boolean> instance())); assertEquals(p,p); assertObjectsAreEqual(p,new IgnoreLeftPredicate<Object, Boolean>( new FunctionPredicate<Boolean>(Identity.<Boolean> instance()))); assertObjectsAreNotEqual(p,Constant.TRUE); assertObjectsAreNotEqual(p,new IgnoreLeftPredicate<Object, Object>(Constant.FALSE)); assertObjectsAreNotEqual(p,Constant.FALSE); assertObjectsAreNotEqual(p,new IgnoreLeftPredicate<Object, Object>(Constant.of(null))); assertObjectsAreEqual(new IgnoreLeftPredicate<Object, Object>(Constant.of(null)),new IgnoreLeftPredicate<Object, Object>(Constant.of(null))); assertTrue(!p.equals(null)); }
|
### Question:
IgnoreLeftPredicate implements BinaryPredicate<L, R> { public static <L, R> IgnoreLeftPredicate<L, R> adapt(Predicate<? super R> predicate) { return null == predicate ? null : new IgnoreLeftPredicate<L, R>(predicate); } IgnoreLeftPredicate(Predicate<? super R> predicate); boolean test(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreLeftPredicate<L, R> adapt(Predicate<? super R> predicate); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(IgnoreLeftPredicate.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(IgnoreLeftPredicate.adapt(Constant.TRUE)); }
|
### Question:
IgnoreRightPredicate implements BinaryPredicate<L, R> { public boolean test(L left, R right) { return predicate.test(left); } IgnoreRightPredicate(Predicate<? super L> predicate); boolean test(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightPredicate<L, R> adapt(Predicate<? super L> predicate); }### Answer:
@Test public void testEvaluate() throws Exception { BinaryPredicate<Boolean, Object> p = new IgnoreRightPredicate<Boolean, Object>( new FunctionPredicate<Boolean>(Identity.<Boolean> instance())); assertTrue(p.test(Boolean.TRUE,null)); assertTrue(!p.test(Boolean.FALSE,null)); }
|
### Question:
IgnoreRightPredicate implements BinaryPredicate<L, R> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IgnoreRightPredicate<?, ?>)) { return false; } IgnoreRightPredicate<?, ?> that = (IgnoreRightPredicate<?, ?>) obj; return this.predicate.equals(that.predicate); } IgnoreRightPredicate(Predicate<? super L> predicate); boolean test(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightPredicate<L, R> adapt(Predicate<? super L> predicate); }### Answer:
@Test public void testEquals() throws Exception { BinaryPredicate<Boolean, Object> p = new IgnoreRightPredicate<Boolean, Object>( new FunctionPredicate<Boolean>(Identity.<Boolean> instance())); assertEquals(p,p); assertObjectsAreEqual(p,new IgnoreRightPredicate<Boolean, Object>( new FunctionPredicate<Boolean>(Identity.<Boolean> instance()))); assertObjectsAreNotEqual(p,Constant.TRUE); assertObjectsAreNotEqual(p,new IgnoreRightPredicate<Boolean, Object>(Constant.FALSE)); assertObjectsAreNotEqual(p,Constant.FALSE); assertTrue(!p.equals(null)); }
|
### Question:
IgnoreRightPredicate implements BinaryPredicate<L, R> { public static <L, R> IgnoreRightPredicate<L, R> adapt(Predicate<? super L> predicate) { return null == predicate ? null : new IgnoreRightPredicate<L, R>(predicate); } IgnoreRightPredicate(Predicate<? super L> predicate); boolean test(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightPredicate<L, R> adapt(Predicate<? super L> predicate); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(IgnoreRightPredicate.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(IgnoreRightPredicate.adapt(Constant.TRUE)); }
|
### Question:
BoundNullaryFunction implements NullaryFunction<T> { public T evaluate() { return function.evaluate(arg); } @SuppressWarnings("unchecked") <A> BoundNullaryFunction(Function<? super A, ? extends T> function, A arg); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryFunction<T> bind(Function<? super A, ? extends T> function, A arg); }### Answer:
@Test public void testEvaluate() throws Exception { NullaryFunction<Object> f = new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy"); assertEquals("xyzzy",f.evaluate()); }
|
### Question:
BoundNullaryFunction implements NullaryFunction<T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BoundNullaryFunction<?>)) { return false; } BoundNullaryFunction<?> that = (BoundNullaryFunction<?>) obj; if (!(that.function.equals(this.function))) { return false; } return that.arg == this.arg || that.arg != null && that.arg.equals(this.arg); } @SuppressWarnings("unchecked") <A> BoundNullaryFunction(Function<? super A, ? extends T> function, A arg); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryFunction<T> bind(Function<? super A, ? extends T> function, A arg); }### Answer:
@Test public void testEquals() throws Exception { NullaryFunction<Object> f = new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy"); assertEquals(f,f); assertObjectsAreEqual(f,new BoundNullaryFunction<Object>(Identity.INSTANCE,"xyzzy")); assertObjectsAreNotEqual(f,Constant.of("xyzzy")); assertObjectsAreNotEqual(f,new BoundNullaryFunction<Object>(Identity.INSTANCE,"foo")); assertObjectsAreNotEqual(f,new BoundNullaryFunction<Object>(Constant.of("xyzzy"),"foo")); assertObjectsAreNotEqual(f,new BoundNullaryFunction<Object>(Identity.INSTANCE,null)); assertTrue(!f.equals(null)); }
|
### Question:
BoundNullaryFunction implements NullaryFunction<T> { public static <A, T> BoundNullaryFunction<T> bind(Function<? super A, ? extends T> function, A arg) { return null == function ? null : new BoundNullaryFunction<T>(function, arg); } @SuppressWarnings("unchecked") <A> BoundNullaryFunction(Function<? super A, ? extends T> function, A arg); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BoundNullaryFunction<T> bind(Function<? super A, ? extends T> function, A arg); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BoundNullaryFunction.bind(null,"xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(BoundNullaryFunction.bind(Identity.INSTANCE,"xyzzy")); assertNotNull(BoundNullaryFunction.bind(Identity.INSTANCE,null)); }
|
### Question:
FunctionPredicate implements Predicate<A> { public boolean test(A obj) { return function.evaluate(obj).booleanValue(); } FunctionPredicate(Function<? super A, Boolean> function); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FunctionPredicate<A> adapt(Function<? super A, Boolean> function); }### Answer:
@Test public void testTestWhenTrue() throws Exception { Predicate<Object> p = new FunctionPredicate<Object>(Constant.TRUE); assertTrue(p.test(null)); }
@Test public void testTestWhenFalse() throws Exception { Predicate<Object> p = new FunctionPredicate<Object>(Constant.FALSE); assertTrue(!p.test(null)); }
|
### Question:
FunctionPredicate implements Predicate<A> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof FunctionPredicate<?>)) { return false; } FunctionPredicate<?> that = (FunctionPredicate<?>) obj; return this.function.equals(that.function); } FunctionPredicate(Function<? super A, Boolean> function); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FunctionPredicate<A> adapt(Function<? super A, Boolean> function); }### Answer:
@Test public void testEquals() throws Exception { Predicate<Object> p = new FunctionPredicate<Object>(Constant.TRUE); assertEquals(p,p); assertObjectsAreEqual(p,new FunctionPredicate<Object>(Constant.TRUE)); assertObjectsAreNotEqual(p,Constant.TRUE); assertObjectsAreNotEqual(p,new FunctionPredicate<Object>(Constant.FALSE)); assertTrue(!p.equals(null)); }
|
### Question:
FunctionPredicate implements Predicate<A> { public static <A> FunctionPredicate<A> adapt(Function<? super A, Boolean> function) { return null == function ? null : new FunctionPredicate<A>(function); } FunctionPredicate(Function<? super A, Boolean> function); boolean test(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FunctionPredicate<A> adapt(Function<? super A, Boolean> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(FunctionPredicate.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(FunctionPredicate.adapt(Constant.TRUE)); }
|
### Question:
BinaryPredicateBinaryFunction implements BinaryFunction<L, R, Boolean> { public Boolean evaluate(L left, R right) { return predicate.test(left, right) ? Boolean.TRUE : Boolean.FALSE; } BinaryPredicateBinaryFunction(BinaryPredicate<? super L, ? super R> predicate); Boolean evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryPredicateBinaryFunction<L, R> adapt(BinaryPredicate<? super L, ? super R> predicate); }### Answer:
@Test public void testTestWhenTrue() throws Exception { BinaryFunction<Object, Object, Boolean> f = new BinaryPredicateBinaryFunction<Object, Object>(Constant.TRUE); assertEquals(Boolean.TRUE, f.evaluate(null,null)); }
@Test public void testTestWhenFalse() throws Exception { BinaryFunction<Object, Object, Boolean> f = new BinaryPredicateBinaryFunction<Object, Object>(Constant.FALSE); assertEquals(Boolean.FALSE, f.evaluate(null,null)); }
|
### Question:
BinaryPredicateBinaryFunction implements BinaryFunction<L, R, Boolean> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BinaryPredicateBinaryFunction<?, ?>)) { return false; } BinaryPredicateBinaryFunction<?, ?> that = (BinaryPredicateBinaryFunction<?, ?>) obj; return this.predicate.equals(that.predicate); } BinaryPredicateBinaryFunction(BinaryPredicate<? super L, ? super R> predicate); Boolean evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryPredicateBinaryFunction<L, R> adapt(BinaryPredicate<? super L, ? super R> predicate); }### Answer:
@Test public void testEquals() throws Exception { BinaryFunction<Object, Object, Boolean> f = new BinaryPredicateBinaryFunction<Object, Object>(Constant.TRUE); assertEquals(f,f); assertObjectsAreEqual(f,new BinaryPredicateBinaryFunction<Object, Object>(Constant.TRUE)); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f,new BinaryPredicateBinaryFunction<Object, Object>(Constant.FALSE)); assertTrue(!f.equals(null)); }
|
### Question:
BinaryPredicateBinaryFunction implements BinaryFunction<L, R, Boolean> { public static <L, R> BinaryPredicateBinaryFunction<L, R> adapt(BinaryPredicate<? super L, ? super R> predicate) { return null == predicate ? null : new BinaryPredicateBinaryFunction<L, R>(predicate); } BinaryPredicateBinaryFunction(BinaryPredicate<? super L, ? super R> predicate); Boolean evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static BinaryPredicateBinaryFunction<L, R> adapt(BinaryPredicate<? super L, ? super R> predicate); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BinaryPredicateBinaryFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(BinaryPredicateBinaryFunction.adapt(Constant.TRUE)); }
|
### Question:
FullyBoundNullaryProcedure implements NullaryProcedure { public void run() { procedure.run(left, right); } @SuppressWarnings("unchecked") <L, R> FullyBoundNullaryProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FullyBoundNullaryProcedure bind(
BinaryProcedure<? super L, ? super R> procedure, L left, R right); }### Answer:
@Test public void testRun() throws Exception { NullaryProcedure p = new FullyBoundNullaryProcedure(new BinaryFunctionBinaryProcedure<Object, Object>( RightIdentity.FUNCTION), "foo", null); p.run(); }
|
### Question:
FullyBoundNullaryProcedure implements NullaryProcedure { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof FullyBoundNullaryProcedure)) { return false; } FullyBoundNullaryProcedure that = (FullyBoundNullaryProcedure) obj; return procedure.equals(that.procedure) && (null == left ? null == that.left : left.equals(that.left)) && (null == right ? null == that.right : right.equals(that.right)); } @SuppressWarnings("unchecked") <L, R> FullyBoundNullaryProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FullyBoundNullaryProcedure bind(
BinaryProcedure<? super L, ? super R> procedure, L left, R right); }### Answer:
@Test public void testEquals() throws Exception { NullaryProcedure f = new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null); assertEquals(f, f); assertObjectsAreEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null)); assertObjectsAreNotEqual(f, new NoOp()); assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure( new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "xyzzy", null)); assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", null)); assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", "yzzyx")); assertObjectsAreNotEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", "yzzyx"), new FullyBoundNullaryProcedure(NoOp.INSTANCE, "xyzzy", null)); assertObjectsAreNotEqual(f, new FullyBoundNullaryProcedure(NoOp.INSTANCE, null, null)); assertObjectsAreEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, null, null), new FullyBoundNullaryProcedure(NoOp.INSTANCE, null, null)); assertObjectsAreEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", null), new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", null)); assertObjectsAreEqual(new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", "xyzzy"), new FullyBoundNullaryProcedure(NoOp.INSTANCE, "foo", "xyzzy")); assertTrue(!f.equals(null)); }
|
### Question:
FullyBoundNullaryProcedure implements NullaryProcedure { public static <L, R> FullyBoundNullaryProcedure bind( BinaryProcedure<? super L, ? super R> procedure, L left, R right) { return null == procedure ? null : new FullyBoundNullaryProcedure(procedure, left, right); } @SuppressWarnings("unchecked") <L, R> FullyBoundNullaryProcedure(BinaryProcedure<? super L, ? super R> procedure, L left, R right); void run(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FullyBoundNullaryProcedure bind(
BinaryProcedure<? super L, ? super R> procedure, L left, R right); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(FullyBoundNullaryProcedure.bind(null, "xyzzy", null)); }
@Test public void testAdapt() throws Exception { assertNotNull(FullyBoundNullaryProcedure.bind(new NoOp(), "xyzzy", "foobar")); assertNotNull(FullyBoundNullaryProcedure.bind(new NoOp(), null, null)); }
|
### Question:
IgnoreRightFunction implements BinaryFunction<L, R, T> { public T evaluate(L left, R right) { return function.evaluate(left); } IgnoreRightFunction(Function<? super L, ? extends T> function); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightFunction<L, R, T> adapt(Function<? super L, ? extends T> function); }### Answer:
@Test public void testEvaluate() throws Exception { BinaryFunction<String, String, String> f = new IgnoreRightFunction<String, String, String>(new Identity<String>()); assertNull(f.evaluate(null,null)); assertNull(f.evaluate(null,"xyzzy")); assertEquals("xyzzy",f.evaluate("xyzzy",null)); assertEquals("xyzzy",f.evaluate("xyzzy","abc")); }
|
### Question:
IgnoreRightFunction implements BinaryFunction<L, R, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IgnoreRightFunction<?, ?, ?>)) { return false; } IgnoreRightFunction<?, ?, ?> that = (IgnoreRightFunction<?, ?, ?>) obj; return this.function.equals(that.function); } IgnoreRightFunction(Function<? super L, ? extends T> function); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightFunction<L, R, T> adapt(Function<? super L, ? extends T> function); }### Answer:
@Test public void testEquals() throws Exception { BinaryFunction<String, String, String> f = new IgnoreRightFunction<String, String, String>(Constant.of("xyzzy")); assertEquals(f,f); assertObjectsAreEqual(f,new IgnoreRightFunction<String, String, String>(Constant.of("xyzzy"))); assertObjectsAreNotEqual(f,Constant.of("x")); assertObjectsAreNotEqual(f,new IgnoreRightFunction<String, String, String>(Constant.<String>of(null))); assertObjectsAreNotEqual(f,Constant.of(null)); assertObjectsAreEqual(new IgnoreRightFunction<String, String, String>(Constant.<String>of(null)),new IgnoreRightFunction<String, String, String>(Constant.<String>of(null))); assertTrue(!f.equals(null)); }
|
### Question:
IgnoreRightFunction implements BinaryFunction<L, R, T> { public static <L, R, T> IgnoreRightFunction<L, R, T> adapt(Function<? super L, ? extends T> function) { return null == function ? null : new IgnoreRightFunction<L, R, T>(function); } IgnoreRightFunction(Function<? super L, ? extends T> function); T evaluate(L left, R right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IgnoreRightFunction<L, R, T> adapt(Function<? super L, ? extends T> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(IgnoreRightFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(IgnoreRightFunction.adapt(Constant.of("xyzzy"))); }
|
### Question:
FullyBoundNullaryFunction implements NullaryFunction<T> { public T evaluate() { return function.evaluate(left, right); } @SuppressWarnings("unchecked") <L, R> FullyBoundNullaryFunction(
BinaryFunction<? super L, ? super R, ? extends T> function,
L left, R right); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FullyBoundNullaryFunction<T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right); }### Answer:
@Test public void testEvaluate() throws Exception { NullaryFunction<Object> f = new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "foo"); assertEquals("foo", f.evaluate()); }
|
### Question:
FullyBoundNullaryFunction implements NullaryFunction<T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof FullyBoundNullaryFunction<?>)) { return false; } FullyBoundNullaryFunction<?> that = (FullyBoundNullaryFunction<?>) obj; return function.equals(that.function) && (null == left ? null == that.left : left.equals(that.left)) && (null == right ? null == that.right : right.equals(that.right)); } @SuppressWarnings("unchecked") <L, R> FullyBoundNullaryFunction(
BinaryFunction<? super L, ? super R, ? extends T> function,
L left, R right); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FullyBoundNullaryFunction<T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right); }### Answer:
@Test public void testEquals() throws Exception { NullaryFunction<Object> f = new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy"); assertEquals(f, f); assertObjectsAreEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "xyzzy")); assertObjectsAreEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy"), new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy")); assertObjectsAreEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", null), new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", null)); assertObjectsAreNotEqual(f, Constant.of("xyzzy")); assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(LeftIdentity.FUNCTION, null, "xyzzy")); assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "xyzzy")); assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "bar")); assertObjectsAreNotEqual(f, new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, null)); assertObjectsAreNotEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "xyzzy", "bar"), new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, null, "bar")); assertObjectsAreNotEqual(new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "xyzzy", "bar"), new FullyBoundNullaryFunction<Object>(RightIdentity.FUNCTION, "bar", "bar")); assertTrue(!f.equals(null)); }
|
### Question:
FullyBoundNullaryFunction implements NullaryFunction<T> { public static <L, R, T> FullyBoundNullaryFunction<T> bind( BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right) { return null == function ? null : new FullyBoundNullaryFunction<T>(function, left, right); } @SuppressWarnings("unchecked") <L, R> FullyBoundNullaryFunction(
BinaryFunction<? super L, ? super R, ? extends T> function,
L left, R right); T evaluate(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FullyBoundNullaryFunction<T> bind(
BinaryFunction<? super L, ? super R, ? extends T> function, L left, R right); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(FullyBoundNullaryFunction.bind(null, null, "xyzzy")); }
@Test public void testAdapt() throws Exception { assertNotNull(FullyBoundNullaryFunction.bind(RightIdentity.FUNCTION, "xyzzy", "foobar")); assertNotNull(FullyBoundNullaryFunction.bind(RightIdentity.FUNCTION, null, null)); }
|
### Question:
BinaryFunctionFunction implements Function<A, T> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BinaryFunctionFunction<?, ?>)) { return false; } BinaryFunctionFunction<?, ?> that = (BinaryFunctionFunction<?, ?>) obj; return this.function.equals(that.function); } BinaryFunctionFunction(BinaryFunction<? super A, ? super A, ? extends T> function); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Function<A, T> adapt(BinaryFunction<? super A, ? super A, ? extends T> function); }### Answer:
@Test public void testEquals() throws Exception { Function<Object, Boolean> f = new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE)); assertEquals(f, f); assertObjectsAreEqual(f, new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsSame.INSTANCE))); assertObjectsAreNotEqual(f, Constant.truePredicate()); assertObjectsAreNotEqual(f, new BinaryFunctionFunction<Object, Boolean>(BinaryPredicateBinaryFunction.adapt(IsNotSame.INSTANCE))); }
|
### Question:
BinaryFunctionFunction implements Function<A, T> { public static <A, T> Function<A, T> adapt(BinaryFunction<? super A, ? super A, ? extends T> function) { return null == function ? null : new BinaryFunctionFunction<A, T>(function); } BinaryFunctionFunction(BinaryFunction<? super A, ? super A, ? extends T> function); T evaluate(A obj); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static Function<A, T> adapt(BinaryFunction<? super A, ? super A, ? extends T> function); }### Answer:
@Test public void testAdaptNull() throws Exception { assertNull(BinaryFunctionFunction.adapt(null)); }
@Test public void testAdapt() throws Exception { assertNotNull(BinaryFunctionFunction.adapt(Constant.TRUE)); }
|
### Question:
ArrayListBackedAggregator extends AbstractListBackedAggregator<T> { @Override protected List<T> createList() { return new ArrayList<T>(); } ArrayListBackedAggregator(Function<List<T>, T> aggregationFunction); ArrayListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval); ArrayListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval,
boolean useSharedTimer); @Override String toString(); }### Answer:
@Test public void testCreateList() throws Exception { @SuppressWarnings("unchecked") ArrayListBackedAggregator<Object> fct = (ArrayListBackedAggregator<Object>) makeFunctor(); assertNotNull(fct.getSeries()); assertTrue(fct.getSeries() instanceof ArrayList); assertEquals(fct.getSeries().size(), 0); int initialSize = 31; fct = new ArrayListBackedAggregator<Object>(new SelectFirstFunction<Object>(), initialSize); assertNotNull(fct.getSeries()); assertTrue(fct.getSeries() instanceof ArrayList); assertEquals(fct.getSeries().size(), 0); }
|
### Question:
AbstractListBackedAggregator extends AbstractTimedAggregator<T> { protected final List<T> getSeries() { return series; } AbstractListBackedAggregator(Function<List<T>, T> aggregationFunction); AbstractListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval); AbstractListBackedAggregator(Function<List<T>, T> aggregationFunction, long interval,
boolean useSharedTimer); @Override final void doAdd(T data); @Override String toString(); }### Answer:
@Test public void testListCreated() throws Exception { @SuppressWarnings("unchecked") TestListBackedAggregator<Object> fct = (TestListBackedAggregator<Object>) makeFunctor(); assertNotNull(fct.getSeries()); assertEquals(fct.getSeries().size(), 0); }
@Test public void testAdd() throws Exception { @SuppressWarnings("unchecked") TestListBackedAggregator<Object> fct = (TestListBackedAggregator<Object>) makeFunctor(); int calls = 31; for (int i = 1; i <= calls; i++) { fct.add(new Object()); assertEquals(fct.getSeries().size(), i); assertEquals(fct.callsCreateList, 0); } }
@Test public void testReset() throws Exception { @SuppressWarnings("unchecked") TestListBackedAggregator<Object> fct = (TestListBackedAggregator<Object>) makeFunctor(); int calls = 31; for (int i = 1; i <= calls; i++) { fct.reset(); assertEquals(fct.getSeries().size(), 0); assertEquals(fct.callsCreateList, 0); } }
|
### Question:
AbstractNoStoreAggregator extends AbstractTimedAggregator<T> { final T getResult() { return result; } AbstractNoStoreAggregator(BinaryFunction<T, T, T> aggregationFunction); AbstractNoStoreAggregator(BinaryFunction<T, T, T> aggregationFunction, long interval); AbstractNoStoreAggregator(BinaryFunction<T, T, T> aggregationFunction, long interval,
boolean useSharedTimer); @Override String toString(); }### Answer:
@Test public void testReset() throws Exception { @SuppressWarnings("unchecked") TestNoStoreAggregator<Object> fct = (TestNoStoreAggregator<Object>) makeFunctor(); int calls = 31; for (int i = 1; i <= calls; i++) { fct.reset(); assertEquals(INITIAL, fct.getResult()); assertEquals(fct.callsInitialValue, i + 1); } }
|
### Question:
AbstractNoStoreAggregator extends AbstractTimedAggregator<T> { @Override protected int retrieveDataSize() { return 0; } AbstractNoStoreAggregator(BinaryFunction<T, T, T> aggregationFunction); AbstractNoStoreAggregator(BinaryFunction<T, T, T> aggregationFunction, long interval); AbstractNoStoreAggregator(BinaryFunction<T, T, T> aggregationFunction, long interval,
boolean useSharedTimer); @Override String toString(); }### Answer:
@Test public void testDataSize() { assertEquals(0, new TestNoStoreAggregator<Object>(new Object()).retrieveDataSize()); }
|
### Question:
DoubleMaxAggregatorFunction implements Function<List<Double>, Double> { public Double evaluate(List<Double> data) { if (data == null || data.size() == 0) { return null; } Double max = null; for (Double d : data) { if (max == null) { max = d; } else { if (max.doubleValue() < d.doubleValue()) { max = d; } } } return max; } Double evaluate(List<Double> data); @Override String toString(); }### Answer:
@Test public void testEmptyList() throws Exception { DoubleMaxAggregatorFunction fct = (DoubleMaxAggregatorFunction) makeFunctor(); List<Double> lst = null; Double res = fct.evaluate(lst); assertNull(res); lst = new ArrayList<Double>(); res = fct.evaluate(lst); assertNull(res); }
@Test public void testSum() throws Exception { DoubleMaxAggregatorFunction fct = (DoubleMaxAggregatorFunction) makeFunctor(); List<Double> lst = new ArrayList<Double>(); lst.add(0.0); double res = fct.evaluate(lst); assertEquals(res, 0.0, 0.01); lst.add(1.0); res = fct.evaluate(lst); assertEquals(res, 1.0, 0.01); lst.add(2.0); res = fct.evaluate(lst); assertEquals(res, 2.0, 0.01); lst.clear(); int calls = 31; double max = 0.0; Random rnd = new Random(); for (int i = 0; i < calls; i++) { double random = rnd.nextDouble(); lst.add(random); if (random > max) { max = random; } res = fct.evaluate(lst); assertEquals(res, max, 0.01); } }
|
### Question:
DoublePercentileAggregatorFunction implements Function<List<Double>, Double> { final int computeRank(List<Double> data) { int maxRank = data.size() - 1; int rank = (int) Math.floor((percentile * maxRank) / MAX_PERCENTAGE); return rank; } DoublePercentileAggregatorFunction(double percentile); DoublePercentileAggregatorFunction(double percentile, boolean useCopy); Double evaluate(List<Double> data); double getPercentile(); boolean isUseCopy(); @Override String toString(); }### Answer:
@Test public void testComputeRank() throws Exception { List<Double> data = new ArrayList<Double>(); data.add(0.0); data.add(1.0); data.add(2.0); data.add(3.0); data.add(4.0); DoublePercentileAggregatorFunction fct = new DoublePercentileAggregatorFunction(0.0); int rank = fct.computeRank(data); assertEquals(rank, 0); assertEquals(data.get(rank).doubleValue(), 0.0, DELTA); fct = new DoublePercentileAggregatorFunction(100.0); rank = fct.computeRank(data); assertEquals(rank, data.size() - 1); assertEquals(data.get(rank).doubleValue(), 4.0, DELTA); fct = new DoublePercentileAggregatorFunction(50.0); rank = fct.computeRank(data); assertEquals(rank, 2); assertEquals(data.get(rank).doubleValue(), 2.0, DELTA); fct = new DoublePercentileAggregatorFunction(40.0); rank = fct.computeRank(data); assertEquals(rank, 1); assertEquals(data.get(rank).doubleValue(), 1.0, DELTA); fct = new DoublePercentileAggregatorFunction(80.0); rank = fct.computeRank(data); assertEquals(rank, 3); assertEquals(data.get(rank).doubleValue(), 3.0, DELTA); fct = new DoublePercentileAggregatorFunction(70.0); rank = fct.computeRank(data); assertEquals(rank, 2); assertEquals(data.get(rank).doubleValue(), 2.0, DELTA); fct = new DoublePercentileAggregatorFunction(75.0); rank = fct.computeRank(data); assertEquals(rank, 3); assertEquals(data.get(rank).doubleValue(), 3.0, DELTA); }
|
### Question:
DoublePercentileAggregatorFunction implements Function<List<Double>, Double> { public Double evaluate(List<Double> data) { if (data == null || data.size() == 0) { return null; } List<Double> copy = data; if (useCopy) { copy = new ArrayList<Double>(data); } Collections.sort(copy); int rank = computeRank(data); return copy.get(rank); } DoublePercentileAggregatorFunction(double percentile); DoublePercentileAggregatorFunction(double percentile, boolean useCopy); Double evaluate(List<Double> data); double getPercentile(); boolean isUseCopy(); @Override String toString(); }### Answer:
@Test public void testEvaluateNullEmpty() throws Exception { DoublePercentileAggregatorFunction fct = (DoublePercentileAggregatorFunction) makeFunctor(); List<Double> data = null; Double d = fct.evaluate(data); assertNull(d); data = new ArrayList<Double>(); d = fct.evaluate(data); assertNull(d); }
@Test public void testEvaluateNoCopy() throws Exception { DoublePercentileAggregatorFunction fct = (DoublePercentileAggregatorFunction) makeFunctor(); List<Double> data = new ArrayList<Double>(); data.add(4.0); data.add(3.0); data.add(2.0); data.add(1.0); data.add(0.0); Double d = fct.evaluate(data); assertEquals(d, 3.0, DELTA); assertEquals(data.get(0), 4.0, DELTA); assertEquals(data.get(1), 3.0, DELTA); assertEquals(data.get(2), 2.0, DELTA); assertEquals(data.get(3), 1.0, DELTA); assertEquals(data.get(4), 0.0, DELTA); fct = new DoublePercentileAggregatorFunction(DEF_PERC, true); d = fct.evaluate(data); assertEquals(d, 3.0, DELTA); assertEquals(data.get(0), 4.0, DELTA); assertEquals(data.get(1), 3.0, DELTA); assertEquals(data.get(2), 2.0, DELTA); assertEquals(data.get(3), 1.0, DELTA); assertEquals(data.get(4), 0.0, DELTA); fct = new DoublePercentileAggregatorFunction(DEF_PERC, false); d = fct.evaluate(data); assertEquals(d, 3.0, DELTA); assertEquals(data.get(4), 4.0, DELTA); assertEquals(data.get(3), 3.0, DELTA); assertEquals(data.get(2), 2.0, DELTA); assertEquals(data.get(1), 1.0, DELTA); assertEquals(data.get(0), 0.0, DELTA); }
|
### Question:
DoubleSumAggregatorBinaryFunction implements BinaryFunction<Double, Double, Double> { public Double evaluate(Double left, Double right) { if (left == null) { return right; } if (right == null) { return left; } return left + right; } Double evaluate(Double left, Double right); @Override String toString(); }### Answer:
@Test public void testNulls() throws Exception { DoubleSumAggregatorBinaryFunction fct = (DoubleSumAggregatorBinaryFunction)makeFunctor(); Double d = fct.evaluate(null, null); assertNull( d ); d = fct.evaluate( null, 1.0 ); assertEquals( 1.0, d.doubleValue(), DELTA ); d = fct.evaluate( 2.0, null ); assertEquals( 2.0, d.doubleValue(), DELTA ); }
@Test public void testSum() throws Exception { DoubleSumAggregatorBinaryFunction fct = (DoubleSumAggregatorBinaryFunction)makeFunctor(); double total = 0.0; double result = 0.0; int calls = 31; Random rnd = new Random(); for( int i = 0; i < calls; i++ ) { double number = rnd.nextDouble(); total += number; result = fct.evaluate(result, number); assertEquals( result, total, DELTA ); } }
|
### Question:
DoubleMeanValueAggregatorFunction implements Function<List<Double>, Double> { public Double evaluate(List<Double> data) { if (data == null || data.size() == 0) { return null; } double mean = 0.0; int n = data.size(); for (Double d : data) { mean += d.doubleValue(); } mean /= n; return mean; } Double evaluate(List<Double> data); @Override String toString(); }### Answer:
@Test public void testEmptyList() throws Exception { DoubleMeanValueAggregatorFunction fct = (DoubleMeanValueAggregatorFunction)makeFunctor(); List<Double> lst = null; Double res = fct.evaluate(lst); assertNull( res ); lst = new ArrayList<Double>(); res = fct.evaluate(lst); assertNull( res ); }
@Test public void testMean() throws Exception { DoubleMeanValueAggregatorFunction fct = (DoubleMeanValueAggregatorFunction)makeFunctor(); List<Double> lst = new ArrayList<Double>(); lst.add( 0.0 ); double res = fct.evaluate(lst); assertEquals(res, 0.0, 0.01); lst.add( 1.0 ); res = fct.evaluate( lst ); assertEquals( res, 0.5, 0.01 ); lst.add( 2.0 ); res = fct.evaluate( lst ); assertEquals( res, 1.0, 0.01 ); int calls = 31; double total; for( int i = 2; i <= calls; i++ ) { lst.clear(); total = 0.0; for( int j = 1; j <= i; j++ ) { lst.add( (double)j ); total += j; } total /= i; res = fct.evaluate( lst ); assertEquals( res, total, 0.01 ); } }
|
### Question:
DoubleSumAggregatorFunction implements Function<List<Double>, Double> { public Double evaluate(List<Double> data) { if (data == null || data.size() == 0) { return null; } double sum = 0.0; for (Double d : data) { sum += d; } return sum; } Double evaluate(List<Double> data); @Override String toString(); }### Answer:
@Test public void testEmptyList() throws Exception { DoubleSumAggregatorFunction fct = (DoubleSumAggregatorFunction) makeFunctor(); List<Double> lst = null; Double res = fct.evaluate(lst); assertNull(res); lst = new ArrayList<Double>(); res = fct.evaluate(lst); assertNull(res); }
@Test public void testSum() throws Exception { DoubleSumAggregatorFunction fct = (DoubleSumAggregatorFunction) makeFunctor(); List<Double> lst = new ArrayList<Double>(); lst.add(0.0); double res = fct.evaluate(lst); assertEquals(res, 0.0, 0.01); lst.add(1.0); res = fct.evaluate(lst); assertEquals(res, 1.0, 0.01); lst.add(2.0); res = fct.evaluate(lst); assertEquals(res, 3.0, 0.01); lst.clear(); int calls = 31; double total = 0.0; Random rnd = new Random(); for (int i = 0; i < calls; i++) { double random = rnd.nextDouble(); lst.add(random); total += random; res = fct.evaluate(lst); assertEquals(res, total, 0.01); } }
|
### Question:
DoubleMaxAggregatorBinaryFunction implements BinaryFunction<Double, Double, Double> { public Double evaluate(Double left, Double right) { if (left == null) { return right; } if (right == null) { return left; } if (left.doubleValue() < right.doubleValue()) { return right; } return left; } Double evaluate(Double left, Double right); @Override String toString(); }### Answer:
@Test public void testNulls() throws Exception { DoubleMaxAggregatorBinaryFunction fct = (DoubleMaxAggregatorBinaryFunction) makeFunctor(); Double d = fct.evaluate(null, null); assertNull(d); d = fct.evaluate(null, 1.0); assertEquals(1.0, d.doubleValue(), DELTA); d = fct.evaluate(2.0, null); assertEquals(2.0, d.doubleValue(), DELTA); }
@Test public void testMax() throws Exception { DoubleMaxAggregatorBinaryFunction fct = (DoubleMaxAggregatorBinaryFunction) makeFunctor(); double max = 0.0; double result = 0.0; double number1 = 0.0; double number2 = 0.0; int calls = 31; Random rnd = new Random(); for (int i = 0; i < calls; i++) { number1 = rnd.nextDouble(); number2 = rnd.nextDouble(); max = Math.max(number1, number2); result = fct.evaluate(number1, number2); assertEquals(result, max, DELTA); } }
|
### Question:
DoubleMedianValueAggregatorFunction implements Function<List<Double>, Double> { public boolean isUseCopy() { return useCopy; } DoubleMedianValueAggregatorFunction(); DoubleMedianValueAggregatorFunction(boolean useCopy); boolean isUseCopy(); Double evaluate(List<Double> data); @Override String toString(); }### Answer:
@Test public void testMedianCopy() throws Exception { DoubleMedianValueAggregatorFunction fct = new DoubleMedianValueAggregatorFunction(true); assertTrue(fct.isUseCopy()); checkMedianCopy(fct); fct = (DoubleMedianValueAggregatorFunction) makeFunctor(); checkMedianCopy(fct); }
|
### Question:
UntilGenerate extends LoopGenerator<E> { @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof UntilGenerate<?>)) { return false; } UntilGenerate<?> other = (UntilGenerate<?>) obj; return other.getWrappedGenerator().equals(getWrappedGenerator()) && other.test.equals(test); } UntilGenerate(Predicate<? super E> test, Generator<? extends E> wrapped); void run(final Procedure<? super E> proc); @Override boolean equals(Object obj); @Override int hashCode(); }### Answer:
@Test public void testEquals() { Generator<Integer> anotherGenerate = new UntilGenerate<Integer>( isGreaterThanFive, IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10))); assertEquals(untilGenerate, untilGenerate); assertEquals(untilGenerate, anotherGenerate); assertTrue(!untilGenerate.equals((UntilGenerate<Integer>)null)); Generator<Integer> aGenerateWithADifferentPredicate = new UntilGenerate<Integer>( new Predicate<Integer>() { public boolean test(Integer obj) { return obj < FIVE; } }, IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 10))); assertTrue(!untilGenerate.equals(aGenerateWithADifferentPredicate)); Generator<Integer> aGenerateWithADifferentWrapped = new UntilGenerate<Integer>( isGreaterThanFive, IteratorToGeneratorAdapter.adapt(new IntegerRange(1,2))); assertTrue(!untilGenerate.equals(aGenerateWithADifferentWrapped)); }
|
### Question:
UntilGenerate extends LoopGenerator<E> { @Override public int hashCode() { int result = "UntilGenerate".hashCode(); result <<= 2; Generator<?> gen = getWrappedGenerator(); result ^= gen.hashCode(); result <<= 2; result ^= test.hashCode(); return result; } UntilGenerate(Predicate<? super E> test, Generator<? extends E> wrapped); void run(final Procedure<? super E> proc); @Override boolean equals(Object obj); @Override int hashCode(); }### Answer:
@Test public void testHashcode() { assertEquals(untilGenerate.hashCode(), untilGenerate.hashCode()); assertEquals(untilGenerate.hashCode(), new UntilGenerate<Integer>(isGreaterThanFive, wrappedGenerator).hashCode()); }
|
### Question:
UntilGenerate extends LoopGenerator<E> { public void run(final Procedure<? super E> proc) { getWrappedGenerator().run(new Procedure<E>() { public void run(E obj) { if (test.test(obj)) { UntilGenerate.this.stop(); } else { proc.run(obj); } } }); } UntilGenerate(Predicate<? super E> test, Generator<? extends E> wrapped); void run(final Procedure<? super E> proc); @Override boolean equals(Object obj); @Override int hashCode(); }### Answer:
@Test public void testGenerate() { final List<Integer> numbersGreaterThanFive = new ArrayList<Integer>(); untilGenerate.run(new Procedure<Integer>() { public void run( Integer obj ) { numbersGreaterThanFive.add(obj); } }); assertEquals(5, numbersGreaterThanFive.size()); final List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5); assertEquals(expected, numbersGreaterThanFive); }
|
### Question:
IteratorToGeneratorAdapter extends LoopGenerator<E> { public static <E> IteratorToGeneratorAdapter<E> adapt(Iterator<? extends E> iter) { return null == iter ? null : new IteratorToGeneratorAdapter<E>(iter); } IteratorToGeneratorAdapter(Iterator<? extends E> iter); void run(Procedure<? super E> proc); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static IteratorToGeneratorAdapter<E> adapt(Iterator<? extends E> iter); static IteratorToGeneratorAdapter<E> adapt(Iterable<? extends E> iterable); }### Answer:
@Test public void testAdaptNull() { assertNull(IteratorToGeneratorAdapter.adapt((Iterator<?>) null)); }
@Test public void testAdaptNonNull() { assertNotNull(IteratorToGeneratorAdapter.adapt(list.iterator())); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.