cleanups
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/functor/trunk@1541658 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java b/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java
index 94536ea..bcb7d3c 100644
--- a/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java
+++ b/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java
@@ -38,38 +38,37 @@
@Test
public final void testObjectEquals() throws Exception {
Object obj = makeFunctor();
- assertEquals("equals must be reflexive",obj,obj);
- assertEquals("hashCode must be reflexive",obj.hashCode(),obj.hashCode());
- assertTrue(! obj.equals(null) ); // should be able to compare to null
+ assertEquals("equals must be reflexive", obj, obj);
+ assertEquals("hashCode must be reflexive", obj.hashCode(), obj.hashCode());
+ assertTrue(!obj.equals(null)); // should be able to compare to null
Object obj2 = makeFunctor();
if (obj.equals(obj2)) {
- assertEquals("equals implies hash equals",obj.hashCode(),obj2.hashCode());
- assertEquals("equals must be symmetric",obj2,obj);
+ assertEquals("equals implies hash equals", obj.hashCode(), obj2.hashCode());
+ assertEquals("equals must be symmetric", obj2, obj);
} else {
- assertTrue("equals must be symmetric",! obj2.equals(obj));
+ assertTrue("equals must be symmetric", !obj2.equals(obj));
}
-
- assertTrue("a functor is not equal to an integer", ! obj.equals(new Integer(1)));
+
+ assertTrue("a functor is not equal to an integer", !obj.equals(Integer.valueOf(1)));
}
@Test
public void testToStringIsOverridden() throws Exception {
Object obj = makeFunctor();
- assertNotNull("toString should never return null",obj.toString());
- assertTrue(
- obj.getClass().getName() + " should override toString(), found \"" + obj.toString() + "\"",
- !obj.toString().equals(objectToString(obj)));
+ assertNotNull("toString should never return null", obj.toString());
+ assertTrue(obj.getClass().getName() + " should override toString(), found \"" + obj.toString() + "\"", !obj
+ .toString().equals(objectToString(obj)));
}
// protected utils
// ------------------------------------------------------------------------
public static void assertObjectsAreEqual(Object a, Object b) {
- assertEquals(a,b);
- assertEquals(b,a);
- assertEquals(a.hashCode(),b.hashCode());
- assertEquals(a.toString(),b.toString()); // not strictly required
+ assertEquals(a, b);
+ assertEquals(b, a);
+ assertEquals(a.hashCode(), b.hashCode());
+ assertEquals(a.toString(), b.toString()); // not strictly required
}
public static void assertObjectsAreNotEqual(Object a, Object b) {
@@ -84,4 +83,4 @@
private String objectToString(Object obj) {
return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode());
}
-}
\ No newline at end of file
+}
diff --git a/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java b/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
index fc22086..e386cc0 100644
--- a/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
+++ b/core/src/test/java/org/apache/commons/functor/TestAlgorithms.java
@@ -54,14 +54,14 @@
doubled = new ArrayList<Integer>();
listWithDuplicates = new ArrayList<Integer>();
sum = 0;
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- doubled.add(new Integer(i*2));
- listWithDuplicates.add(new Integer(i));
- listWithDuplicates.add(new Integer(i));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ doubled.add(Integer.valueOf(i * 2));
+ listWithDuplicates.add(Integer.valueOf(i));
+ listWithDuplicates.add(Integer.valueOf(i));
sum += i;
- if (i%2 == 0) {
- evens.add(new Integer(i));
+ if (i % 2 == 0) {
+ evens.add(Integer.valueOf(i));
}
}
}
@@ -77,68 +77,72 @@
// Tests
// ------------------------------------------------------------------------
-
-
@Test
public void testRun() {
Summer summer = new Summer();
IteratorToGeneratorAdapter.adapt(list.iterator()).run(summer);
- assertEquals(sum,summer.sum);
+ assertEquals(sum, summer.sum);
}
@Test
public void testSelect1() {
- Collection<Integer> result = new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),isEven).toCollection();
+ Collection<Integer> result =
+ new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()), isEven).toCollection();
assertNotNull(result);
- assertEquals(evens,result);
+ assertEquals(evens, result);
}
@Test
public void testSelect2() {
List<Integer> result = new ArrayList<Integer>();
- assertSame(result,new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),isEven).to(result));
- assertEquals(evens,result);
+ assertSame(result,
+ new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()), isEven).to(result));
+ assertEquals(evens, result);
}
@Test
public void testReject1() {
- Collection<Integer> result = new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),new Not<Integer>(isOdd)).toCollection();
+ Collection<Integer> result =
+ new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()), new Not<Integer>(isOdd))
+ .toCollection();
assertNotNull(result);
- assertEquals(evens,result);
+ assertEquals(evens, result);
}
@Test
public void testReject2() {
List<Object> result = new ArrayList<Object>();
- assertSame(result,new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),new Not<Integer>(isOdd)).to(result));
- assertEquals(evens,result);
+ assertSame(result, new FilteredGenerator<Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),
+ new Not<Integer>(isOdd)).to(result));
+ assertEquals(evens, result);
}
@Test
public void testApplyToGenerator() {
- LoopGenerator<Integer> gen = IteratorToGeneratorAdapter.adapt(new IntegerRange(1,5));
+ LoopGenerator<Integer> gen = IteratorToGeneratorAdapter.adapt(new IntegerRange(1, 5));
Summer summer = new Summer();
new TransformedGenerator<Integer, Integer>(gen, new Doubler()).run(summer);
- assertEquals(2*(1+2+3+4),summer.sum);
+ assertEquals(2 * (1 + 2 + 3 + 4), summer.sum);
}
@Test
public void testApply() {
- Collection<Integer> result = new TransformedGenerator<Integer, Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()), new Doubler())
+ Collection<Integer> result =
+ new TransformedGenerator<Integer, Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()), new Doubler())
.toCollection();
assertNotNull(result);
- assertEquals(doubled,result);
+ assertEquals(doubled, result);
}
@Test
public void testApply2() {
Set<Integer> set = new HashSet<Integer>();
- assertSame(set, new TransformedGenerator<Integer, Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()), Identity.<Integer>instance())
- .to(set));
- assertEquals(list.size(),set.size());
- for (Iterator<Integer> iter = list.iterator(); iter.hasNext(); ) {
+ assertSame(set, new TransformedGenerator<Integer, Integer>(IteratorToGeneratorAdapter.adapt(list.iterator()),
+ Identity.<Integer> instance()).to(set));
+ assertEquals(list.size(), set.size());
+ for (Iterator<Integer> iter = list.iterator(); iter.hasNext();) {
assertTrue(set.contains(iter.next()));
}
}
@@ -146,10 +150,11 @@
@Test
public void testApply3() {
Set<Object> set = new HashSet<Object>();
- assertSame(set, new TransformedGenerator<Object, Object>(IteratorToGeneratorAdapter.adapt(listWithDuplicates.iterator()),
+ assertSame(set,
+ new TransformedGenerator<Object, Object>(IteratorToGeneratorAdapter.adapt(listWithDuplicates.iterator()),
Identity.instance()).to(set));
assertTrue(listWithDuplicates.size() > set.size());
- for (Iterator<Integer> iter = listWithDuplicates.iterator(); iter.hasNext(); ) {
+ for (Iterator<Integer> iter = listWithDuplicates.iterator(); iter.hasNext();) {
assertTrue(set.contains(iter.next()));
}
}
@@ -179,6 +184,7 @@
public void run() {
count++;
}
+
public int count = 0;
}
@@ -186,12 +192,13 @@
public void run(Integer that) {
sum += that.intValue();
}
+
public int sum = 0;
}
static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
- return new Integer(2* obj.intValue());
+ return Integer.valueOf(2 * obj.intValue());
}
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionBinaryProcedure.java b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionBinaryProcedure.java
index 8981b34..5f31ace 100644
--- a/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionBinaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/adapter/TestBinaryFunctionBinaryProcedure.java
@@ -48,7 +48,7 @@
public void testRun() throws Exception {
class EvaluateCounter implements BinaryFunction<Object, Object, Integer> {
int count = 0;
- public Integer evaluate(Object a, Object b) { return new Integer(count++); }
+ public Integer evaluate(Object a, Object b) { return Integer.valueOf(count++); }
}
EvaluateCounter counter = new EvaluateCounter();
BinaryProcedure<Object, Object> p = new BinaryFunctionBinaryProcedure<Object, Object>(counter);
diff --git a/core/src/test/java/org/apache/commons/functor/aggregator/AbstractTimedAggregatorTest.java b/core/src/test/java/org/apache/commons/functor/aggregator/AbstractTimedAggregatorTest.java
index bba1003..c4cc488 100644
--- a/core/src/test/java/org/apache/commons/functor/aggregator/AbstractTimedAggregatorTest.java
+++ b/core/src/test/java/org/apache/commons/functor/aggregator/AbstractTimedAggregatorTest.java
@@ -86,7 +86,6 @@
// give enough time for the timer to kick in again
TimeUnit.MILLISECONDS.sleep(interval + SLEEP);
assertEquals(saveValue, count.get());
-
}
@Test
@@ -154,7 +153,7 @@
@Override
protected void doReset() {
- object = new Integer(0);
+ object = Integer.valueOf( 0);
}
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestConstant.java b/core/src/test/java/org/apache/commons/functor/core/TestConstant.java
index 9ef4a6a..1a60ec4 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestConstant.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestConstant.java
@@ -43,12 +43,12 @@
@Test
public void testEvaluate() throws Exception {
Constant<Object> f = new Constant<Object>("xyzzy");
- assertEquals("xyzzy",f.evaluate());
- assertEquals("xyzzy",f.evaluate(null));
- assertEquals("xyzzy",f.evaluate(null,null));
- assertEquals("xyzzy",f.evaluate());
- assertEquals("xyzzy",f.evaluate("foo"));
- assertEquals("xyzzy",f.evaluate("foo",new Integer(2)));
+ assertEquals("xyzzy", f.evaluate());
+ assertEquals("xyzzy", f.evaluate(null));
+ assertEquals("xyzzy", f.evaluate(null, null));
+ assertEquals("xyzzy", f.evaluate());
+ assertEquals("xyzzy", f.evaluate("foo"));
+ assertEquals("xyzzy", f.evaluate("foo", Integer.valueOf(2)));
}
@Test
@@ -56,10 +56,10 @@
Constant<Object> f = new Constant<Object>(null);
assertNull(f.evaluate());
assertNull(f.evaluate(null));
- assertNull(f.evaluate(null,null));
+ assertNull(f.evaluate(null, null));
assertNull(f.evaluate());
assertNull(f.evaluate("foo"));
- assertNull(f.evaluate("foo",new Integer(2)));
+ assertNull(f.evaluate("foo", Integer.valueOf(2)));
}
@Test
@@ -67,11 +67,11 @@
Constant<Object> truePred = new Constant<Object>(Boolean.TRUE);
assertTrue(truePred.test());
assertTrue(truePred.test(null));
- assertTrue(truePred.test(null,null));
+ assertTrue(truePred.test(null, null));
assertTrue(truePred.test());
assertTrue(truePred.test("foo"));
- assertTrue(truePred.test("foo",new Integer(2)));
+ assertTrue(truePred.test("foo", Integer.valueOf(2)));
}
@Test
@@ -79,41 +79,40 @@
Constant<Object> falsePred = new Constant<Object>(Boolean.FALSE);
assertTrue(!falsePred.test());
assertTrue(!falsePred.test(null));
- assertTrue(!falsePred.test(null,null));
+ assertTrue(!falsePred.test(null, null));
assertTrue(!falsePred.test());
assertTrue(!falsePred.test("foo"));
- assertTrue(!falsePred.test("foo",new Integer(2)));
+ assertTrue(!falsePred.test("foo", Integer.valueOf(2)));
}
@Test
public void testEquals() throws Exception {
Constant<Object> f = new Constant<Object>("xyzzy");
- assertEquals(f,f);
+ assertEquals(f, f);
- assertObjectsAreEqual(f,new Constant<Object>("xyzzy"));
- assertObjectsAreNotEqual(f,new Constant<Object>("abcde"));
- assertObjectsAreNotEqual(f,new Constant<Object>(null));
- assertObjectsAreEqual(new Constant<Object>(null),new Constant<Object>(null));
+ assertObjectsAreEqual(f, new Constant<Object>("xyzzy"));
+ assertObjectsAreNotEqual(f, new Constant<Object>("abcde"));
+ assertObjectsAreNotEqual(f, new Constant<Object>(null));
+ assertObjectsAreEqual(new Constant<Object>(null), new Constant<Object>(null));
assertTrue(!f.equals(null));
}
@Test
public void testConstants() throws Exception {
- assertEquals(Constant.predicate(true),Constant.TRUE);
+ assertEquals(Constant.predicate(true), Constant.TRUE);
- assertEquals(Constant.truePredicate(),Constant.TRUE);
- assertSame(Constant.truePredicate(),Constant.TRUE);
+ assertEquals(Constant.truePredicate(), Constant.TRUE);
+ assertSame(Constant.truePredicate(), Constant.TRUE);
- assertEquals(Constant.predicate(true),Constant.TRUE);
- assertSame(Constant.predicate(true),Constant.TRUE);
+ assertEquals(Constant.predicate(true), Constant.TRUE);
+ assertSame(Constant.predicate(true), Constant.TRUE);
- assertEquals(Constant.falsePredicate(),Constant.FALSE);
- assertSame(Constant.falsePredicate(),Constant.FALSE);
+ assertEquals(Constant.falsePredicate(), Constant.FALSE);
+ assertSame(Constant.falsePredicate(), Constant.FALSE);
- assertEquals(Constant.predicate(false),Constant.FALSE);
- assertSame(Constant.predicate(false),Constant.FALSE);
+ assertEquals(Constant.predicate(false), Constant.FALSE);
+ assertSame(Constant.predicate(false), Constant.FALSE);
}
-
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java b/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java
index c0430bf..a49178b 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIdentity.java
@@ -48,8 +48,8 @@
Function<Object, Object> f = new Identity<Object>();
assertNull(f.evaluate(null));
assertEquals("xyzzy",f.evaluate("xyzzy"));
- assertEquals(new Integer(3),f.evaluate(new Integer(3)));
- Object obj = new Long(12345L);
+ assertEquals(Integer.valueOf(3),f.evaluate(Integer.valueOf(3)));
+ Object obj = Long.valueOf(12345L);
assertSame(obj,f.evaluate(obj));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java b/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
index 4d6db9b..2abc166 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsEqual.java
@@ -50,14 +50,14 @@
assertTrue(p.test("foo", "foo"));
assertFalse(p.test(null, "foo"));
assertFalse(p.test("foo", null));
- assertTrue(p.test(new Integer(3), new Integer(3)));
- assertFalse(p.test(null, new Integer(3)));
- assertFalse(p.test(new Integer(3), null));
+ assertTrue(p.test(Integer.valueOf(3), Integer.valueOf(3)));
+ assertFalse(p.test(null, Integer.valueOf(3)));
+ assertFalse(p.test(Integer.valueOf(3), null));
- assertFalse(p.test(new Integer(3), new Integer(4)));
- assertFalse(p.test(new Integer(4), new Integer(3)));
- assertFalse(p.test("3", new Integer(3)));
- assertFalse(p.test(new Integer(3), "3"));
+ assertFalse(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(4), Integer.valueOf(3)));
+ assertFalse(p.test("3", Integer.valueOf(3)));
+ assertFalse(p.test(Integer.valueOf(3), "3"));
}
@Test
@@ -79,8 +79,8 @@
@Test
public void testToPredicate() {
- Predicate<Integer> isEqual = IsEqual.to(new Integer(1));
- assertTrue(isEqual.test(new Integer(1)));
- assertFalse(isEqual.test(new Integer(2)));
+ Predicate<Integer> isEqual = IsEqual.to(Integer.valueOf(1));
+ assertTrue(isEqual.test(Integer.valueOf(1)));
+ assertFalse(isEqual.test(Integer.valueOf(2)));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
index fc24eae..6ecacd0 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNotEqual.java
@@ -44,38 +44,38 @@
@Test
public void testTest() throws Exception {
IsNotEqual<Object, Object> p = new IsNotEqual<Object, Object>();
- assertTrue("For symmetry, two nulls should be equal",!p.test(null,null));
- assertTrue(!p.test("foo","foo"));
- assertTrue(p.test(null,"foo"));
- assertTrue(p.test("foo",null));
- assertTrue(!p.test(new Integer(3),new Integer(3)));
- assertTrue(p.test(null,new Integer(3)));
- assertTrue(p.test(new Integer(3),null));
+ assertTrue("For symmetry, two nulls should be equal", !p.test(null, null));
+ assertTrue(!p.test("foo", "foo"));
+ assertTrue(p.test(null, "foo"));
+ assertTrue(p.test("foo", null));
+ assertTrue(!p.test(Integer.valueOf(3), Integer.valueOf(3)));
+ assertTrue(p.test(null, Integer.valueOf(3)));
+ assertTrue(p.test(Integer.valueOf(3), null));
- assertTrue(p.test(new Integer(3),new Integer(4)));
- assertTrue(p.test(new Integer(4),new Integer(3)));
- assertTrue(p.test("3",new Integer(3)));
- assertTrue(p.test(new Integer(3),"3"));
+ assertTrue(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(4), Integer.valueOf(3)));
+ assertTrue(p.test("3", Integer.valueOf(3)));
+ assertTrue(p.test(Integer.valueOf(3), "3"));
}
@Test
public void testEquals() throws Exception {
BinaryPredicate<Object, Object> p = new IsNotEqual<Object, Object>();
- assertEquals(p,p);
- assertObjectsAreEqual(p,new IsNotEqual<Object, Object>());
- assertObjectsAreEqual(p,IsNotEqual.instance());
- assertObjectsAreNotEqual(p,Constant.truePredicate());
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new IsNotEqual<Object, Object>());
+ assertObjectsAreEqual(p, IsNotEqual.instance());
+ assertObjectsAreNotEqual(p, Constant.truePredicate());
}
@Test
public void testConstant() throws Exception {
- assertEquals(IsNotEqual.instance(),IsNotEqual.instance());
+ assertEquals(IsNotEqual.instance(), IsNotEqual.instance());
}
@Test
public void testToPredicate() {
- Predicate<Integer> isNotEqual = IsNotEqual.to(new Integer(1));
- assertTrue(isNotEqual.test(new Integer(2)));
- assertFalse(isNotEqual.test(new Integer(1)));
+ Predicate<Integer> isNotEqual = IsNotEqual.to(Integer.valueOf(1));
+ assertTrue(isNotEqual.test(Integer.valueOf(2)));
+ assertFalse(isNotEqual.test(Integer.valueOf(1)));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java
index 74137e9..85647e0 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNotNull.java
@@ -44,20 +44,20 @@
Predicate<Object> p = new IsNotNull<Object>();
assertTrue(!p.test(null));
assertTrue(p.test("foo"));
- assertTrue(p.test(new Integer(3)));
+ assertTrue(p.test(Integer.valueOf(3)));
}
@Test
public void testEquals() throws Exception {
Predicate<Object> p = new IsNotNull<Object>();
- assertEquals(p,p);
- assertObjectsAreEqual(p,new IsNotNull<Object>());
- assertObjectsAreEqual(p,IsNotNull.instance());
- assertObjectsAreNotEqual(p,Constant.TRUE);
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new IsNotNull<Object>());
+ assertObjectsAreEqual(p, IsNotNull.instance());
+ assertObjectsAreNotEqual(p, Constant.TRUE);
}
@Test
public void testConstant() throws Exception {
- assertEquals(IsNotNull.instance(),IsNotNull.instance());
+ assertEquals(IsNotNull.instance(), IsNotNull.instance());
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
index 751674d..940a32c 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNotSame.java
@@ -50,14 +50,14 @@
assertFalse(p.test("foo", "foo"));
assertTrue(p.test(null, "foo"));
assertTrue(p.test("foo", null));
- assertTrue(p.test(new Integer(3), new Integer(3)));
- assertTrue(p.test(null, new Integer(3)));
- assertTrue(p.test(new Integer(3), null));
+ assertTrue(p.test(new Integer(3), Integer.valueOf(3)));
+ assertTrue(p.test(null, Integer.valueOf(3)));
+ assertTrue(p.test(Integer.valueOf(3), null));
- assertTrue(p.test(new Integer(3), new Integer(4)));
- assertTrue(p.test(new Integer(4), new Integer(3)));
- assertTrue(p.test("3", new Integer(3)));
- assertTrue(p.test(new Integer(3), "3"));
+ assertTrue(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(4), Integer.valueOf(3)));
+ assertTrue(p.test("3", Integer.valueOf(3)));
+ assertTrue(p.test(Integer.valueOf(3), "3"));
}
@Test
@@ -79,9 +79,9 @@
@Test
public void testAsPredicate() {
- Integer one = new Integer(1);
+ Integer one = Integer.valueOf(1);
Predicate<Integer> isNotSame = IsNotSame.as(one);
- assertTrue(isNotSame.test(new Integer(2)));
+ assertTrue(isNotSame.test(Integer.valueOf(2)));
assertFalse(isNotSame.test(one));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java b/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java
index 8696e97..e3bbb04 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsNull.java
@@ -45,28 +45,28 @@
Predicate<Object> p = new IsNull<Object>();
assertTrue(p.test(null));
assertFalse(p.test("foo"));
- assertFalse(p.test(new Integer(3)));
+ assertFalse(p.test(Integer.valueOf(3)));
}
@Test
public void testAsBinary() throws Exception {
- assertTrue(IsNull.left().test(null,"not null"));
- assertFalse(IsNull.left().test("not null",null));
- assertTrue(IsNull.right().test("not null",null));
- assertFalse(IsNull.right().test(null,"not null"));
+ assertTrue(IsNull.left().test(null, "not null"));
+ assertFalse(IsNull.left().test("not null", null));
+ assertTrue(IsNull.right().test("not null", null));
+ assertFalse(IsNull.right().test(null, "not null"));
}
@Test
public void testEquals() throws Exception {
Predicate<Object> p = new IsNull<Object>();
- assertEquals(p,p);
- assertObjectsAreEqual(p,new IsNull<Object>());
- assertObjectsAreEqual(p,IsNull.instance());
- assertObjectsAreNotEqual(p,Constant.TRUE);
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new IsNull<Object>());
+ assertObjectsAreEqual(p, IsNull.instance());
+ assertObjectsAreNotEqual(p, Constant.TRUE);
}
@Test
public void testConstant() throws Exception {
- assertEquals(IsNull.instance(),IsNull.instance());
+ assertEquals(IsNull.instance(), IsNull.instance());
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java b/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java
index 259a5f9..5cf72d0 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestIsSame.java
@@ -50,14 +50,14 @@
assertTrue(p.test("foo", "foo"));
assertFalse(p.test(null, "foo"));
assertFalse(p.test("foo", null));
- assertFalse(p.test(new Integer(3), new Integer(3)));
- assertFalse(p.test(null, new Integer(3)));
- assertFalse(p.test(new Integer(3), null));
+ assertFalse(p.test(new Integer(3), Integer.valueOf(3)));
+ assertFalse(p.test(null, Integer.valueOf(3)));
+ assertFalse(p.test(Integer.valueOf(3), null));
- assertFalse(p.test(new Integer(3), new Integer(4)));
- assertFalse(p.test(new Integer(4), new Integer(3)));
- assertFalse(p.test("3", new Integer(3)));
- assertFalse(p.test(new Integer(3), "3"));
+ assertFalse(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(4), Integer.valueOf(3)));
+ assertFalse(p.test("3", Integer.valueOf(3)));
+ assertFalse(p.test(Integer.valueOf(3), "3"));
}
@Test
@@ -79,9 +79,9 @@
@Test
public void testAsPredicate() {
- Integer one = new Integer(1);
+ Integer one = Integer.valueOf(1);
Predicate<Integer> isSame = IsSame.as(one);
assertTrue(isSame.test(one));
- assertFalse(isSame.test(new Integer(2)));
+ assertFalse(isSame.test(Integer.valueOf(2)));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java b/core/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
index f138629..d47e5f9 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java
@@ -55,8 +55,8 @@
assertNull(f.evaluate(null,"xyzzy"));
assertEquals("xyzzy",f.evaluate("xyzzy","abcdefg"));
assertEquals("xyzzy",f.evaluate("xyzzy",null));
- assertEquals(new Integer(3),f.evaluate(new Integer(3),null));
- Object obj = new Long(12345L);
+ assertEquals(Integer.valueOf(3),f.evaluate(Integer.valueOf(3),null));
+ Object obj = Long.valueOf(12345L);
assertSame(obj,f.evaluate(obj,null));
assertSame(obj,f.evaluate(obj,obj));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java b/core/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java
index 841c535..3ac2be6 100644
--- a/core/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java
+++ b/core/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java
@@ -55,8 +55,8 @@
assertNull(f.evaluate("xyzzy",null));
assertEquals("xyzzy",f.evaluate("abcdefg","xyzzy"));
assertEquals("xyzzy",f.evaluate(null,"xyzzy"));
- assertEquals(new Integer(3),f.evaluate(null,new Integer(3)));
- Object obj = new Long(12345L);
+ assertEquals(Integer.valueOf(3),f.evaluate(null,Integer.valueOf(3)));
+ Object obj = Long.valueOf(12345L);
assertSame(obj,f.evaluate(null,obj));
assertSame(obj,f.evaluate(obj,obj));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
index bff00a4..622bd8c 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
@@ -44,55 +44,62 @@
@Test
public void testObjectEqualsWithIfNone() throws Exception {
Object obj = new FindWithinGenerator<Object>(1);
- assertEquals("equals must be reflexive",obj,obj);
- assertEquals("hashCode must be reflexive",obj.hashCode(),obj.hashCode());
- assertTrue(! obj.equals(null) ); // should be able to compare to null
+ assertEquals("equals must be reflexive", obj, obj);
+ assertEquals("hashCode must be reflexive", obj.hashCode(), obj.hashCode());
+ assertTrue(!obj.equals(null)); // should be able to compare to null
Object obj2 = new FindWithinGenerator<Object>(1);
if (obj.equals(obj2)) {
- assertEquals("equals implies hash equals",obj.hashCode(),obj2.hashCode());
- assertEquals("equals must be symmetric",obj2,obj);
+ assertEquals("equals implies hash equals", obj.hashCode(), obj2.hashCode());
+ assertEquals("equals must be symmetric", obj2, obj);
} else {
- assertTrue("equals must be symmetric",! obj2.equals(obj));
+ assertTrue("equals must be symmetric", !obj2.equals(obj));
}
}
@Test
public void testObjectEqualsWithNullDefault() throws Exception {
Object obj = new FindWithinGenerator<Object>(null);
- assertEquals("equals must be reflexive",obj,obj);
- assertEquals("hashCode must be reflexive",obj.hashCode(),obj.hashCode());
- assertTrue(! obj.equals(null) ); // should be able to compare to null
+ assertEquals("equals must be reflexive", obj, obj);
+ assertEquals("hashCode must be reflexive", obj.hashCode(), obj.hashCode());
+ assertTrue(!obj.equals(null)); // should be able to compare to null
Object obj2 = new FindWithinGenerator<Object>(null);
if (obj.equals(obj2)) {
- assertEquals("equals implies hash equals",obj.hashCode(),obj2.hashCode());
- assertEquals("equals must be symmetric",obj2,obj);
+ assertEquals("equals implies hash equals", obj.hashCode(), obj2.hashCode());
+ assertEquals("equals must be symmetric", obj2, obj);
} else {
- assertTrue("equals must be symmetric",! obj2.equals(obj));
+ assertTrue("equals must be symmetric", !obj2.equals(obj));
}
}
@Test
public void testEquals() {
FindWithinGenerator<Object> f = new FindWithinGenerator<Object>();
- assertEquals(f,f);
+ assertEquals(f, f);
- assertObjectsAreEqual(f,new FindWithinGenerator<Object>());
- assertObjectsAreEqual(new FindWithinGenerator<Object>(new Double(0)),new FindWithinGenerator<Object>(new Double(0)));
- assertObjectsAreNotEqual(f, new FindWithinGenerator<Object>(new Integer(0)));
+ assertObjectsAreEqual(f, new FindWithinGenerator<Object>());
+ assertObjectsAreEqual(new FindWithinGenerator<Object>(Double.valueOf(0)), new FindWithinGenerator<Object>(
+ Double.valueOf(0)));
+ assertObjectsAreNotEqual(f, new FindWithinGenerator<Object>(Integer.valueOf(0)));
}
- @Test(expected=NoSuchElementException.class)
+ @Test(expected = NoSuchElementException.class)
public void testDetect() {
- assertEquals(new Integer(3),new FindWithinGenerator<Integer>().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsThree));
- new FindWithinGenerator<Integer>().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsTwentyThree);
+ assertEquals(Integer.valueOf(3), new FindWithinGenerator<Integer>().evaluate(
+ IteratorToGeneratorAdapter.adapt(numbers.iterator()), equalsThree));
+ new FindWithinGenerator<Integer>().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),
+ equalsTwentyThree);
}
@Test
public void testDetectIfNone() {
- assertEquals(new Integer(3),new FindWithinGenerator<Integer>(new Integer(3)).evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsThree));
- assertEquals("Xyzzy",new FindWithinGenerator<String>("Xyzzy").evaluate(IteratorToGeneratorAdapter.adapt(strings.iterator()),equalsXyZ));
+ assertEquals(
+ Integer.valueOf(3),
+ new FindWithinGenerator<Integer>(Integer.valueOf(3)).evaluate(
+ IteratorToGeneratorAdapter.adapt(numbers.iterator()), equalsThree));
+ assertEquals("Xyzzy", new FindWithinGenerator<String>("Xyzzy").evaluate(
+ IteratorToGeneratorAdapter.adapt(strings.iterator()), equalsXyZ));
}
@Test
@@ -103,10 +110,10 @@
// Attributes
// ------------------------------------------------------------------------
- private List<Integer> numbers = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
+ private List<Integer> numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
private List<String> strings = Arrays.asList("Zyx", "xxyZ");
- private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
- private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
- private Predicate<String> equalsXyZ = LeftBoundPredicate.bind(IsEqual.instance(),"xyZ");
+ private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(3));
+ private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(23));
+ private Predicate<String> equalsXyZ = LeftBoundPredicate.bind(IsEqual.instance(), "xyZ");
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java
index 2c31f8e..ea4ab9a 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java
@@ -41,12 +41,12 @@
public void testFoldLeft() {
FoldLeft<Integer> foldLeft = new FoldLeft<Integer>(new BinaryFunction<Integer, Integer, Integer>() {
public Integer evaluate(Integer a, Integer b) {
- return new Integer(a + b);
+ return Integer.valueOf(a + b);
}
});
- assertEquals(new Integer(sum), foldLeft.evaluate(IteratorToGeneratorAdapter.adapt(list.iterator())));
- assertEquals(new Integer(sum), foldLeft.evaluate(IteratorToGeneratorAdapter.adapt(list.iterator()), new Integer(0)));
- assertEquals(new Integer(0), foldLeft.evaluate(IteratorToGeneratorAdapter.adapt(new ArrayList<Integer>(0).iterator()), new Integer(0)), new Integer(0));
+ assertEquals(Integer.valueOf(sum), foldLeft.evaluate(IteratorToGeneratorAdapter.adapt(list.iterator())));
+ assertEquals(Integer.valueOf(sum), foldLeft.evaluate(IteratorToGeneratorAdapter.adapt(list.iterator()), Integer.valueOf(0)));
+ assertEquals(Integer.valueOf(0), foldLeft.evaluate(IteratorToGeneratorAdapter.adapt(new ArrayList<Integer>(0).iterator()), Integer.valueOf(0)), Integer.valueOf(0));
}
// Attributes
@@ -60,7 +60,7 @@
static class Sum implements BinaryFunction<Integer, Integer, Integer> {
public Integer evaluate(Integer a, Integer b) {
- return new Integer(a + b);
+ return Integer.valueOf(a + b);
}
@Override
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
index 4333e72..108c621 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestGeneratorContains.java
@@ -42,15 +42,17 @@
@Test
public void testContains() {
- assertTrue(new GeneratorContains<Integer>().test(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsThree));
- assertFalse(new GeneratorContains<Integer>().test(IteratorToGeneratorAdapter.adapt(list.iterator()),equalsTwentyThree));
+ assertTrue(new GeneratorContains<Integer>()
+ .test(IteratorToGeneratorAdapter.adapt(list.iterator()), equalsThree));
+ assertFalse(new GeneratorContains<Integer>().test(IteratorToGeneratorAdapter.adapt(list.iterator()),
+ equalsTwentyThree));
}
// Attributes
// ------------------------------------------------------------------------
- private List<Integer> list = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
- private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
- private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
+ private List<Integer> list = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(3));
+ private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(23));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java
index 66f0fa7..2f2fe5a 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java
@@ -41,9 +41,9 @@
public void setUp() throws Exception {
list = new ArrayList<Integer>();
doubled = new ArrayList<Integer>();
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- doubled.add(new Integer(i*2));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ doubled.add(Integer.valueOf(i * 2));
}
}
@@ -63,15 +63,12 @@
@Test
public void testTransform() {
- new InPlaceTransform<Integer>().run(
- list.listIterator(),
- new Function<Integer, Integer>() {
- public Integer evaluate(Integer obj) {
- return new Integer(obj*2);
- }
+ new InPlaceTransform<Integer>().run(list.listIterator(), new Function<Integer, Integer>() {
+ public Integer evaluate(Integer obj) {
+ return Integer.valueOf(obj * 2);
}
- );
- assertEquals(doubled,list);
+ });
+ assertEquals(doubled, list);
}
public void testInstance() {
@@ -88,7 +85,7 @@
static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
- return new Integer(2*obj);
+ return Integer.valueOf(2 * obj);
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
index 2027e8f..ba26e2f 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java
@@ -47,6 +47,6 @@
// ------------------------------------------------------------------------
private List<Integer> list = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
- private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
+ private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),Integer.valueOf(3));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java
index 6a9f769..e045421 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java
@@ -35,13 +35,13 @@
@Test
public void testRecurse() {
- assertEquals(new Integer(5), new RecursiveEvaluation(new RecFunc(0, false)).evaluate());
+ assertEquals(Integer.valueOf(5), new RecursiveEvaluation(new RecFunc(0, false)).evaluate());
// this version will return a function. since it is not the same type
// as RecFunc recursion will end.
@SuppressWarnings({ "unchecked", "rawtypes" })
NullaryFunction<Object> func = (NullaryFunction) new RecursiveEvaluation(new RecFunc(0, true)).evaluate();
- assertEquals(new Integer(5), func.evaluate());
+ assertEquals(Integer.valueOf(5), func.evaluate());
}
@Test
@@ -77,7 +77,7 @@
if (returnFunc) {
return new InnerNullaryFunction(times);
} else {
- return new Integer(times);
+ return Integer.valueOf(times);
}
}
}
@@ -109,7 +109,7 @@
}
public Object evaluate() {
- return new Integer(times);
+ return Integer.valueOf(times);
}
@Override
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java
index 12ee536..b131c56 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java
@@ -41,10 +41,10 @@
public void setUp() throws Exception {
list = new ArrayList<Integer>();
evens = new ArrayList<Integer>();
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- if (i%2 == 0) {
- evens.add(new Integer(i));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ if (i % 2 == 0) {
+ evens.add(Integer.valueOf(i));
}
}
}
@@ -65,8 +65,8 @@
@Test
public void testRemove() {
- new RemoveMatching<Integer>().run(list.iterator(),isOdd);
- assertEquals(evens,list);
+ new RemoveMatching<Integer>().run(list.iterator(), isOdd);
+ assertEquals(evens, list);
}
// Attributes
@@ -84,7 +84,7 @@
static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
- return new Integer(2*obj);
+ return Integer.valueOf(2 * obj);
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java
index 25f4cb5..6c7f651 100644
--- a/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java
+++ b/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java
@@ -41,10 +41,10 @@
public void setUp() throws Exception {
list = new ArrayList<Integer>();
odds = new ArrayList<Integer>();
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- if (i%2 != 0) {
- odds.add(new Integer(i));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ if (i % 2 != 0) {
+ odds.add(Integer.valueOf(i));
}
}
}
@@ -65,8 +65,8 @@
@Test
public void testRemove() {
- new RetainMatching<Integer>().run(list.iterator(),isOdd);
- assertEquals(odds,list);
+ new RetainMatching<Integer>().run(list.iterator(), isOdd);
+ assertEquals(odds, list);
}
// Attributes
@@ -84,7 +84,7 @@
static class Doubler implements Function<Integer, Integer> {
public Integer evaluate(Integer obj) {
- return new Integer(2*obj);
+ return Integer.valueOf(2 * obj);
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
index 2df1ecc..01e6412 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java
@@ -43,17 +43,17 @@
public Object makeFunctor() {
List<String> list = new ArrayList<String>();
list.add("xyzzy");
- return FilteredIterator.filter(list.iterator(),Constant.truePredicate());
+ return FilteredIterator.filter(list.iterator(), Constant.truePredicate());
}
@Before
public void setUp() throws Exception {
list = new ArrayList<Integer>();
evens = new ArrayList<Integer>();
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- if (i%2 == 0) {
- evens.add(new Integer(i));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ if (i % 2 == 0) {
+ evens.add(Integer.valueOf(i));
}
}
}
@@ -70,10 +70,10 @@
@Test
public void testSomePass() {
Iterator<Integer> expected = evens.iterator();
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),isEven);
- while(expected.hasNext()) {
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), isEven);
+ while (expected.hasNext()) {
assertTrue(testing.hasNext());
- assertEquals(expected.next(),testing.next());
+ assertEquals(expected.next(), testing.next());
}
assertTrue(!testing.hasNext());
}
@@ -81,10 +81,10 @@
@Test
public void testAllPass() {
Iterator<Integer> expected = list.iterator();
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),Constant.truePredicate());
- while(expected.hasNext()) {
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), Constant.truePredicate());
+ while (expected.hasNext()) {
assertTrue(testing.hasNext());
- assertEquals(expected.next(),testing.next());
+ assertEquals(expected.next(), testing.next());
}
assertTrue(!testing.hasNext());
}
@@ -92,61 +92,62 @@
@Test
public void testAllPass2() {
Iterator<Integer> expected = list.iterator();
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),Constant.truePredicate());
- while(expected.hasNext()) {
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), Constant.truePredicate());
+ while (expected.hasNext()) {
assertTrue(testing.hasNext());
- assertEquals(expected.next(),testing.next());
+ assertEquals(expected.next(), testing.next());
}
assertTrue(!testing.hasNext());
}
@Test
public void testEmptyList() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(new ArrayList<Integer>().iterator(),isEven);
+ Iterator<Integer> testing = new FilteredIterator<Integer>(new ArrayList<Integer>().iterator(), isEven);
assertTrue(!testing.hasNext());
}
@Test
public void testNonePass() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(new ArrayList<Integer>().iterator(),Constant.falsePredicate());
+ Iterator<Integer> testing =
+ new FilteredIterator<Integer>(new ArrayList<Integer>().iterator(), Constant.falsePredicate());
assertTrue(!testing.hasNext());
}
@Test
public void testNextWithoutHasNext() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),isEven);
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), isEven);
Iterator<Integer> expected = evens.iterator();
- while(expected.hasNext()) {
- assertEquals(expected.next(),testing.next());
+ while (expected.hasNext()) {
+ assertEquals(expected.next(), testing.next());
}
assertTrue(!(testing.hasNext()));
}
- @Test(expected=NoSuchElementException.class)
+ @Test(expected = NoSuchElementException.class)
public void testNextAfterEndOfList() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),isEven);
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), isEven);
Iterator<Integer> expected = evens.iterator();
- while(expected.hasNext()) {
- assertEquals(expected.next(),testing.next());
+ while (expected.hasNext()) {
+ assertEquals(expected.next(), testing.next());
}
testing.next();
}
- @Test(expected=NoSuchElementException.class)
+ @Test(expected = NoSuchElementException.class)
public void testNextOnEmptyList() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(new ArrayList<Integer>().iterator(),isEven);
+ Iterator<Integer> testing = new FilteredIterator<Integer>(new ArrayList<Integer>().iterator(), isEven);
testing.next();
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testRemoveBeforeNext() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),isEven);
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), isEven);
testing.remove();
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testRemoveAfterNext() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),isEven);
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), isEven);
testing.next();
testing.remove();
testing.remove();
@@ -154,20 +155,20 @@
@Test
public void testRemoveSome() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),isEven);
- while(testing.hasNext()) {
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), isEven);
+ while (testing.hasNext()) {
testing.next();
testing.remove();
}
for (Iterator<Integer> iter = list.iterator(); iter.hasNext();) {
- assertTrue(! isEven.test(iter.next()) );
+ assertTrue(!isEven.test(iter.next()));
}
}
@Test
public void testRemoveAll() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),Constant.truePredicate());
- while(testing.hasNext()) {
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), Constant.truePredicate());
+ while (testing.hasNext()) {
testing.next();
testing.remove();
}
@@ -176,8 +177,8 @@
@Test
public void testRemoveWithoutHasNext() {
- Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(),Constant.truePredicate());
- for (int i=0,m = list.size();i<m;i++) {
+ Iterator<Integer> testing = new FilteredIterator<Integer>(list.iterator(), Constant.truePredicate());
+ for (int i = 0, m = list.size(); i < m; i++) {
testing.next();
testing.remove();
}
@@ -186,30 +187,30 @@
@Test
public void testFilterWithNullIteratorReturnsNull() {
- assertNull(FilteredIterator.filter(null,Constant.truePredicate()));
+ assertNull(FilteredIterator.filter(null, Constant.truePredicate()));
}
@Test
public void testFilterWithNullPredicateReturnsIdentity() {
Iterator<Integer> iter = list.iterator();
- assertSame(iter,FilteredIterator.filter(iter,null));
+ assertSame(iter, FilteredIterator.filter(iter, null));
}
@Test(expected = NullPointerException.class)
public void testConstructorProhibitsNull() {
- new FilteredIterator<Integer>(null,null);
+ new FilteredIterator<Integer>(null, null);
}
@Test(expected = NullPointerException.class)
public void testConstructorProhibitsNull2() {
- new FilteredIterator<Integer>(null,Constant.truePredicate());
+ new FilteredIterator<Integer>(null, Constant.truePredicate());
}
@Test(expected = NullPointerException.class)
public void testConstructorProhibitsNull3() {
- new FilteredIterator<Integer>(list.iterator(),null);
+ new FilteredIterator<Integer>(list.iterator(), null);
}
-
+
@Test
public void testEquals() {
Iterator<Integer> iter = list.iterator();
@@ -224,7 +225,7 @@
return obj.intValue() % 2 != 0;
}
};
- assertEquals(t,new FilteredIterator<Integer>(iter, isEven));
+ assertEquals(t, new FilteredIterator<Integer>(iter, isEven));
assertTrue(!t.equals(new FilteredIterator<Integer>(list.iterator(), isOdd)));
assertTrue(!t.equals(new FilteredIterator<Float>(Arrays.asList(0.0f, 0.1f).iterator(), isOddFloat)));
assertTrue(!t.equals(null));
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
index 675e379..52435d3 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsElementOf.java
@@ -48,17 +48,17 @@
@Test
public void testTestCollection() throws Exception {
List<Integer> list = new ArrayList<Integer>();
- list.add(new Integer(5));
- list.add(new Integer(10));
- list.add(new Integer(15));
+ list.add(Integer.valueOf(5));
+ list.add(Integer.valueOf(10));
+ list.add(Integer.valueOf(15));
Predicate<Integer> p = IsElementOf.instance(list);
- assertTrue(p.test(new Integer(5)));
- assertTrue(p.test(new Integer(10)));
- assertTrue(p.test(new Integer(15)));
+ assertTrue(p.test(Integer.valueOf(5)));
+ assertTrue(p.test(Integer.valueOf(10)));
+ assertTrue(p.test(Integer.valueOf(15)));
- assertTrue(!p.test(new Integer(4)));
- assertTrue(!p.test(new Integer(11)));
+ assertTrue(!p.test(Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(11)));
}
@@ -67,19 +67,19 @@
int[] list = new int[] { 5, 10, 15 };
Predicate<Integer> p = IsElementOf.instance(list);
- assertTrue(p.test(new Integer(5)));
- assertTrue(p.test(new Integer(10)));
- assertTrue(p.test(new Integer(15)));
+ assertTrue(p.test(Integer.valueOf(5)));
+ assertTrue(p.test(Integer.valueOf(10)));
+ assertTrue(p.test(Integer.valueOf(15)));
- assertTrue(!p.test(new Integer(4)));
- assertTrue(!p.test(new Integer(11)));
+ assertTrue(!p.test(Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(11)));
}
@Test
public void testTestArrayWithNull() throws Exception {
assertTrue(! IsElementOf.instance().test(null,new int[] { 5, 10, 15 }));
- assertTrue(IsElementOf.instance().test(null,new Integer[] { new Integer(5), null, new Integer(15) }));
- assertTrue(IsElementOf.instance().test(new Integer(15),new Integer[] { new Integer(5), null, new Integer(15) }));
+ assertTrue(IsElementOf.instance().test(null,new Integer[] { Integer.valueOf(5), null, Integer.valueOf(15) }));
+ assertTrue(IsElementOf.instance().test(Integer.valueOf(15),new Integer[] { Integer.valueOf(5), null, Integer.valueOf(15) }));
}
@Test
@@ -95,7 +95,7 @@
@Test
public void testWrapNonCollection() {
try {
- IsElementOf.instance(new Integer(3));
+ IsElementOf.instance(Integer.valueOf(3));
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
@@ -104,13 +104,13 @@
@Test(expected = NullPointerException.class)
public void testTestNull() {
- IsElementOf.instance().test(new Integer(5),null);
+ IsElementOf.instance().test(Integer.valueOf(5),null);
}
@Test
public void testTestNonCollection() {
try {
- IsElementOf.instance().test(new Integer(5),new Long(5));
+ IsElementOf.instance().test(Integer.valueOf(5),Long.valueOf(5));
fail("expected IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
index 2db23c9..7a4f49f 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestIsEmpty.java
@@ -75,24 +75,24 @@
@Test
public void testTestNonCollection() throws Exception {
try {
- IsEmpty.instance().test(new Integer(3));
+ IsEmpty.instance().test(Integer.valueOf(3));
fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
// expected
}
}
@Test
public void testTestArray() throws Exception {
- assertTrue(! IsEmpty.instance().test(new int[10]));
- assertTrue(! IsEmpty.instance().test(new Object[10]));
+ assertTrue(!IsEmpty.instance().test(new int[10]));
+ assertTrue(!IsEmpty.instance().test(new Object[10]));
assertTrue(IsEmpty.instance().test(new int[0]));
assertTrue(IsEmpty.instance().test(new Object[0]));
}
@Test
public void testTestString() throws Exception {
- assertTrue(! IsEmpty.instance().test("xyzzy"));
+ assertTrue(!IsEmpty.instance().test("xyzzy"));
assertTrue(IsEmpty.instance().test(""));
}
@@ -100,17 +100,17 @@
public void testTestMap() throws Exception {
Map<String, String> map = new HashMap<String, String>();
assertTrue(IsEmpty.instance().test(map));
- map.put("x","y");
- assertTrue(! IsEmpty.instance().test(map));
+ map.put("x", "y");
+ assertTrue(!IsEmpty.instance().test(map));
}
@Test
public void testEquals() throws Exception {
Predicate<String> p = new IsEmpty<String>();
- assertEquals(p,p);
- assertObjectsAreEqual(p,new IsEmpty<Long>());
- assertObjectsAreEqual(p,IsEmpty.instance());
- assertObjectsAreNotEqual(p,new Constant<Boolean>(Boolean.TRUE));
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new IsEmpty<Long>());
+ assertObjectsAreEqual(p, IsEmpty.instance());
+ assertObjectsAreNotEqual(p, new Constant<Boolean>(Boolean.TRUE));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
index 297cc13..2904e21 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestSize.java
@@ -50,24 +50,24 @@
@Test
public void testEvaluate() throws Exception {
- assertEquals(new Integer(0),Size.instance().evaluate(Collections.EMPTY_LIST));
- assertEquals(new Integer(0),Size.instance().evaluate(Collections.EMPTY_SET));
+ assertEquals(Integer.valueOf(0), Size.instance().evaluate(Collections.EMPTY_LIST));
+ assertEquals(Integer.valueOf(0), Size.instance().evaluate(Collections.EMPTY_SET));
{
List<Integer> list = new ArrayList<Integer>();
- assertEquals(new Integer(0),Size.instance().evaluate(list));
- for (int i=0;i<2;i++) {
- assertEquals(new Integer(i),Size.instance().evaluate(list));
- list.add(new Integer(i));
- assertEquals(new Integer(i+1),Size.instance().evaluate(list));
+ assertEquals(Integer.valueOf(0), Size.instance().evaluate(list));
+ for (int i = 0; i < 2; i++) {
+ assertEquals(Integer.valueOf(i), Size.instance().evaluate(list));
+ list.add(Integer.valueOf(i));
+ assertEquals(Integer.valueOf(i + 1), Size.instance().evaluate(list));
}
}
{
Set<Integer> set = new HashSet<Integer>();
- assertEquals(new Integer(0),Size.instance().evaluate(set));
- for (int i=0;i<2;i++) {
- assertEquals(new Integer(i),Size.instance().evaluate(set));
- set.add(new Integer(i));
- assertEquals(new Integer(i+1),Size.instance().evaluate(set));
+ assertEquals(Integer.valueOf(0), Size.instance().evaluate(set));
+ for (int i = 0; i < 2; i++) {
+ assertEquals(Integer.valueOf(i), Size.instance().evaluate(set));
+ set.add(Integer.valueOf(i));
+ assertEquals(Integer.valueOf(i + 1), Size.instance().evaluate(set));
}
}
}
@@ -80,33 +80,33 @@
@Test
public void testEvaluateNonCollection() throws Exception {
try {
- Size.instance().evaluate(new Integer(3));
+ Size.instance().evaluate(Integer.valueOf(3));
fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
// expected
}
}
@Test
public void testEvaluateArray() throws Exception {
- assertEquals(new Integer(10),Size.instance().evaluate(new int[10]));
- assertEquals(new Integer(7),Size.instance().evaluate(new String[7]));
+ assertEquals(Integer.valueOf(10), Size.instance().evaluate(new int[10]));
+ assertEquals(Integer.valueOf(7), Size.instance().evaluate(new String[7]));
}
@Test
public void testEvaluateString() throws Exception {
- assertEquals(new Integer("xyzzy".length()),Size.instance().evaluate("xyzzy"));
+ assertEquals(Integer.valueOf("xyzzy".length()), Size.instance().evaluate("xyzzy"));
}
@Test
public void testEquals() throws Exception {
Function<Object, Integer> f = new Size<Object>();
- assertEquals(f,f);
- assertObjectsAreEqual(f,new Size<Object>());
- assertObjectsAreEqual(f,Size.instance());
- assertSame(Size.instance(),Size.instance());
- assertObjectsAreNotEqual(f,new Constant<Object>(null));
- assertTrue(! f.equals((Size<?>) null) );
+ assertEquals(f, f);
+ assertObjectsAreEqual(f, new Size<Object>());
+ assertObjectsAreEqual(f, Size.instance());
+ assertSame(Size.instance(), Size.instance());
+ assertObjectsAreNotEqual(f, new Constant<Object>(null));
+ assertTrue(!f.equals((Size<?>) null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java b/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
index 1c61866..ddc5e02 100644
--- a/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
@@ -45,7 +45,7 @@
public Object makeFunctor() {
List<String> list1 = new ArrayList<String>();
list1.add("xyzzy");
- return TransformedIterator.transform(list1.iterator(),Identity.instance());
+ return TransformedIterator.transform(list1.iterator(), Identity.instance());
}
// Lifecycle
@@ -55,9 +55,9 @@
public void setUp() throws Exception {
list = new ArrayList<Integer>();
negatives = new ArrayList<Integer>();
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- negatives.add(new Integer(i*-1));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ negatives.add(Integer.valueOf(i * -1));
}
}
@@ -73,55 +73,57 @@
@Test
public void testBasicTransform() {
Iterator<Integer> expected = negatives.iterator();
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
- while(expected.hasNext()) {
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
+ while (expected.hasNext()) {
assertTrue(testing.hasNext());
- assertEquals(expected.next(),testing.next());
+ assertEquals(expected.next(), testing.next());
}
assertTrue(!testing.hasNext());
}
@Test
public void testEmptyList() {
- Iterator<?> testing = new TransformedIterator<Integer, Integer>(Collections.<Integer>emptyList().iterator(),negate);
+ Iterator<?> testing =
+ new TransformedIterator<Integer, Integer>(Collections.<Integer> emptyList().iterator(), negate);
assertTrue(!testing.hasNext());
}
@Test
public void testNextWithoutHasNext() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
Iterator<Integer> expected = negatives.iterator();
- while(expected.hasNext()) {
- assertEquals(expected.next(),testing.next());
+ while (expected.hasNext()) {
+ assertEquals(expected.next(), testing.next());
}
assertTrue(!(testing.hasNext()));
}
- @Test(expected=NoSuchElementException.class)
+ @Test(expected = NoSuchElementException.class)
public void testNextAfterEndOfList() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
Iterator<Integer> expected = negatives.iterator();
- while(expected.hasNext()) {
- assertEquals(expected.next(),testing.next());
+ while (expected.hasNext()) {
+ assertEquals(expected.next(), testing.next());
}
testing.next();
}
- @Test(expected=NoSuchElementException.class)
+ @Test(expected = NoSuchElementException.class)
public void testNextOnEmptyList() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(Collections.<Integer>emptyList().iterator(),negate);
+ Iterator<Integer> testing =
+ new TransformedIterator<Integer, Integer>(Collections.<Integer> emptyList().iterator(), negate);
testing.next();
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testRemoveBeforeNext() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
testing.remove();
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testRemoveAfterNext() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
testing.next();
testing.remove();
testing.remove();
@@ -129,8 +131,8 @@
@Test
public void testRemoveAll() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
- while(testing.hasNext()) {
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
+ while (testing.hasNext()) {
testing.next();
testing.remove();
}
@@ -139,8 +141,8 @@
@Test
public void testRemoveWithoutHasNext() {
- Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(),negate);
- for (int i=0,m = list.size();i<m;i++) {
+ Iterator<Integer> testing = new TransformedIterator<Integer, Integer>(list.iterator(), negate);
+ for (int i = 0, m = list.size(); i < m; i++) {
testing.next();
testing.remove();
}
@@ -149,24 +151,24 @@
@Test
public void testTransformWithNullIteratorReturnsNull() {
- assertNull(TransformedIterator.transform(null,negate));
+ assertNull(TransformedIterator.transform(null, negate));
}
@Test
public void testTransformWithNullFunctionReturnsIdentity() {
Iterator<Integer> iter = list.iterator();
- assertSame(iter,TransformedIterator.maybeTransform(iter,null));
+ assertSame(iter, TransformedIterator.maybeTransform(iter, null));
}
@Test
public void testTransformWithNullIteratorAndNullFunctionReturnsNull() {
- assertSame(null,TransformedIterator.maybeTransform(null,null));
+ assertSame(null, TransformedIterator.maybeTransform(null, null));
}
@Test
public void testTransform() {
Iterator<Integer> iter = list.iterator();
- assertNotSame(iter,TransformedIterator.maybeTransform(iter, negate));
+ assertNotSame(iter, TransformedIterator.maybeTransform(iter, negate));
}
@Test(expected = NullPointerException.class)
@@ -190,10 +192,10 @@
TransformedIterator<Integer, Integer> t = new TransformedIterator<Integer, Integer>(iter, negate);
Function<Number, Double> negateDouble = new Function<Number, Double>() {
public Double evaluate(Number obj) {
- return new Double(obj.intValue() * -1);
- }
+ return Double.valueOf(obj.intValue() * -1);
+ }
};
- assertEquals(t,new TransformedIterator<Integer, Integer>(iter, negate));
+ assertEquals(t, new TransformedIterator<Integer, Integer>(iter, negate));
assertTrue(!t.equals(new TransformedIterator<Integer, Double>(list.iterator(), negateDouble)));
assertTrue(!t.equals(new TransformedIterator<Float, Integer>(Arrays.asList(0.0f, 0.1f).iterator(), negate)));
assertTrue(!t.equals(null));
@@ -205,7 +207,7 @@
private List<Integer> negatives = null;
private Function<Number, Integer> negate = new Function<Number, Integer>() {
public Integer evaluate(Number obj) {
- return new Integer(obj.intValue() * -1);
+ return Integer.valueOf(obj.intValue() * -1);
}
};
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java b/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java
index cbad942..1ac1fed 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java
@@ -33,23 +33,23 @@
@Test
public final void testTestNull() throws Exception {
@SuppressWarnings("unchecked")
- BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>)(makeFunctor());
+ BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>) (makeFunctor());
try {
- p.test(new Integer(2),null);
+ p.test(Integer.valueOf(2), null);
fail("Expected NullPointerException");
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
// expected
}
try {
- p.test(null,new Integer(2));
+ p.test(null, Integer.valueOf(2));
fail("Expected NullPointerException");
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
// expected
}
try {
- p.test(null,null);
+ p.test(null, null);
fail("Expected NullPointerException");
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
// expected
}
}
@@ -57,23 +57,23 @@
@Test
public final void testTestNonComparable() throws Exception {
@SuppressWarnings("unchecked")
- BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>)(makeFunctor());
+ BinaryPredicate<Object, Object> p = (BinaryPredicate<Object, Object>) (makeFunctor());
try {
- p.test(new Integer(2),new Object());
+ p.test(Integer.valueOf(2), new Object());
fail("Expected ClassCastException");
- } catch(ClassCastException e) {
+ } catch (ClassCastException e) {
// expected
}
try {
- p.test(new Object(),new Integer(2));
+ p.test(new Object(), Integer.valueOf(2));
fail("Expected ClassCastException");
- } catch(ClassCastException e) {
+ } catch (ClassCastException e) {
// expected
}
try {
- p.test(new Object(),new Object());
+ p.test(new Object(), new Object());
fail("Expected ClassCastException");
- } catch(ClassCastException e) {
+ } catch (ClassCastException e) {
// expected
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java
index bdeb139..f6c991e 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java
@@ -31,22 +31,24 @@
@Test
public void testCompareIntegers() {
- assertTrue(ComparableComparator.<Integer>instance().compare(new Integer(Integer.MIN_VALUE),new Integer(Integer.MIN_VALUE)) == 0);
- assertTrue(ComparableComparator.<Integer>instance().compare(new Integer(-1),new Integer(-1)) == 0);
- assertTrue(ComparableComparator.<Integer>instance().compare(new Integer(0),new Integer(0)) == 0);
- assertTrue(ComparableComparator.<Integer>instance().compare(new Integer(Integer.MAX_VALUE),new Integer(Integer.MAX_VALUE)) == 0);
- assertTrue(ComparableComparator.<Integer>instance().compare(new Integer(1),new Integer(1)) == 0);
+ assertTrue(ComparableComparator.<Integer> instance().compare(Integer.valueOf(Integer.MIN_VALUE),
+ Integer.valueOf(Integer.MIN_VALUE)) == 0);
+ assertTrue(ComparableComparator.<Integer> instance().compare(Integer.valueOf(-1), Integer.valueOf(-1)) == 0);
+ assertTrue(ComparableComparator.<Integer> instance().compare(Integer.valueOf(0), Integer.valueOf(0)) == 0);
+ assertTrue(ComparableComparator.<Integer> instance().compare(Integer.valueOf(Integer.MAX_VALUE),
+ Integer.valueOf(Integer.MAX_VALUE)) == 0);
+ assertTrue(ComparableComparator.<Integer> instance().compare(Integer.valueOf(1), Integer.valueOf(1)) == 0);
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void testCompareNull() {
- ComparableComparator.<Integer>instance().compare(null,new Integer(2));
+ ComparableComparator.<Integer> instance().compare(null, Integer.valueOf(2));
}
@Test
public void testEqualsAndHashCode() {
- assertEquals(new ComparableComparator<Integer>(),new ComparableComparator<Integer>());
- assertEquals(new ComparableComparator<Integer>().hashCode(),new ComparableComparator<Integer>().hashCode());
+ assertEquals(new ComparableComparator<Integer>(), new ComparableComparator<Integer>());
+ assertEquals(new ComparableComparator<Integer>().hashCode(), new ComparableComparator<Integer>().hashCode());
assertTrue(!new ComparableComparator<Integer>().equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
index baf425c..10e1029 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
@@ -41,45 +41,45 @@
@Test
public void testEvaluate() {
- ComparatorFunction<Integer> f = ComparatorFunction.<Integer>instance();
+ ComparatorFunction<Integer> f = ComparatorFunction.<Integer> instance();
- assertTrue((f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(Integer.MAX_VALUE))).intValue() == 0);
- assertTrue((f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(1))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(0))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(-1))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(Integer.MIN_VALUE))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(Integer.MAX_VALUE))).intValue() == 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(1))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(0))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(-1))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MAX_VALUE), Integer.valueOf(Integer.MIN_VALUE))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(1),new Integer(Integer.MAX_VALUE))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(1),new Integer(1))).intValue() == 0);
- assertTrue((f.evaluate(new Integer(1),new Integer(0))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(1),new Integer(-1))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(1),new Integer(Integer.MIN_VALUE))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(1), Integer.valueOf(Integer.MAX_VALUE))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(1), Integer.valueOf(1))).intValue() == 0);
+ assertTrue((f.evaluate(Integer.valueOf(1), Integer.valueOf(0))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(1), Integer.valueOf(-1))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(1), Integer.valueOf(Integer.MIN_VALUE))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(0),new Integer(Integer.MAX_VALUE))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(0),new Integer(1))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(0),new Integer(0))).intValue() == 0);
- assertTrue((f.evaluate(new Integer(0),new Integer(-1))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(0),new Integer(Integer.MIN_VALUE))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(0), Integer.valueOf(Integer.MAX_VALUE))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(0), Integer.valueOf(1))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(0), Integer.valueOf(0))).intValue() == 0);
+ assertTrue((f.evaluate(Integer.valueOf(0), Integer.valueOf(-1))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(0), Integer.valueOf(Integer.MIN_VALUE))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(-1),new Integer(Integer.MAX_VALUE))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(-1),new Integer(1))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(-1),new Integer(0))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(-1),new Integer(-1))).intValue() == 0);
- assertTrue((f.evaluate(new Integer(-1),new Integer(Integer.MIN_VALUE))).intValue() > 0);
+ assertTrue((f.evaluate(Integer.valueOf(-1), Integer.valueOf(Integer.MAX_VALUE))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(-1), Integer.valueOf(1))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(-1), Integer.valueOf(0))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(-1), Integer.valueOf(-1))).intValue() == 0);
+ assertTrue((f.evaluate(Integer.valueOf(-1), Integer.valueOf(Integer.MIN_VALUE))).intValue() > 0);
- assertTrue((f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(Integer.MAX_VALUE))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(1))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(0))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(-1))).intValue() < 0);
- assertTrue((f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(Integer.MIN_VALUE))).intValue() == 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MIN_VALUE), Integer.valueOf(Integer.MAX_VALUE))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MIN_VALUE), Integer.valueOf(1))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MIN_VALUE), Integer.valueOf(0))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MIN_VALUE), Integer.valueOf(-1))).intValue() < 0);
+ assertTrue((f.evaluate(Integer.valueOf(Integer.MIN_VALUE), Integer.valueOf(Integer.MIN_VALUE))).intValue() == 0);
}
@Test
public void testEquals() {
ComparatorFunction<Comparable<?>> f = ComparatorFunction.instance();
- assertObjectsAreEqual(f,f);
- assertObjectsAreEqual(f,new ComparatorFunction<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreNotEqual(f,new ComparatorFunction<Boolean>(Collections.reverseOrder()));
+ assertObjectsAreEqual(f, f);
+ assertObjectsAreEqual(f, new ComparatorFunction<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreNotEqual(f, new ComparatorFunction<Boolean>(Collections.reverseOrder()));
assertTrue(!f.equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java
index b46ccce..fad151f 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java
@@ -41,12 +41,12 @@
@Test
public void testTest() throws Exception {
- IsEquivalent<Integer> p = IsEquivalent.<Integer>instance();
- assertTrue(!p.test(new Integer(2),new Integer(4)));
- assertTrue(!p.test(new Integer(3),new Integer(4)));
- assertTrue(p.test(new Integer(4),new Integer(4)));
- assertTrue(!p.test(new Integer(5),new Integer(4)));
- assertTrue(!p.test(new Integer(6),new Integer(4)));
+ IsEquivalent<Integer> p = IsEquivalent.<Integer> instance();
+ assertTrue(!p.test(Integer.valueOf(2), Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(4), Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(5), Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(6), Integer.valueOf(4)));
}
@Test
@@ -58,11 +58,11 @@
@Test
public void testEquals() throws Exception {
IsEquivalent<Comparable<Integer>> p = IsEquivalent.instance();
- assertEquals(p,p);
+ assertEquals(p, p);
- assertObjectsAreEqual(p,new IsEquivalent<Comparable<?>>());
- assertObjectsAreEqual(p,new IsEquivalent<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreNotEqual(p,Constant.FALSE);
+ assertObjectsAreEqual(p, new IsEquivalent<Comparable<?>>());
+ assertObjectsAreEqual(p, new IsEquivalent<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreNotEqual(p, Constant.FALSE);
assertFalse(p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java
index 7d67958..28edb14 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java
@@ -42,28 +42,28 @@
@Test
public void testTest() throws Exception {
IsGreaterThan<Integer> p = new IsGreaterThan<Integer>();
- assertFalse(p.test(new Integer(2),new Integer(4)));
- assertFalse(p.test(new Integer(3),new Integer(4)));
- assertFalse(p.test(new Integer(4),new Integer(4)));
- assertTrue(p.test(new Integer(5),new Integer(4)));
- assertTrue(p.test(new Integer(6),new Integer(4)));
+ assertFalse(p.test(Integer.valueOf(2), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(4), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(5), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(6), Integer.valueOf(4)));
}
@Test
public void testInstance() {
- assertTrue(IsGreaterThan.instance(new Integer(7)).test(new Integer(8)));
- assertTrue(! IsGreaterThan.instance(new Integer(7)).test(new Integer(6)));
+ assertTrue(IsGreaterThan.instance(Integer.valueOf(7)).test(Integer.valueOf(8)));
+ assertTrue(!IsGreaterThan.instance(Integer.valueOf(7)).test(Integer.valueOf(6)));
}
@Test
public void testEquals() throws Exception {
IsGreaterThan<Comparable<?>> p = new IsGreaterThan<Comparable<?>>();
- assertEquals(p,p);
+ assertEquals(p, p);
- assertObjectsAreEqual(p,new IsGreaterThan<Comparable<?>>());
- assertObjectsAreEqual(p,new IsGreaterThan<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreEqual(p,IsGreaterThan.instance());
- assertObjectsAreNotEqual(p,Constant.FALSE);
+ assertObjectsAreEqual(p, new IsGreaterThan<Comparable<?>>());
+ assertObjectsAreEqual(p, new IsGreaterThan<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreEqual(p, IsGreaterThan.instance());
+ assertObjectsAreNotEqual(p, Constant.FALSE);
assertFalse(p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java
index 3e1ef6a..05f2281 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java
@@ -42,28 +42,28 @@
@Test
public void testTest() throws Exception {
IsGreaterThanOrEqual<Integer> p = new IsGreaterThanOrEqual<Integer>();
- assertFalse(p.test(new Integer(2),new Integer(4)));
- assertFalse(p.test(new Integer(3),new Integer(4)));
- assertTrue(p.test(new Integer(4),new Integer(4)));
- assertTrue(p.test(new Integer(5),new Integer(4)));
- assertTrue(p.test(new Integer(6),new Integer(4)));
+ assertFalse(p.test(Integer.valueOf(2), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(4), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(5), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(6), Integer.valueOf(4)));
}
@Test
public void testInstance() {
- assertTrue(IsGreaterThanOrEqual.instance(new Integer(7)).test(new Integer(8)));
- assertTrue(! IsGreaterThanOrEqual.instance(new Integer(7)).test(new Integer(6)));
+ assertTrue(IsGreaterThanOrEqual.instance(Integer.valueOf(7)).test(Integer.valueOf(8)));
+ assertTrue(!IsGreaterThanOrEqual.instance(Integer.valueOf(7)).test(Integer.valueOf(6)));
}
@Test
public void testEquals() throws Exception {
IsGreaterThanOrEqual<Comparable<?>> p = new IsGreaterThanOrEqual<Comparable<?>>();
- assertEquals(p,p);
+ assertEquals(p, p);
- assertObjectsAreEqual(p,new IsGreaterThanOrEqual<Comparable<?>>());
- assertObjectsAreEqual(p,new IsGreaterThanOrEqual<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreEqual(p,IsGreaterThanOrEqual.instance());
- assertObjectsAreNotEqual(p,Constant.FALSE);
+ assertObjectsAreEqual(p, new IsGreaterThanOrEqual<Comparable<?>>());
+ assertObjectsAreEqual(p, new IsGreaterThanOrEqual<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreEqual(p, IsGreaterThanOrEqual.instance());
+ assertObjectsAreNotEqual(p, Constant.FALSE);
assertFalse(p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java
index ff0dfe8..ae1aa1d 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java
@@ -42,28 +42,28 @@
@Test
public void testTest() throws Exception {
IsLessThan<Integer> p = new IsLessThan<Integer>();
- assertTrue(p.test(new Integer(2),new Integer(4)));
- assertTrue(p.test(new Integer(3),new Integer(4)));
- assertFalse(p.test(new Integer(4),new Integer(4)));
- assertFalse(p.test(new Integer(5),new Integer(4)));
- assertFalse(p.test(new Integer(6),new Integer(4)));
+ assertTrue(p.test(Integer.valueOf(2), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(4), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(5), Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(6), Integer.valueOf(4)));
}
@Test
public void testInstance() {
- assertFalse(IsLessThan.instance(new Integer(7)).test(new Integer(8)));
- assertTrue(IsLessThan.instance(new Integer(7)).test(new Integer(6)));
+ assertFalse(IsLessThan.instance(Integer.valueOf(7)).test(Integer.valueOf(8)));
+ assertTrue(IsLessThan.instance(Integer.valueOf(7)).test(Integer.valueOf(6)));
}
@Test
public void testEquals() throws Exception {
IsLessThan<Comparable<?>> p = new IsLessThan<Comparable<?>>();
- assertEquals(p,p);
+ assertEquals(p, p);
- assertObjectsAreEqual(p,new IsLessThan<Comparable<?>>());
- assertObjectsAreEqual(p,new IsLessThan<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreEqual(p,IsLessThan.instance());
- assertObjectsAreNotEqual(p,Constant.FALSE);
+ assertObjectsAreEqual(p, new IsLessThan<Comparable<?>>());
+ assertObjectsAreEqual(p, new IsLessThan<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreEqual(p, IsLessThan.instance());
+ assertObjectsAreNotEqual(p, Constant.FALSE);
assertFalse(p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java
index 1e47a38..40a40a0 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java
@@ -42,17 +42,17 @@
@Test
public void testTest() throws Exception {
IsLessThanOrEqual<Integer> p = new IsLessThanOrEqual<Integer>();
- assertTrue(p.test(new Integer(2),new Integer(4)));
- assertTrue(p.test(new Integer(3),new Integer(4)));
- assertTrue(p.test(new Integer(4),new Integer(4)));
- assertFalse(p.test(new Integer(5),new Integer(4)));
- assertFalse(p.test(new Integer(6),new Integer(4)));
+ assertTrue(p.test(Integer.valueOf(2),Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(3),Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(4),Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(5),Integer.valueOf(4)));
+ assertFalse(p.test(Integer.valueOf(6),Integer.valueOf(4)));
}
@Test
public void testInstance() {
- assertFalse(IsLessThanOrEqual.instance(new Integer(7)).test(new Integer(8)));
- assertTrue(IsLessThanOrEqual.instance(new Integer(7)).test(new Integer(6)));
+ assertFalse(IsLessThanOrEqual.instance(Integer.valueOf(7)).test(Integer.valueOf(8)));
+ assertTrue(IsLessThanOrEqual.instance(Integer.valueOf(7)).test(Integer.valueOf(6)));
}
@Test
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java
index fdf011a..0da5bc1 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java
@@ -42,27 +42,27 @@
@Test
public void testTest() throws Exception {
IsNotEquivalent<Integer> p = new IsNotEquivalent<Integer>();
- assertTrue(p.test(new Integer(2),new Integer(4)));
- assertTrue(p.test(new Integer(3),new Integer(4)));
- assertTrue(!p.test(new Integer(4),new Integer(4)));
- assertTrue(p.test(new Integer(5),new Integer(4)));
- assertTrue(p.test(new Integer(6),new Integer(4)));
+ assertTrue(p.test(Integer.valueOf(2), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(3), Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(4), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(5), Integer.valueOf(4)));
+ assertTrue(p.test(Integer.valueOf(6), Integer.valueOf(4)));
}
@Test
public void testInstance() {
- assertTrue(! IsNotEquivalent.instance(new Integer(7)).test(new Integer(7)));
- assertTrue(IsNotEquivalent.instance(new Integer(7)).test(new Integer(8)));
+ assertTrue(!IsNotEquivalent.instance(Integer.valueOf(7)).test(Integer.valueOf(7)));
+ assertTrue(IsNotEquivalent.instance(Integer.valueOf(7)).test(Integer.valueOf(8)));
}
@Test
public void testEquals() throws Exception {
IsNotEquivalent<Comparable<?>> p = new IsNotEquivalent<Comparable<?>>();
- assertEquals(p,p);
+ assertEquals(p, p);
- assertObjectsAreEqual(p,new IsNotEquivalent<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreEqual(p,IsNotEquivalent.instance());
- assertObjectsAreNotEqual(p,Constant.FALSE);
+ assertObjectsAreEqual(p, new IsNotEquivalent<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreEqual(p, IsNotEquivalent.instance());
+ assertObjectsAreNotEqual(p, Constant.FALSE);
assertFalse(p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
index 524fb43..c30cc11 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
@@ -32,7 +32,7 @@
@Override
protected Object makeFunctor() {
- return new IsWithinRange<Integer>(new Integer(5), new Integer(10));
+ return new IsWithinRange<Integer>(Integer.valueOf(5), Integer.valueOf(10));
}
// Tests
@@ -40,52 +40,50 @@
@Test
public void testTest() throws Exception {
- IsWithinRange<Integer> p = new IsWithinRange<Integer>(new Integer(5), new Integer(10));
- assertTrue(p.test(new Integer(5)));
- assertTrue(p.test(new Integer(6)));
- assertTrue(p.test(new Integer(7)));
- assertTrue(p.test(new Integer(8)));
- assertTrue(p.test(new Integer(9)));
- assertTrue(p.test(new Integer(10)));
+ IsWithinRange<Integer> p = new IsWithinRange<Integer>(Integer.valueOf(5), Integer.valueOf(10));
+ assertTrue(p.test(Integer.valueOf(5)));
+ assertTrue(p.test(Integer.valueOf(6)));
+ assertTrue(p.test(Integer.valueOf(7)));
+ assertTrue(p.test(Integer.valueOf(8)));
+ assertTrue(p.test(Integer.valueOf(9)));
+ assertTrue(p.test(Integer.valueOf(10)));
- assertTrue(!p.test(new Integer(4)));
- assertTrue(!p.test(new Integer(11)));
-
+ assertTrue(!p.test(Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(11)));
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidRange() {
- new IsWithinRange<Integer>(new Integer(5), new Integer(4));
+ new IsWithinRange<Integer>(Integer.valueOf(5), Integer.valueOf(4));
}
@Test(expected = NullPointerException.class)
public void testInvalidRange2() {
- new IsWithinRange<Integer>(new Integer(5), null);
+ new IsWithinRange<Integer>(Integer.valueOf(5), null);
}
@Test
public void testEquals() throws Exception {
- IsWithinRange<Integer> p1 = new IsWithinRange<Integer>(new Integer(5), new Integer(10));
- IsWithinRange<Integer> p2 = new IsWithinRange<Integer>(new Integer(5), new Integer(10));
+ IsWithinRange<Integer> p1 = new IsWithinRange<Integer>(Integer.valueOf(5), Integer.valueOf(10));
+ IsWithinRange<Integer> p2 = new IsWithinRange<Integer>(Integer.valueOf(5), Integer.valueOf(10));
assertEquals(p1, p2);
- p2 = new IsWithinRange<Integer>(new Integer(5), new Integer(11));
+ p2 = new IsWithinRange<Integer>(Integer.valueOf(5), Integer.valueOf(11));
assertTrue(!p1.equals(p2));
- p2 = new IsWithinRange<Integer>(new Integer(6), new Integer(10));
+ p2 = new IsWithinRange<Integer>(Integer.valueOf(6), Integer.valueOf(10));
assertTrue(!p1.equals(p2));
}
@Test
public void testFactory() throws Exception {
- IsWithinRange<Integer> p = IsWithinRange.instance(new Integer(5), new Integer(10));
- assertTrue(p.test(new Integer(5)));
- assertTrue(p.test(new Integer(6)));
- assertTrue(p.test(new Integer(7)));
- assertTrue(p.test(new Integer(8)));
- assertTrue(p.test(new Integer(9)));
- assertTrue(p.test(new Integer(10)));
+ IsWithinRange<Integer> p = IsWithinRange.instance(Integer.valueOf(5), Integer.valueOf(10));
+ assertTrue(p.test(Integer.valueOf(5)));
+ assertTrue(p.test(Integer.valueOf(6)));
+ assertTrue(p.test(Integer.valueOf(7)));
+ assertTrue(p.test(Integer.valueOf(8)));
+ assertTrue(p.test(Integer.valueOf(9)));
+ assertTrue(p.test(Integer.valueOf(10)));
- assertTrue(!p.test(new Integer(4)));
- assertTrue(!p.test(new Integer(11)));
-
+ assertTrue(!p.test(Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(11)));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
index abee5ad..6ffb747 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
@@ -38,11 +38,11 @@
return Max.instance();
}
- private Integer MIN = new Integer(Integer.MIN_VALUE);
- private Integer MINUS_TWO = new Integer(-2);
- private Integer ZERO = new Integer(0);
- private Integer ONE = new Integer(1);
- private Integer MAX = new Integer(Integer.MAX_VALUE);
+ private Integer MIN = Integer.valueOf(Integer.MIN_VALUE);
+ private Integer MINUS_TWO = Integer.valueOf(-2);
+ private Integer ZERO = Integer.valueOf(0);
+ private Integer ONE = Integer.valueOf(1);
+ private Integer MAX = Integer.valueOf(Integer.MAX_VALUE);
// Tests
// ------------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
index 3e63cd2..74ddcc2 100644
--- a/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
+++ b/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
@@ -38,38 +38,39 @@
return Min.instance();
}
- private Integer MIN = new Integer(Integer.MIN_VALUE);
- private Integer MINUS_TWO = new Integer(-2);
- private Integer ZERO = new Integer(0);
- private Integer ONE = new Integer(1);
- private Integer MAX = new Integer(Integer.MAX_VALUE);
+ private Integer MIN = Integer.valueOf(Integer.MIN_VALUE);
+ private Integer MINUS_TWO = Integer.valueOf(-2);
+ private Integer ZERO = Integer.valueOf(0);
+ private Integer ONE = Integer.valueOf(1);
+ private Integer MAX = Integer.valueOf(Integer.MAX_VALUE);
+
// Tests
// ------------------------------------------------------------------------
@Test
public void testEvaluate() {
Min<Integer> f = Min.instance();
- assertEquals(ONE,f.evaluate(ONE,ONE));
- assertEquals(ZERO,f.evaluate(ZERO,ONE));
- assertEquals(ZERO,f.evaluate(ONE,ZERO));
- assertEquals(ONE,f.evaluate(ONE,MAX));
- assertEquals(MIN,f.evaluate(MIN,MAX));
- assertEquals(MIN,f.evaluate(MIN,MINUS_TWO));
+ assertEquals(ONE, f.evaluate(ONE, ONE));
+ assertEquals(ZERO, f.evaluate(ZERO, ONE));
+ assertEquals(ZERO, f.evaluate(ONE, ZERO));
+ assertEquals(ONE, f.evaluate(ONE, MAX));
+ assertEquals(MIN, f.evaluate(MIN, MAX));
+ assertEquals(MIN, f.evaluate(MIN, MINUS_TWO));
}
@Test
public void testEquals() {
Min<Comparable<?>> f = Min.instance();
- assertObjectsAreEqual(f,f);
- assertObjectsAreEqual(f,Min.instance());
- assertObjectsAreEqual(f,new Min<Integer>(ComparableComparator.<Integer>instance()));
- assertObjectsAreNotEqual(f,new Min<Comparable<?>>(Collections.<Comparable<?>>reverseOrder()));
+ assertObjectsAreEqual(f, f);
+ assertObjectsAreEqual(f, Min.instance());
+ assertObjectsAreEqual(f, new Min<Integer>(ComparableComparator.<Integer> instance()));
+ assertObjectsAreNotEqual(f, new Min<Comparable<?>>(Collections.<Comparable<?>> reverseOrder()));
assertFalse(f.equals(null));
}
@Test
public void testFunctionMin() {
Function<Integer, Integer> min = Min.instance(ONE);
- assertEquals(ZERO,min.evaluate(ZERO));
+ assertEquals(ZERO, min.evaluate(ZERO));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java
index 432eb2a..edd03c5 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java
@@ -45,61 +45,63 @@
@Test
public void testTrue() throws Exception {
- assertTrue((new BinaryOr<Object, Object>(Constant.TRUE)).test("xyzzy",new Integer(3)));
- assertTrue((new BinaryOr<Object, Object>(Constant.FALSE,Constant.TRUE)).test("xyzzy",new Integer(3)));
- assertTrue((new BinaryOr<Object, Object>(Constant.FALSE, Constant.FALSE, Constant.TRUE)).test("xyzzy",new Integer(3)));
+ assertTrue((new BinaryOr<Object, Object>(Constant.TRUE)).test("xyzzy", Integer.valueOf(3)));
+ assertTrue((new BinaryOr<Object, Object>(Constant.FALSE, Constant.TRUE)).test("xyzzy", Integer.valueOf(3)));
+ assertTrue((new BinaryOr<Object, Object>(Constant.FALSE, Constant.FALSE, Constant.TRUE)).test("xyzzy",
+ Integer.valueOf(3)));
BinaryOr<Object, Object> p = new BinaryOr<Object, Object>(Constant.TRUE);
- assertTrue(p.test("xyzzy",new Integer(3)));
- for (int i=0;i<10;i++) {
- p.or(Constant.of(i%2==0));
- assertTrue(p.test("xyzzy",new Integer(3)));
+ assertTrue(p.test("xyzzy", Integer.valueOf(3)));
+ for (int i = 0; i < 10; i++) {
+ p.or(Constant.of(i % 2 == 0));
+ assertTrue(p.test("xyzzy", Integer.valueOf(3)));
}
BinaryOr<Object, Object> q = new BinaryOr<Object, Object>(Constant.TRUE);
- assertTrue(q.test("xyzzy",new Integer(3)));
- for (int i=0;i<10;i++) {
- q.or(Constant.of(i%2==0));
- assertTrue(q.test("xyzzy",new Integer(3)));
+ assertTrue(q.test("xyzzy", Integer.valueOf(3)));
+ for (int i = 0; i < 10; i++) {
+ q.or(Constant.of(i % 2 == 0));
+ assertTrue(q.test("xyzzy", Integer.valueOf(3)));
}
- BinaryOr<Object, Object> r = new BinaryOr<Object, Object>(p,q);
- assertTrue(r.test("xyzzy",new Integer(3)));
+ BinaryOr<Object, Object> r = new BinaryOr<Object, Object>(p, q);
+ assertTrue(r.test("xyzzy", Integer.valueOf(3)));
}
@Test
public void testFalse() throws Exception {
- assertTrue(!(new BinaryOr<Object, Object>()).test("xyzzy",new Integer(3)));
- assertTrue(!(new BinaryOr<Object, Object>(Constant.FALSE)).test("xyzzy",new Integer(3)));
- assertTrue(!(new BinaryOr<Object, Object>(Constant.FALSE,Constant.FALSE)).test("xyzzy",new Integer(3)));
- assertTrue(!(new BinaryOr<Object, Object>(Constant.FALSE,Constant.FALSE,Constant.FALSE)).test("xyzzy",new Integer(3)));
+ assertTrue(!(new BinaryOr<Object, Object>()).test("xyzzy", Integer.valueOf(3)));
+ assertTrue(!(new BinaryOr<Object, Object>(Constant.FALSE)).test("xyzzy", Integer.valueOf(3)));
+ assertTrue(!(new BinaryOr<Object, Object>(Constant.FALSE, Constant.FALSE)).test("xyzzy", Integer.valueOf(3)));
+ assertTrue(!(new BinaryOr<Object, Object>(Constant.FALSE, Constant.FALSE, Constant.FALSE)).test("xyzzy",
+ Integer.valueOf(3)));
BinaryOr<Object, Object> p = new BinaryOr<Object, Object>(Constant.FALSE);
- assertTrue(!p.test("xyzzy",new Integer(3)));
- for (int i=0;i<10;i++) {
+ assertTrue(!p.test("xyzzy", Integer.valueOf(3)));
+ for (int i = 0; i < 10; i++) {
p.or(Constant.FALSE);
- assertTrue(!p.test("xyzzy",new Integer(3)));
+ assertTrue(!p.test("xyzzy", Integer.valueOf(3)));
}
BinaryOr<Object, Object> q = new BinaryOr<Object, Object>(Constant.FALSE);
- assertTrue(!q.test("xyzzy",new Integer(3)));
- for (int i=0;i<10;i++) {
+ assertTrue(!q.test("xyzzy", Integer.valueOf(3)));
+ for (int i = 0; i < 10; i++) {
q.or(Constant.FALSE);
- assertTrue(!q.test("xyzzy",new Integer(3)));
+ assertTrue(!q.test("xyzzy", Integer.valueOf(3)));
}
- BinaryOr<Object, Object> r = new BinaryOr<Object, Object>(p,q);
- assertTrue(!r.test("xyzzy",new Integer(3)));
+ BinaryOr<Object, Object> r = new BinaryOr<Object, Object>(p, q);
+ assertTrue(!r.test("xyzzy", Integer.valueOf(3)));
}
@Test
public void testDuplicateAdd() throws Exception {
BinaryPredicate<Object, Object> p = Constant.TRUE;
- BinaryOr<Object, Object> q = new BinaryOr<Object, Object>(p,p);
- assertTrue(q.test("xyzzy",new Integer(3)));
- for (int i=0;i<10;i++) {
+ BinaryOr<Object, Object> q = new BinaryOr<Object, Object>(p, p);
+ assertTrue(q.test("xyzzy", Integer.valueOf(3)));
+ for (int i = 0; i < 10; i++) {
q.or(p);
- assertTrue(q.test("xyzzy",new Integer(3)));
+ assertTrue(q.test("xyzzy", Integer.valueOf(3)));
}
}
@@ -107,37 +109,37 @@
@Test
public void testEquals() throws Exception {
BinaryOr<Object, Object> p = new BinaryOr<Object, Object>();
- assertEquals(p,p);
+ assertEquals(p, p);
BinaryOr<Object, Object> q = new BinaryOr<Object, Object>();
- assertObjectsAreEqual(p,q);
+ assertObjectsAreEqual(p, q);
BinaryAnd<Object, Object> r = new BinaryAnd<Object, Object>();
- assertObjectsAreNotEqual(p,r);
+ assertObjectsAreNotEqual(p, r);
- for (int i=0;i<3;i++) {
+ for (int i = 0; i < 3; i++) {
p.or(Constant.TRUE);
- assertObjectsAreNotEqual(p,q);
+ assertObjectsAreNotEqual(p, q);
q.or(Constant.TRUE);
- assertObjectsAreEqual(p,q);
+ assertObjectsAreEqual(p, q);
r.and(Constant.TRUE);
- assertObjectsAreNotEqual(p,r);
+ assertObjectsAreNotEqual(p, r);
- p.or(new BinaryOr<Object, Object>(Constant.truePredicate(),Constant.FALSE));
- assertObjectsAreNotEqual(p,q);
- q.or(new BinaryOr<Object, Object>(Constant.truePredicate(),Constant.FALSE));
- assertObjectsAreEqual(p,q);
- r.and(new BinaryOr<Object, Object>(Constant.truePredicate(),Constant.FALSE));
- assertObjectsAreNotEqual(p,r);
+ p.or(new BinaryOr<Object, Object>(Constant.truePredicate(), Constant.FALSE));
+ assertObjectsAreNotEqual(p, q);
+ q.or(new BinaryOr<Object, Object>(Constant.truePredicate(), Constant.FALSE));
+ assertObjectsAreEqual(p, q);
+ r.and(new BinaryOr<Object, Object>(Constant.truePredicate(), Constant.FALSE));
+ assertObjectsAreNotEqual(p, r);
}
- assertObjectsAreNotEqual(p,Constant.TRUE);
- Iterable<BinaryPredicate<Object, Object>> iterable = Arrays.<BinaryPredicate<Object, Object>>asList(
- (BinaryPredicate<Object, Object>)Constant.truePredicate());
- assertObjectsAreNotEqual(p,new BinaryOr(iterable));
- assertObjectsAreNotEqual(p,new BinaryOr((Iterable<BinaryPredicate<Object, Object>>)null));
- assertObjectsAreNotEqual(p,new BinaryOr((BinaryPredicate<Object, Object>[])null));
- assertObjectsAreNotEqual(p,new BinaryOr((BinaryPredicate<Object, Object>)null));
+ assertObjectsAreNotEqual(p, Constant.TRUE);
+ Iterable<BinaryPredicate<Object, Object>> iterable =
+ Arrays.<BinaryPredicate<Object, Object>> asList((BinaryPredicate<Object, Object>) Constant.truePredicate());
+ assertObjectsAreNotEqual(p, new BinaryOr(iterable));
+ assertObjectsAreNotEqual(p, new BinaryOr((Iterable<BinaryPredicate<Object, Object>>) null));
+ assertObjectsAreNotEqual(p, new BinaryOr((BinaryPredicate<Object, Object>[]) null));
+ assertObjectsAreNotEqual(p, new BinaryOr((BinaryPredicate<Object, Object>) null));
assertTrue(!p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
index 42f4274..ad1b663 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
@@ -44,10 +44,10 @@
@Test
public void testEvaluate() throws Exception {
- assertEquals(new Integer(4),(new CompositeFunction<Object, Integer>(Constant.of(4))).evaluate(null));
+ assertEquals(Integer.valueOf(4),(new CompositeFunction<Object, Integer>(Constant.of(4))).evaluate(null));
- assertEquals(new Integer(4),(Composite.function(Constant.of(4)).of(Constant.of(3)).evaluate("xyzzy")));
- assertEquals(new Integer(3),(new CompositeFunction<Object, Integer>(Constant.of(3)).of(Constant.of(4)).evaluate("xyzzy")));
+ assertEquals(Integer.valueOf(4),(Composite.function(Constant.of(4)).of(Constant.of(3)).evaluate("xyzzy")));
+ assertEquals(Integer.valueOf(3),(new CompositeFunction<Object, Integer>(Constant.of(3)).of(Constant.of(4)).evaluate("xyzzy")));
}
@Test
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
index e83fc22..64f40ff 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
@@ -47,17 +47,17 @@
Predicate<Object> truePred = new Not<Object>(Constant.FALSE);
assertTrue(truePred.test(null));
assertTrue(truePred.test("xyzzy"));
- assertTrue(truePred.test(new Integer(3)));
+ assertTrue(truePred.test(Integer.valueOf(3)));
}
@Test
public void testEquals() throws Exception {
Not<Object> p = new Not<Object>(Constant.TRUE);
- assertEquals(p,p);
- assertObjectsAreEqual(p,new Not<Object>(Constant.TRUE));
- assertObjectsAreEqual(p,Not.not(Constant.TRUE));
- assertObjectsAreNotEqual(p,new Not<Object>(Constant.FALSE));
- assertObjectsAreNotEqual(p,Constant.TRUE);
+ assertEquals(p, p);
+ assertObjectsAreEqual(p, new Not<Object>(Constant.TRUE));
+ assertObjectsAreEqual(p, Not.not(Constant.TRUE));
+ assertObjectsAreNotEqual(p, new Not<Object>(Constant.FALSE));
+ assertObjectsAreNotEqual(p, Constant.TRUE);
assertTrue(!p.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
index dc66166..cfe4da8 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
@@ -26,18 +26,21 @@
/**
* Tests for TransformedNullaryFunction.
+ *
* @version $Revision: $ $Date: $
*/
public class TestTransformedNullaryFunction extends BaseFunctorTest {
private static class One implements NullaryFunction<Integer> {
public Integer evaluate() {
- return new Integer(1);
+ return Integer.valueOf(1);
}
+
@Override
public boolean equals(Object obj) {
return obj == this || obj != null && obj instanceof One;
}
+
@Override
public int hashCode() {
return "One".hashCode();
@@ -48,10 +51,12 @@
public Integer evaluate(Integer obj) {
return obj + 1;
}
+
@Override
public boolean equals(Object obj) {
return obj == this || obj != null && obj instanceof AddOne;
}
+
@Override
public int hashCode() {
return "AddOne".hashCode();
@@ -69,7 +74,7 @@
@Test
public void testRun() {
TransformedNullaryFunction<Integer> p = new TransformedNullaryFunction<Integer>(one, addOne);
- assertEquals(Integer.valueOf(2),p.evaluate());
+ assertEquals(Integer.valueOf(2), p.evaluate());
}
@Test
@@ -77,7 +82,7 @@
TransformedNullaryFunction<Integer> t = new TransformedNullaryFunction<Integer>(one, addOne);
NullaryFunction<Integer> f = new NullaryFunction<Integer>() {
public Integer evaluate() {
- return new Integer(2);
+ return Integer.valueOf(2);
}
};
Function<Integer, Integer> p = new Function<Integer, Integer>() {
@@ -85,10 +90,10 @@
return obj + 2;
}
};
- assertEquals(t,t);
- assertObjectsAreEqual(t,new TransformedNullaryFunction<Integer>(one, addOne));
- assertObjectsAreNotEqual(t,new TransformedNullaryFunction<Integer>(f, addOne));
- assertObjectsAreNotEqual(t,new TransformedNullaryFunction<Integer>(one, p));
+ assertEquals(t, t);
+ assertObjectsAreEqual(t, new TransformedNullaryFunction<Integer>(one, addOne));
+ assertObjectsAreNotEqual(t, new TransformedNullaryFunction<Integer>(f, addOne));
+ assertObjectsAreNotEqual(t, new TransformedNullaryFunction<Integer>(one, p));
assertTrue(!t.equals(null));
}
diff --git a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
index 8e26408..c0bcb9b 100644
--- a/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
+++ b/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
@@ -26,18 +26,21 @@
/**
* Tests for TransformedNullaryProcedure.
+ *
* @version $Revision: $ $Date: $
*/
-public class TestTransformedNullaryProcedure extends BaseFunctorTest{
+public class TestTransformedNullaryProcedure extends BaseFunctorTest {
private static class One implements NullaryFunction<Integer> {
public Integer evaluate() {
- return new Integer(1);
+ return Integer.valueOf(1);
}
+
@Override
public boolean equals(Object obj) {
return obj == this || obj != null && obj instanceof One;
}
+
@Override
public int hashCode() {
return "One".hashCode();
@@ -46,16 +49,20 @@
private static class AggregatorProcedure implements Procedure<Integer> {
private int total = 0;
+
public void run(Integer obj) {
total += obj;
}
+
public int getTotal() {
return total;
}
+
@Override
public boolean equals(Object obj) {
return obj == this || obj != null && obj instanceof AggregatorProcedure;
}
+
@Override
public int hashCode() {
return "AggregatorProcedure".hashCode();
@@ -74,7 +81,7 @@
public void testRun() {
TransformedNullaryProcedure p = new TransformedNullaryProcedure(one, aggregator);
p.run();
- assertEquals(1,aggregator.getTotal());
+ assertEquals(1, aggregator.getTotal());
}
@Test
@@ -82,7 +89,7 @@
TransformedNullaryProcedure t = new TransformedNullaryProcedure(one, aggregator);
NullaryFunction<Integer> f = new NullaryFunction<Integer>() {
public Integer evaluate() {
- return new Integer(2);
+ return Integer.valueOf(2);
}
};
Procedure<Integer> p = new Procedure<Integer>() {
@@ -90,10 +97,10 @@
// Do nothing
}
};
- assertEquals(t,t);
- assertObjectsAreEqual(t,new TransformedNullaryProcedure(one, aggregator));
- assertObjectsAreNotEqual(t,new TransformedNullaryProcedure(f, aggregator));
- assertObjectsAreNotEqual(t,new TransformedNullaryProcedure(one, p));
+ assertEquals(t, t);
+ assertObjectsAreEqual(t, new TransformedNullaryProcedure(one, aggregator));
+ assertObjectsAreNotEqual(t, new TransformedNullaryProcedure(f, aggregator));
+ assertObjectsAreNotEqual(t, new TransformedNullaryProcedure(one, p));
assertTrue(!t.equals(null));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java b/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
index 6e67e78..e57dd51 100644
--- a/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
@@ -63,14 +63,12 @@
public class FlexiMapExample {
/*
- * ----------------------------------------------------------------------------
- * UNIT TESTS:
+ * ---------------------------------------------------------------------------- UNIT TESTS:
* ----------------------------------------------------------------------------
*/
/*
- * In a "test first" style, let's first specify the Map behaviour we'd like
- * to implement via unit tests.
+ * In a "test first" style, let's first specify the Map behaviour we'd like to implement via unit tests.
*/
/*
@@ -85,65 +83,61 @@
/* (We'll define these make*Map functions below.) */
Map<Object, Object> map = makeBasicMap();
Object key = "key";
- Object value = new Integer(3);
- map.put(key,value);
- assertEquals(value, map.get(key) );
+ Object value = Integer.valueOf(3);
+ map.put(key, value);
+ assertEquals(value, map.get(key));
}
/*
- * If there is no value associated with a key,
- * the basic Map will return null for that key:
+ * If there is no value associated with a key, the basic Map will return null for that key:
*/
@Test
public void testBasicMapReturnsNullForMissingKey() {
Map<Object, Object> map = makeBasicMap();
- assertNull( map.get("key") );
+ assertNull(map.get("key"));
}
/*
- * One can also explicitly store a null value for
- * some key:
+ * One can also explicitly store a null value for some key:
*/
@Test
public void testBasicMapAllowsNull() {
Map<Object, Object> map = makeBasicMap();
Object key = "key";
Object value = null;
- map.put(key,value);
- assertNull( map.get(key) );
+ map.put(key, value);
+ assertNull(map.get(key));
}
/*
- * The basic Map deals with Objects--it can store keys
- * and values of multiple or differing types:
+ * The basic Map deals with Objects--it can store keys and values of multiple or differing types:
*/
@Test
public void testBasicMapAllowsMultipleTypes() {
Map<Object, Object> map = makeBasicMap();
- map.put("key-1","value-1");
- map.put(new Integer(2),"value-2");
- map.put("key-3",new Integer(3));
- map.put(new Integer(4),new Integer(4));
+ map.put("key-1", "value-1");
+ map.put(Integer.valueOf(2), "value-2");
+ map.put("key-3", Integer.valueOf(3));
+ map.put(Integer.valueOf(4), Integer.valueOf(4));
- assertEquals("value-1", map.get("key-1") );
- assertEquals("value-2", map.get(new Integer(2)) );
- assertEquals(new Integer(3), map.get("key-3") );
- assertEquals(new Integer(4), map.get(new Integer(4)) );
+ assertEquals("value-1", map.get("key-1"));
+ assertEquals("value-2", map.get(Integer.valueOf(2)));
+ assertEquals(Integer.valueOf(3), map.get("key-3"));
+ assertEquals(Integer.valueOf(4), map.get(Integer.valueOf(4)));
}
/*
- * Finally, note that putting a second value for a given
- * key will overwrite the first value--the basic Map only
+ * Finally, note that putting a second value for a given key will overwrite the first value--the basic Map only
* stores the most recently put value for each key:
*/
@Test
public void testBasicMapStoresOnlyOneValuePerKey() {
Map<Object, Object> map = makeBasicMap();
- assertNull( map.put("key","value-1") );
- assertEquals("value-1", map.get("key") );
- assertEquals("value-1", map.put("key","value-2"));
- assertEquals("value-2", map.get("key") );
+ assertNull(map.put("key", "value-1"));
+ assertEquals("value-1", map.get("key"));
+ assertEquals("value-1", map.put("key", "value-2"));
+ assertEquals("value-2", map.get("key"));
}
/*
@@ -151,69 +145,62 @@
*/
/*
- * One common specialization is to forbid null values,
- * like our old friend Hashtable:
+ * One common specialization is to forbid null values, like our old friend Hashtable:
*/
@Test
public void testForbidNull() {
Map<Object, Object> map = makeNullForbiddenMap();
- map.put("key","value");
- map.put("key2", new Integer(2) );
+ map.put("key", "value");
+ map.put("key2", Integer.valueOf(2));
try {
- map.put("key3",null);
+ map.put("key3", null);
fail("Expected NullPointerException");
- } catch(NullPointerException e) {
+ } catch (NullPointerException e) {
// expected
}
}
/*
- * Alternatively, we may want to provide a default
- * value to return when null is associated with some
- * key. (This might be useful, for example, when the Map
- * contains a counter--when there's no count yet, we'll
- * want to treat it as zero.):
+ * Alternatively, we may want to provide a default value to return when null is associated with some key. (This
+ * might be useful, for example, when the Map contains a counter--when there's no count yet, we'll want to treat it
+ * as zero.):
*/
@Test
public void testNullDefaultsToZero() {
- Map<Object, Object> map = makeDefaultValueForNullMap(new Integer(0));
+ Map<Object, Object> map = makeDefaultValueForNullMap(Integer.valueOf(0));
/*
* We expect 0 when no value has been associated with "key".
*/
- assertEquals( new Integer(0), map.get("key") );
+ assertEquals(Integer.valueOf(0), map.get("key"));
/*
* We also expect 0 when a null value has been associated with "key".
*/
map.put("key", null);
- assertEquals( new Integer(0), map.get("key") );
+ assertEquals(Integer.valueOf(0), map.get("key"));
}
/*
- * Another common specialization is to constrain the type of values
- * that may be stored in the Map:
+ * Another common specialization is to constrain the type of values that may be stored in the Map:
*/
@Test
public void testIntegerValuesOnly() {
Map<Object, Object> map = makeTypeConstrainedMap(Integer.class);
- map.put("key", new Integer(2));
- assertEquals( new Integer(2), map.get("key") );
+ map.put("key", Integer.valueOf(2));
+ assertEquals(Integer.valueOf(2), map.get("key"));
try {
- map.put("key2","value");
+ map.put("key2", "value");
fail("Expected ClassCastException");
- } catch(ClassCastException e) {
+ } catch (ClassCastException e) {
// expected
}
}
/*
- * A more interesting specialization is that used by the
- * Apache Commons Collections MultiMap class, which allows
- * one to associate multiple values with each key. The put
- * function still accepts a single value, but the get function
- * will return a Collection of values. Associating multiple values
- * with a key adds to that collection, rather than overwriting the
- * previous value:
+ * A more interesting specialization is that used by the Apache Commons Collections MultiMap class, which allows one
+ * to associate multiple values with each key. The put function still accepts a single value, but the get function
+ * will return a Collection of values. Associating multiple values with a key adds to that collection, rather than
+ * overwriting the previous value:
*/
@SuppressWarnings("unchecked")
@Test
@@ -223,16 +210,16 @@
map.put("key", "value 1");
{
- Collection<Object> result = (Collection<Object>)(map.get("key"));
- assertEquals(1,result.size());
+ Collection<Object> result = (Collection<Object>) (map.get("key"));
+ assertEquals(1, result.size());
assertEquals("value 1", result.iterator().next());
}
map.put("key", "value 2");
{
- Collection<Object> result = (Collection<Object>)(map.get("key"));
- assertEquals(2,result.size());
+ Collection<Object> result = (Collection<Object>) (map.get("key"));
+ assertEquals(2, result.size());
Iterator<Object> iter = result.iterator();
assertEquals("value 1", iter.next());
assertEquals("value 2", iter.next());
@@ -241,8 +228,8 @@
map.put("key", "value 3");
{
- Collection<Object> result = (Collection<Object>)(map.get("key"));
- assertEquals(3,result.size());
+ Collection<Object> result = (Collection<Object>) (map.get("key"));
+ assertEquals(3, result.size());
Iterator<Object> iter = result.iterator();
assertEquals("value 1", iter.next());
assertEquals("value 2", iter.next());
@@ -252,44 +239,37 @@
}
/*
- * Here's another variation on the MultiMap theme.
- * Rather than adding elements to a Collection, let's
- * concatenate String values together, delimited by commas.
- * (Such a Map might be used by the Commons Collection's
+ * Here's another variation on the MultiMap theme. Rather than adding elements to a Collection, let's concatenate
+ * String values together, delimited by commas. (Such a Map might be used by the Commons Collection's
* ExtendedProperties type.):
*/
@Test
public void testStringConcatMap() {
Map<Object, Object> map = makeStringConcatMap();
map.put("key", "value 1");
- assertEquals("value 1",map.get("key"));
+ assertEquals("value 1", map.get("key"));
map.put("key", "value 2");
- assertEquals("value 1, value 2",map.get("key"));
+ assertEquals("value 1, value 2", map.get("key"));
map.put("key", "value 3");
- assertEquals("value 1, value 2, value 3",map.get("key"));
+ assertEquals("value 1, value 2, value 3", map.get("key"));
}
/*
- * ----------------------------------------------------------------------------
- * THE GENERIC MAP IMPLEMENTATION:
+ * ---------------------------------------------------------------------------- THE GENERIC MAP IMPLEMENTATION:
* ----------------------------------------------------------------------------
*/
/*
- * How can one Map implementation support all these behaviors?
- * Using functors and composition, of course.
- *
- * In order to keep our example small, we'll just consider the
- * primary Map.put and Map.get methods here, although the remaining
- * Map methods could be handled similiarly.
+ * How can one Map implementation support all these behaviors? Using functors and composition, of course.
+ *
+ * In order to keep our example small, we'll just consider the primary Map.put and Map.get methods here, although
+ * the remaining Map methods could be handled similiarly.
*/
static class FlexiMap implements Map<Object, Object> {
/*
- * Our FlexiMap will accept two BinaryFunctions, one
- * that's used to transform objects being put into the Map,
- * and one that's used to transforms objects being retrieved
- * from the map.
+ * Our FlexiMap will accept two BinaryFunctions, one that's used to transform objects being put into the Map,
+ * and one that's used to transforms objects being retrieved from the map.
*/
public FlexiMap(BinaryFunction<Object, Object, Object> putfn, BinaryFunction<Object, Object, Object> getfn) {
onPut = null == putfn ? RightIdentity.function() : putfn;
@@ -297,34 +277,29 @@
proxiedMap = new HashMap<Object, Object>();
}
-
/*
- * The arguments to our "onGet" function will be the
- * key and the value associated with that key in the
- * underlying Map. We'll return whatever the function
- * returns.
+ * The arguments to our "onGet" function will be the key and the value associated with that key in the
+ * underlying Map. We'll return whatever the function returns.
*/
public Object get(Object key) {
- return onGet.evaluate( key, proxiedMap.get(key) );
+ return onGet.evaluate(key, proxiedMap.get(key));
}
/*
- * The arguments to our "onPut" function will be the
- * value previously associated with that key (if any),
- * as well as the new value being associated with that key.
- *
- * Since put returns the previously associated value,
- * we'll invoke onGet here as well.
+ * The arguments to our "onPut" function will be the value previously associated with that key (if any), as well
+ * as the new value being associated with that key.
+ *
+ * Since put returns the previously associated value, we'll invoke onGet here as well.
*/
public Object put(Object key, Object value) {
Object oldvalue = proxiedMap.get(key);
proxiedMap.put(key, onPut.evaluate(oldvalue, value));
- return onGet.evaluate(key,oldvalue);
+ return onGet.evaluate(key, oldvalue);
}
- /*
- * We'll skip the remaining Map methods for now.
- */
+ /*
+ * We'll skip the remaining Map methods for now.
+ */
public void clear() {
throw new UnsupportedOperationException("Left as an exercise for the reader.");
@@ -372,136 +347,113 @@
}
/*
- * ----------------------------------------------------------------------------
- * MAP SPECIALIZATIONS:
+ * ---------------------------------------------------------------------------- MAP SPECIALIZATIONS:
* ----------------------------------------------------------------------------
*/
/*
- * For the "basic" Map, we'll simply create a HashMap.
- * Note that using a RightIdentity for onPut and onGet
- * would yield the same behavior.
+ * For the "basic" Map, we'll simply create a HashMap. Note that using a RightIdentity for onPut and onGet would
+ * yield the same behavior.
*/
private Map<Object, Object> makeBasicMap() {
return new HashMap<Object, Object>();
}
/*
- * To prohibit null values, we'll only need to
- * provide an onPut function.
+ * To prohibit null values, we'll only need to provide an onPut function.
*/
private Map<Object, Object> makeNullForbiddenMap() {
return new FlexiMap(
- /*
- * We simply ignore the left-hand argument,
- */
- IgnoreLeftFunction.adapt(
- /*
- * and for the right-hand,
- */
- Conditional.function(
- /*
- * we'll test for null,
- */
- IsNull.instance(),
- /*
- * throwing a NullPointerException when the value is null,
- */
- throwNPE,
- /*
- * and passing through all non-null values.
- */
- Identity.instance()
- )
- ),
- null
- );
+ /*
+ * We simply ignore the left-hand argument,
+ */
+ IgnoreLeftFunction.adapt(
+ /*
+ * and for the right-hand,
+ */
+ Conditional.function(
+ /*
+ * we'll test for null,
+ */
+ IsNull.instance(),
+ /*
+ * throwing a NullPointerException when the value is null,
+ */
+ throwNPE,
+ /*
+ * and passing through all non-null values.
+ */
+ Identity.instance())), null);
}
/*
- * To provide a default for null values, we'll only need to
- * provide an onGet function, simliar to the onPut method used
- * above.
+ * To provide a default for null values, we'll only need to provide an onGet function, simliar to the onPut method
+ * used above.
*/
private Map<Object, Object> makeDefaultValueForNullMap(Object defaultValue) {
- return new FlexiMap(
- null,
- /*
- * We ignore the left-hand argument,
- */
- IgnoreLeftFunction.adapt(
- /*
- * and for the right-hand,
- */
- Conditional.function(
- /*
- * we'll test for null,
- */
- IsNull.instance(),
- /*
- * returning our default when the value is otherwise null,
- */
- new Constant<Object>(defaultValue),
- /*
- * and passing through all non-null values.
- */
- Identity.instance()
- )
- )
- );
+ return new FlexiMap(null,
+ /*
+ * We ignore the left-hand argument,
+ */
+ IgnoreLeftFunction.adapt(
+ /*
+ * and for the right-hand,
+ */
+ Conditional.function(
+ /*
+ * we'll test for null,
+ */
+ IsNull.instance(),
+ /*
+ * returning our default when the value is otherwise null,
+ */
+ new Constant<Object>(defaultValue),
+ /*
+ * and passing through all non-null values.
+ */
+ Identity.instance())));
}
/*
- * To constrain the value types, we'll
- * provide an onPut function,
+ * To constrain the value types, we'll provide an onPut function,
*/
private Map<Object, Object> makeTypeConstrainedMap(Class<?> clazz) {
return new FlexiMap(
- /*
- * ignore the left-hand argument,
- */
- IgnoreLeftFunction.adapt(
- Conditional.function(
- /*
- * we'll test the type of the right-hand argument,
- */
- IsInstance.of(clazz),
- /*
- * and either pass the given value through,
- */
- Identity.instance(),
- /*
- * or throw a ClassCastException.
- */
- throwCCE
- )
- ),
- null
- );
+ /*
+ * ignore the left-hand argument,
+ */
+ IgnoreLeftFunction.adapt(Conditional.function(
+ /*
+ * we'll test the type of the right-hand argument,
+ */
+ IsInstance.of(clazz),
+ /*
+ * and either pass the given value through,
+ */
+ Identity.instance(),
+ /*
+ * or throw a ClassCastException.
+ */
+ throwCCE)), null);
}
/*
- * The MultiMap is a bit more interesting, since we'll
- * need to consider both the old and new values during
- * onPut:
+ * The MultiMap is a bit more interesting, since we'll need to consider both the old and new values during onPut:
*/
private Map<Object, Object> makeMultiMap() {
- return new FlexiMap(
- new BinaryFunction<Object, Object, Object>() {
- @SuppressWarnings("unchecked")
- public Object evaluate(Object oldval, Object newval) {
- List<Object> list = null;
- if (null == oldval) {
- list = new ArrayList<Object>();
- } else {
- list = (List<Object>) oldval;
- }
- list.add(newval);
- return list;
+ return new FlexiMap(new BinaryFunction<Object, Object, Object>() {
+ @SuppressWarnings("unchecked")
+ public Object evaluate(Object oldval, Object newval) {
+ List<Object> list = null;
+ if (null == oldval) {
+ list = new ArrayList<Object>();
+ } else {
+ list = (List<Object>) oldval;
}
- },
- null
- );
+ list.add(newval);
+ return list;
+ }
+ }, null);
}
/*
@@ -509,65 +461,64 @@
*/
private Map<Object, Object> makeStringConcatMap() {
return new FlexiMap(
- /*
- * The onPut function looks similiar to the MultiMap
- * method:
- */
- new BinaryFunction<Object, Object, Object>() {
- public Object evaluate(Object oldval, Object newval) {
- StringBuffer buf = null;
- if (null == oldval) {
- buf = new StringBuffer();
- } else {
- buf = (StringBuffer) oldval;
- buf.append(", ");
- }
- buf.append(newval);
- return buf;
+ /*
+ * The onPut function looks similiar to the MultiMap method:
+ */
+ new BinaryFunction<Object, Object, Object>() {
+ public Object evaluate(Object oldval, Object newval) {
+ StringBuilder buf = null;
+ if (null == oldval) {
+ buf = new StringBuilder();
+ } else {
+ buf = (StringBuilder) oldval;
+ buf.append(", ");
}
- },
- /*
- * but we'll also need an onGet functor to convert
- * the StringBuffer to a String:
- */
- new BinaryFunction<Object, Object, Object>() {
- public Object evaluate(Object key, Object val) {
- if (null == val) {
- return null;
- } else {
- return ((StringBuffer) val).toString();
- }
+ buf.append(newval);
+ return buf;
+ }
+ },
+ /*
+ * but we'll also need an onGet functor to convert the StringBuilder to a String:
+ */
+ new BinaryFunction<Object, Object, Object>() {
+ public Object evaluate(Object key, Object val) {
+ if (null == val) {
+ return null;
+ } else {
+ return ((StringBuilder) val).toString();
}
}
- );
+ });
}
/*
- * (This "UniversalFunctor" type provides a functor
- * that takes the same action regardless of the number of
- * parameters. We used it above to throw Exceptions when
- * needed.)
+ * (This "UniversalFunctor" type provides a functor that takes the same action regardless of the number of
+ * parameters. We used it above to throw Exceptions when needed.)
*/
- private abstract class UniversalFunctor implements
- NullaryProcedure, Procedure<Object>, BinaryProcedure<Object, Object>,
- NullaryFunction<Object>, Function<Object, Object>, BinaryFunction<Object, Object, Object> {
+ private abstract class UniversalFunctor implements NullaryProcedure, Procedure<Object>,
+ BinaryProcedure<Object, Object>, NullaryFunction<Object>, Function<Object, Object>,
+ BinaryFunction<Object, Object, Object> {
public abstract void run();
public void run(Object obj) {
run();
}
+
public void run(Object left, Object right) {
run();
}
+
public Object evaluate() {
run();
return null;
}
+
public Object evaluate(Object obj) {
run();
return null;
}
+
public Object evaluate(Object left, Object right) {
run();
return null;
diff --git a/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java b/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
index b2a1e8f..5639398 100644
--- a/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/QuicksortExample.java
@@ -140,7 +140,7 @@
public void testSortSorted() {
List<Object> list = new ArrayList<Object>();
for (int i = 0; i < 10; i++) {
- list.add(new Integer(i));
+ list.add(Integer.valueOf(i));
}
List<?> sorted = quicksort(list);
@@ -167,11 +167,11 @@
/*
* The "expected" list contains the integers in order.
*/
- expected.add(new Integer(i));
+ expected.add(Integer.valueOf(i));
/*
* The "tosort" list contains the integers in reverse order.
*/
- tosort.add(new Integer(9 - i));
+ tosort.add(Integer.valueOf(9 - i));
}
assertEquals(expected, quicksort(tosort));
@@ -184,7 +184,7 @@
public void testSortShuffled() {
List<Object> expected = new ArrayList<Object>();
for (int i = 0; i < 10; i++) {
- expected.add(new Integer(i));
+ expected.add(Integer.valueOf(i));
}
List<Object> tosort = new ArrayList<Object>(expected);
Collections.shuffle(tosort);
@@ -203,7 +203,7 @@
*/
List<Integer> tosort = new ArrayList<Integer>();
for (int i = 0; i < 10; i++) {
- tosort.add(new Integer(random.nextInt(10)));
+ tosort.add(Integer.valueOf(random.nextInt(10)));
}
/*
* and use java.util.Collections.sort to
@@ -248,7 +248,7 @@
*/
List<Object> tosort = new ArrayList<Object>(SIZE);
for (int j = 0; j < SIZE; j++) {
- tosort.add(new Integer(random.nextInt(SIZE)));
+ tosort.add(Integer.valueOf(random.nextInt(SIZE)));
}
/*
@@ -535,14 +535,14 @@
public void testLesserTail() {
List<Integer> list = new ArrayList<Integer>();
for (int i=0;i<10;i++) {
- list.add(new Integer(i));
+ list.add(Integer.valueOf(i));
}
for (int i=0;i<10;i++) {
- Integer val = new Integer(i);
+ Integer val = Integer.valueOf(i);
List<Integer> lesser = (List<Integer>) lesserTail.evaluate(val,list);
assertEquals(i,lesser.size());
for (int j=0;j<i;j++) {
- assertEquals(new Integer(j),lesser.get(j));
+ assertEquals(Integer.valueOf(j),lesser.get(j));
}
}
}
@@ -550,14 +550,14 @@
public void testGreaterTail() {
List<Integer> list = new ArrayList<Integer>();
for (int i=0;i<10;i++) {
- list.add(new Integer(i));
+ list.add(Integer.valueOf(i));
}
for (int i=0;i<10;i++) {
- Integer val = new Integer(i);
+ Integer val = Integer.valueOf(i);
List<Integer> greater = (List<Integer>) greaterTail.evaluate(val,list);
assertEquals(10-i,greater.size());
for (int j=i;j<10;j++) {
- assertEquals(new Integer(j),greater.get(j-i));
+ assertEquals(Integer.valueOf(j),greater.get(j-i));
}
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java
index e941c8e..df1a9bb 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/Abs.java
@@ -27,7 +27,7 @@
public final class Abs implements Function<Number, Integer> {
public Integer evaluate(Number num) {
- return new Integer(Math.abs(num.intValue()));
+ return Integer.valueOf(Math.abs(num.intValue()));
}
public static final Abs instance() {
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java b/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java
index d840fff..194376c 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/four/ToInteger.java
@@ -19,19 +19,17 @@
import org.apache.commons.functor.Function;
/**
- * Converts a String value to an Integer, throwing
- * an exception if no such conversion can be made.
- *
- * Trailing, non-{@link Character#isDigit digit} characters
- * are ignored.
- *
+ * Converts a String value to an Integer, throwing an exception if no such conversion can be made.
+ *
+ * Trailing, non-{@link Character#isDigit digit} characters are ignored.
+ *
* @version $Revision$ $Date$
*/
public final class ToInteger implements Function<String, Integer> {
public Integer evaluate(String str) {
- StringBuffer buf = new StringBuffer();
- for (int i=0;i<str.length();i++) {
+ StringBuilder buf = new StringBuilder();
+ for (int i = 0; i < str.length(); i++) {
if (Character.isDigit(str.charAt(i))) {
buf.append(str.charAt(i));
} else {
@@ -39,8 +37,8 @@
}
}
try {
- return new Integer(buf.toString());
- } catch(NumberFormatException e) {
+ return Integer.valueOf(buf.toString());
+ } catch (NumberFormatException e) {
throw new NumberFormatException(str);
}
}
@@ -50,4 +48,4 @@
}
private static final ToInteger INSTANCE = new ToInteger();
-}
\ No newline at end of file
+}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java
index 06f9c73..38538da 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Add.java
@@ -24,7 +24,7 @@
*/
public class Add extends ArithmeticOperation {
public Number evaluate(Number left, Number right) {
- return new Integer(left.intValue() + right.intValue());
+ return Integer.valueOf(left.intValue() + right.intValue());
}
public static Add instance() {
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java
index e0320a8..51859da 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Divide.java
@@ -25,7 +25,7 @@
public class Divide extends ArithmeticOperation {
public Number evaluate(Number left, Number right) {
- return new Integer(left.intValue() / right.intValue());
+ return Integer.valueOf(left.intValue() / right.intValue());
}
public static Divide instance() {
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java
index 9e7858b..4bfd55c 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Mod.java
@@ -24,7 +24,7 @@
*/
public class Mod extends ArithmeticOperation {
public Number evaluate(Number left, Number right) {
- return new Integer(left.intValue() % right.intValue());
+ return Integer.valueOf(left.intValue() % right.intValue());
}
public static Mod instance() {
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java
index 8ccd6cd..4a1e9e6 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Multiply.java
@@ -25,7 +25,7 @@
public class Multiply extends ArithmeticOperation {
public Number evaluate(Number left, Number right) {
- return new Integer(left.intValue() * right.intValue());
+ return Integer.valueOf(left.intValue() * right.intValue());
}
public static Multiply instance() {
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java
index 865b22f..9fd8594 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/Subtract.java
@@ -24,7 +24,7 @@
*/
public class Subtract extends ArithmeticOperation {
public Number evaluate(Number left, Number right) {
- return new Integer(left.intValue() - right.intValue());
+ return Integer.valueOf(left.intValue() - right.intValue());
}
public static Subtract instance() {
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java b/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
index b56fa1e..6b3a539 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/one/SupermarketPricingExample.java
@@ -28,276 +28,223 @@
import org.junit.Test;
/**
- * Dave Thomas's Kata One asks us to think about how one might
- * implement pricing rules:
- *
- * "Some things in supermarkets have simple prices: this can of
- * beans costs $0.65. Other things have more complex prices.
- * For example:
- *
+ * Dave Thomas's Kata One asks us to think about how one might implement pricing rules:
+ *
+ * "Some things in supermarkets have simple prices: this can of beans costs $0.65. Other things have more complex
+ * prices. For example:
+ *
* o three for a dollar (so what?s the price if I buy 4, or 5?)
- *
+ *
* o $1.99/pound (so what does 4 ounces cost?)
- *
+ *
* o buy two, get one free (so does the third item have a price?)"
- *
- * Functors provide one approach to this sort of problem, and in
- * this example we'll demonstrate some simple cases.
- *
- * See http://pragprog.com/pragdave/Practices/Kata/KataOne.rdoc,v
- * for more information on this Kata.
- *
+ *
+ * Functors provide one approach to this sort of problem, and in this example we'll demonstrate some simple cases.
+ *
+ * See http://pragprog.com/pragdave/Practices/Kata/KataOne.rdoc,v for more information on this Kata.
+ *
* @version $Revision$ $Date$
*/
public class SupermarketPricingExample {
// tests
- //----------------------------------------------------------
+ // ----------------------------------------------------------
/*
- * The simplest form of pricing is simply a constant
- * rate. In Dave's example, a can of beans costs $0.65,
- * and n cans of beans cost n*0.65.
- *
- * This pricing rule simply multiplies the quantity by
- * a constant, e.g.:
- * ToMoney.from(Multiply.by(65))
- *
- * This case is so common, we may want to introduce a
- * special Product constructor to wrap up create the
- * functors for us.
+ * The simplest form of pricing is simply a constant rate. In Dave's example, a can of beans costs $0.65, and n cans
+ * of beans cost n*0.65.
+ *
+ * This pricing rule simply multiplies the quantity by a constant, e.g.: ToMoney.from(Multiply.by(65))
+ *
+ * This case is so common, we may want to introduce a special Product constructor to wrap up create the functors for
+ * us.
*/
@Test
public void testConstantPricePerUnit() throws Exception {
{
- Product beans = new Product(
- "Can of Beans",
- "SKU-0001",
- ToMoney.from(Multiply.by(65)));
+ Product beans = new Product("Can of Beans", "SKU-0001", ToMoney.from(Multiply.by(65)));
- assertEquals(new Money(0*65),beans.getPrice(0));
- assertEquals(new Money(1*65),beans.getPrice(1));
- assertEquals(new Money(2*65),beans.getPrice(2));
- assertEquals(new Money(3*65),beans.getPrice(3));
+ assertEquals(new Money(0 * 65), beans.getPrice(0));
+ assertEquals(new Money(1 * 65), beans.getPrice(1));
+ assertEquals(new Money(2 * 65), beans.getPrice(2));
+ assertEquals(new Money(3 * 65), beans.getPrice(3));
}
// or, using the speical constructor:
{
- Product beans = new Product(
- "Can of Beans",
- "SKU-0001",
- 65);
+ Product beans = new Product("Can of Beans", "SKU-0001", 65);
- assertEquals(new Money(0*65),beans.getPrice(0));
- assertEquals(new Money(1*65),beans.getPrice(1));
- assertEquals(new Money(2*65),beans.getPrice(2));
- assertEquals(new Money(3*65),beans.getPrice(3));
+ assertEquals(new Money(0 * 65), beans.getPrice(0));
+ assertEquals(new Money(1 * 65), beans.getPrice(1));
+ assertEquals(new Money(2 * 65), beans.getPrice(2));
+ assertEquals(new Money(3 * 65), beans.getPrice(3));
}
}
/*
- * A slighly more complicated example is a bulk
- * discount. For example, bananas may be
- * $0.33 cents each, or 4 for a dollar ($1.00).
- *
- * This rule is underspecified by itself, there are
- * at least two ways to interpret this pricing rule:
- *
- * a) the cost is $0.33 cents for 3 or fewer, $0.25
- * for 4 or more
- *
+ * A slighly more complicated example is a bulk discount. For example, bananas may be $0.33 cents each, or 4 for a
+ * dollar ($1.00).
+ *
+ * This rule is underspecified by itself, there are at least two ways to interpret this pricing rule:
+ *
+ * a) the cost is $0.33 cents for 3 or fewer, $0.25 for 4 or more
+ *
* or
- *
- * b) the cost is $1.00 for every group of 4, $0.33
- * each for anything left over
- *
- * although I think in practice, "4 for a dollar"
- * usually means the former and not the latter.
- *
+ *
+ * b) the cost is $1.00 for every group of 4, $0.33 each for anything left over
+ *
+ * although I think in practice, "4 for a dollar" usually means the former and not the latter.
+ *
* We can implement either:
*/
@Test
public void testFourForADollar_A() throws Exception {
- Product banana = new Product(
- "Banana",
- "SKU-0002",
- ToMoney.from(
- new ConditionalFunction<Integer, Number>(
- IsGreaterThan.instance(new Integer(3)),
- Multiply.by(25),
- Multiply.by(33))));
+ Product banana =
+ new Product("Banana", "SKU-0002", ToMoney.from(new ConditionalFunction<Integer, Number>(IsGreaterThan
+ .instance(Integer.valueOf(3)), Multiply.by(25), Multiply.by(33))));
- assertEquals(new Money(0*33),banana.getPrice(0));
- assertEquals(new Money(1*33),banana.getPrice(1));
- assertEquals(new Money(2*33),banana.getPrice(2));
- assertEquals(new Money(3*33),banana.getPrice(3));
- assertEquals(new Money(4*25),banana.getPrice(4));
- assertEquals(new Money(5*25),banana.getPrice(5));
- assertEquals(new Money(6*25),banana.getPrice(6));
- assertEquals(new Money(7*25),banana.getPrice(7));
- assertEquals(new Money(8*25),banana.getPrice(8));
+ assertEquals(new Money(0 * 33), banana.getPrice(0));
+ assertEquals(new Money(1 * 33), banana.getPrice(1));
+ assertEquals(new Money(2 * 33), banana.getPrice(2));
+ assertEquals(new Money(3 * 33), banana.getPrice(3));
+ assertEquals(new Money(4 * 25), banana.getPrice(4));
+ assertEquals(new Money(5 * 25), banana.getPrice(5));
+ assertEquals(new Money(6 * 25), banana.getPrice(6));
+ assertEquals(new Money(7 * 25), banana.getPrice(7));
+ assertEquals(new Money(8 * 25), banana.getPrice(8));
}
-
@Test
public void testFourForADollar_B() throws Exception {
- Product banana = new Product(
- "Banana",
- "SKU-0002",
- ToMoney.from(
- new BinaryFunctionFunction<Integer, Number>(
- new CompositeBinaryFunction<Integer, Integer, Number>(
- Add.instance(),
- Composite.function(
- Multiply.by(100),
- Divide.by(4)),
- Composite.function(
- Multiply.by(33),
- Mod.by(4))))));
- assertEquals(new Money(0*33+0*25),banana.getPrice(0));
- assertEquals(new Money(1*33+0*25),banana.getPrice(1));
- assertEquals(new Money(2*33+0*25),banana.getPrice(2));
- assertEquals(new Money(3*33+0*25),banana.getPrice(3));
- assertEquals(new Money(0*33+4*25),banana.getPrice(4));
- assertEquals(new Money(1*33+4*25),banana.getPrice(5));
- assertEquals(new Money(2*33+4*25),banana.getPrice(6));
- assertEquals(new Money(3*33+4*25),banana.getPrice(7));
- assertEquals(new Money(0*33+8*25),banana.getPrice(8));
+ Product banana =
+ new Product("Banana", "SKU-0002", ToMoney.from(new BinaryFunctionFunction<Integer, Number>(
+ new CompositeBinaryFunction<Integer, Integer, Number>(Add.instance(), Composite.function(
+ Multiply.by(100), Divide.by(4)), Composite.function(Multiply.by(33), Mod.by(4))))));
+ assertEquals(new Money(0 * 33 + 0 * 25), banana.getPrice(0));
+ assertEquals(new Money(1 * 33 + 0 * 25), banana.getPrice(1));
+ assertEquals(new Money(2 * 33 + 0 * 25), banana.getPrice(2));
+ assertEquals(new Money(3 * 33 + 0 * 25), banana.getPrice(3));
+ assertEquals(new Money(0 * 33 + 4 * 25), banana.getPrice(4));
+ assertEquals(new Money(1 * 33 + 4 * 25), banana.getPrice(5));
+ assertEquals(new Money(2 * 33 + 4 * 25), banana.getPrice(6));
+ assertEquals(new Money(3 * 33 + 4 * 25), banana.getPrice(7));
+ assertEquals(new Money(0 * 33 + 8 * 25), banana.getPrice(8));
}
-
/*
- * Another interesting pricing rule is
- * something like "buy 2, get 1 free".
- *
- * This may be implemented using a formula
- * like:
- * costPerUnit * (quantity - quantity / 2)
- *
+ * Another interesting pricing rule is something like "buy 2, get 1 free".
+ *
+ * This may be implemented using a formula like: costPerUnit * (quantity - quantity / 2)
+ *
* For example...
*/
@Test
public void testBuyTwoGetOneFree_1() throws Exception {
- Product apple = new Product(
- "Apple",
- "SKU-0003",
- ToMoney.from(
- Composite.function(Multiply.by(40),
- BinaryFunctionFunction.adapt(new CompositeBinaryFunction<Number, Number, Number>(Subtract.instance(),
- new Identity<Number>(),
- Divide.by(3))))));
+ Product apple =
+ new Product("Apple", "SKU-0003", ToMoney.from(Composite.function(Multiply.by(40), BinaryFunctionFunction
+ .adapt(new CompositeBinaryFunction<Number, Number, Number>(Subtract.instance(), new Identity<Number>(),
+ Divide.by(3))))));
- assertEquals(new Money(0*40),apple.getPrice(0));
- assertEquals(new Money(1*40),apple.getPrice(1));
- assertEquals(new Money(2*40),apple.getPrice(2));
- assertEquals(new Money(2*40),apple.getPrice(3));
- assertEquals(new Money(3*40),apple.getPrice(4));
- assertEquals(new Money(4*40),apple.getPrice(5));
- assertEquals(new Money(4*40),apple.getPrice(6));
- assertEquals(new Money(5*40),apple.getPrice(7));
- assertEquals(new Money(6*40),apple.getPrice(8));
- assertEquals(new Money(6*40),apple.getPrice(9));
- assertEquals(new Money(7*40),apple.getPrice(10));
+ assertEquals(new Money(0 * 40), apple.getPrice(0));
+ assertEquals(new Money(1 * 40), apple.getPrice(1));
+ assertEquals(new Money(2 * 40), apple.getPrice(2));
+ assertEquals(new Money(2 * 40), apple.getPrice(3));
+ assertEquals(new Money(3 * 40), apple.getPrice(4));
+ assertEquals(new Money(4 * 40), apple.getPrice(5));
+ assertEquals(new Money(4 * 40), apple.getPrice(6));
+ assertEquals(new Money(5 * 40), apple.getPrice(7));
+ assertEquals(new Money(6 * 40), apple.getPrice(8));
+ assertEquals(new Money(6 * 40), apple.getPrice(9));
+ assertEquals(new Money(7 * 40), apple.getPrice(10));
}
/*
- * ...but our pricing rule is starting to get ugly,
- * and we haven't even considered things
- * something like "buy 3, get 2 free", etc.
- *
- * Perhaps a special Function instance is in
- * order:
+ * ...but our pricing rule is starting to get ugly, and we haven't even considered things something like
+ * "buy 3, get 2 free", etc.
+ *
+ * Perhaps a special Function instance is in order:
*/
class BuyNGetMFree implements Function<Number, Number> {
- public BuyNGetMFree(int n, int m, int costPerUnit) {
- this.n = n;
- this.m = m;
- this.costPerUnit = costPerUnit;
- }
+ public BuyNGetMFree(int n, int m, int costPerUnit) {
+ this.n = n;
+ this.m = m;
+ this.costPerUnit = costPerUnit;
+ }
- public Number evaluate(Number num) {
- int quantity = num.intValue();
- int cost = 0;
+ public Number evaluate(Number num) {
+ int quantity = num.intValue();
+ int cost = 0;
- while(quantity >= n) {
- // buy n
- cost += n * costPerUnit;
- quantity -= n;
- // get m (or fewer) free
- quantity -= Math.min(quantity,m);
- }
- // buy less than n
- cost += quantity * costPerUnit;
+ while (quantity >= n) {
+ // buy n
+ cost += n * costPerUnit;
+ quantity -= n;
+ // get m (or fewer) free
+ quantity -= Math.min(quantity, m);
+ }
+ // buy less than n
+ cost += quantity * costPerUnit;
- return new Integer(cost);
- }
+ return Integer.valueOf(cost);
+ }
- private int n, m, costPerUnit;
- }
+ private int n, m, costPerUnit;
+ }
@Test
public void testBuyTwoGetOneFree_2() throws Exception {
- Product apple = new Product(
- "Apple",
- "SKU-0003",
- ToMoney.from(new BuyNGetMFree(2,1,40)));
+ Product apple = new Product("Apple", "SKU-0003", ToMoney.from(new BuyNGetMFree(2, 1, 40)));
- assertEquals(new Money(0*40),apple.getPrice(0));
- assertEquals(new Money(1*40),apple.getPrice(1));
- assertEquals(new Money(2*40),apple.getPrice(2));
- assertEquals(new Money(2*40),apple.getPrice(3));
- assertEquals(new Money(3*40),apple.getPrice(4));
- assertEquals(new Money(4*40),apple.getPrice(5));
- assertEquals(new Money(4*40),apple.getPrice(6));
- assertEquals(new Money(5*40),apple.getPrice(7));
- assertEquals(new Money(6*40),apple.getPrice(8));
- assertEquals(new Money(6*40),apple.getPrice(9));
- assertEquals(new Money(7*40),apple.getPrice(10));
+ assertEquals(new Money(0 * 40), apple.getPrice(0));
+ assertEquals(new Money(1 * 40), apple.getPrice(1));
+ assertEquals(new Money(2 * 40), apple.getPrice(2));
+ assertEquals(new Money(2 * 40), apple.getPrice(3));
+ assertEquals(new Money(3 * 40), apple.getPrice(4));
+ assertEquals(new Money(4 * 40), apple.getPrice(5));
+ assertEquals(new Money(4 * 40), apple.getPrice(6));
+ assertEquals(new Money(5 * 40), apple.getPrice(7));
+ assertEquals(new Money(6 * 40), apple.getPrice(8));
+ assertEquals(new Money(6 * 40), apple.getPrice(9));
+ assertEquals(new Money(7 * 40), apple.getPrice(10));
}
@Test
public void testBuyThreeGetTwoFree() throws Exception {
- Product apple = new Product(
- "Apple",
- "SKU-0003",
- ToMoney.from(new BuyNGetMFree(3,2,40)));
+ Product apple = new Product("Apple", "SKU-0003", ToMoney.from(new BuyNGetMFree(3, 2, 40)));
- assertEquals(new Money(0*40),apple.getPrice(0));
- assertEquals(new Money(1*40),apple.getPrice(1));
- assertEquals(new Money(2*40),apple.getPrice(2));
- assertEquals(new Money(3*40),apple.getPrice(3));
- assertEquals(new Money(3*40),apple.getPrice(4));
- assertEquals(new Money(3*40),apple.getPrice(5));
- assertEquals(new Money(4*40),apple.getPrice(6));
- assertEquals(new Money(5*40),apple.getPrice(7));
- assertEquals(new Money(6*40),apple.getPrice(8));
- assertEquals(new Money(6*40),apple.getPrice(9));
- assertEquals(new Money(6*40),apple.getPrice(10));
- assertEquals(new Money(7*40),apple.getPrice(11));
+ assertEquals(new Money(0 * 40), apple.getPrice(0));
+ assertEquals(new Money(1 * 40), apple.getPrice(1));
+ assertEquals(new Money(2 * 40), apple.getPrice(2));
+ assertEquals(new Money(3 * 40), apple.getPrice(3));
+ assertEquals(new Money(3 * 40), apple.getPrice(4));
+ assertEquals(new Money(3 * 40), apple.getPrice(5));
+ assertEquals(new Money(4 * 40), apple.getPrice(6));
+ assertEquals(new Money(5 * 40), apple.getPrice(7));
+ assertEquals(new Money(6 * 40), apple.getPrice(8));
+ assertEquals(new Money(6 * 40), apple.getPrice(9));
+ assertEquals(new Money(6 * 40), apple.getPrice(10));
+ assertEquals(new Money(7 * 40), apple.getPrice(11));
}
@Test
public void testBuyTwoGetFiveFree() throws Exception {
- Product apple = new Product(
- "Apple",
- "SKU-0003",
- ToMoney.from(new BuyNGetMFree(2,5,40)));
+ Product apple = new Product("Apple", "SKU-0003", ToMoney.from(new BuyNGetMFree(2, 5, 40)));
- assertEquals(new Money(0*40),apple.getPrice(0));
- assertEquals(new Money(1*40),apple.getPrice(1));
- assertEquals(new Money(2*40),apple.getPrice(2));
- assertEquals(new Money(2*40),apple.getPrice(3));
- assertEquals(new Money(2*40),apple.getPrice(4));
- assertEquals(new Money(2*40),apple.getPrice(5));
- assertEquals(new Money(2*40),apple.getPrice(6));
- assertEquals(new Money(2*40),apple.getPrice(7));
- assertEquals(new Money(3*40),apple.getPrice(8));
- assertEquals(new Money(4*40),apple.getPrice(9));
- assertEquals(new Money(4*40),apple.getPrice(10));
- assertEquals(new Money(4*40),apple.getPrice(11));
- assertEquals(new Money(4*40),apple.getPrice(12));
- assertEquals(new Money(4*40),apple.getPrice(13));
- assertEquals(new Money(4*40),apple.getPrice(14));
- assertEquals(new Money(5*40),apple.getPrice(15));
- }
+ assertEquals(new Money(0 * 40), apple.getPrice(0));
+ assertEquals(new Money(1 * 40), apple.getPrice(1));
+ assertEquals(new Money(2 * 40), apple.getPrice(2));
+ assertEquals(new Money(2 * 40), apple.getPrice(3));
+ assertEquals(new Money(2 * 40), apple.getPrice(4));
+ assertEquals(new Money(2 * 40), apple.getPrice(5));
+ assertEquals(new Money(2 * 40), apple.getPrice(6));
+ assertEquals(new Money(2 * 40), apple.getPrice(7));
+ assertEquals(new Money(3 * 40), apple.getPrice(8));
+ assertEquals(new Money(4 * 40), apple.getPrice(9));
+ assertEquals(new Money(4 * 40), apple.getPrice(10));
+ assertEquals(new Money(4 * 40), apple.getPrice(11));
+ assertEquals(new Money(4 * 40), apple.getPrice(12));
+ assertEquals(new Money(4 * 40), apple.getPrice(13));
+ assertEquals(new Money(4 * 40), apple.getPrice(14));
+ assertEquals(new Money(5 * 40), apple.getPrice(15));
+ }
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/two/BaseBinaryChop.java b/core/src/test/java/org/apache/commons/functor/example/kata/two/BaseBinaryChop.java
index 399b1ef..00bd01e 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/two/BaseBinaryChop.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/two/BaseBinaryChop.java
@@ -20,18 +20,17 @@
import java.util.List;
/**
- * See http://pragprog.com/pragdave/Practices/Kata/KataTwo.rdoc,v
- * for more information on this Kata.
- *
+ * See http://pragprog.com/pragdave/Practices/Kata/KataTwo.rdoc,v for more information on this Kata.
+ *
* @version $Revision$ $Date$
*/
public abstract class BaseBinaryChop implements BinaryChop {
public int find(int seeking, int[] in) {
Integer[] In = new Integer[in.length];
- for (int i=0;i<in.length;i++) {
- In[i] = new Integer(in[i]);
+ for (int i = 0; i < in.length; i++) {
+ In[i] = Integer.valueOf(in[i]);
}
- return find(new Integer(seeking), In);
+ return find(Integer.valueOf(seeking), In);
}
public int find(Integer seeking, Integer[] in) {
@@ -43,13 +42,13 @@
}
protected static boolean greaterThan(List<Integer> list, int index, Integer obj) {
- return compare(list,index,obj) > 0;
+ return compare(list, index, obj) > 0;
}
protected static boolean equals(List<Integer> list, int index, Integer obj) {
- return compare(list,index,obj) == 0;
+ return compare(list, index, obj) == 0;
}
- protected static final Integer NEGATIVE_ONE = new Integer(-1);
+ protected static final Integer NEGATIVE_ONE = Integer.valueOf(-1);
-}
\ No newline at end of file
+}
diff --git a/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java b/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
index b7b95a4..babddce 100644
--- a/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
+++ b/core/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java
@@ -107,10 +107,10 @@
final List<Integer> largeList =
IteratorToGeneratorAdapter.adapt(new IntegerRange(0, 100001)).to(new ArrayList<Integer>());
- assertEquals(-1, chopper.find(new Integer(-5), largeList));
- assertEquals(100000, chopper.find(new Integer(100000), largeList));
- assertEquals(0, chopper.find(new Integer(0), largeList));
- assertEquals(50000, chopper.find(new Integer(50000), largeList));
+ assertEquals(-1, chopper.find(Integer.valueOf(-5), largeList));
+ assertEquals(100000, chopper.find(Integer.valueOf(100000), largeList));
+ assertEquals(0, chopper.find(Integer.valueOf(0), largeList));
+ assertEquals(50000, chopper.find(Integer.valueOf(50000), largeList));
}
@@ -303,7 +303,7 @@
* at the end of the loop.
*/
public Object evaluate() {
- return new Integer(
+ return Integer.valueOf(
list.isEmpty() ?
-1 :
(BaseBinaryChop.equals(list,low,seeking) ? low : -1));
@@ -360,7 +360,7 @@
variant(new NullaryFunction<Object>() {
public Object evaluate() {
- return new Integer(high - low);
+ return Integer.valueOf(high - low);
}
});
@@ -459,7 +459,7 @@
return list.isEmpty() ?
BaseBinaryChop.NEGATIVE_ONE :
(BaseBinaryChop.equals(list,low,seeking) ?
- new Integer(low) :
+ Integer.valueOf(low) :
BaseBinaryChop.NEGATIVE_ONE);
}
}
@@ -527,7 +527,7 @@
return BaseBinaryChop.NEGATIVE_ONE;
} if (sublist.size() == 1) {
return (BaseBinaryChop.equals(sublist,0,seeking) ?
- new Integer(offset) :
+ Integer.valueOf(offset) :
BaseBinaryChop.NEGATIVE_ONE);
} else {
int mid = sublist.size() / 2;
diff --git a/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java b/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
index 1e159ad..1b9a8ea 100644
--- a/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
+++ b/core/src/test/java/org/apache/commons/functor/example/lines/TestLines.java
@@ -64,14 +64,14 @@
Object result = new FoldLeft<Integer>(Sum.instance()).evaluate(
new TransformedGenerator<String, Integer>(Lines.from(reader), new Size<String>()));
- assertEquals("Expected 990 characters",new Integer(990),result);
+ assertEquals("Expected 990 characters",Integer.valueOf(990),result);
}
public void testCountWords() throws Exception {
Object result = new FoldLeft<Integer>(Sum.instance()).evaluate(
new TransformedGenerator<String, Integer>(Lines.from(reader),WordCount.instance()));
- assertEquals("Expected 157 words",new Integer(157),result);
+ assertEquals("Expected 157 words",Integer.valueOf(157),result);
}
public void testCountLines() throws Exception {
@@ -88,7 +88,7 @@
new FilteredGenerator<String>(Lines.from(reader), Not.not(new StartsWith<String>("#"))), WordCount
.instance()));
- assertEquals("Expected 90 words",new Integer(90),result);
+ assertEquals("Expected 90 words",Integer.valueOf(90),result);
}
public void testCountCommentLines() throws Exception {
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java b/core/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java
index c3eea07..4d205bf 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/TestFixedSizeMap.java
@@ -23,7 +23,6 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
-
/**
* @version $Revision$ $Date$
*/
@@ -44,11 +43,11 @@
public void setUp() throws Exception {
super.setUp();
baseMap = new HashMap<Object, Object>();
- baseMap.put(new Integer(1),"one");
- baseMap.put(new Integer(2),"two");
- baseMap.put(new Integer(3),"three");
- baseMap.put(new Integer(4),"four");
- baseMap.put(new Integer(5),"five");
+ baseMap.put(Integer.valueOf(1), "one");
+ baseMap.put(Integer.valueOf(2), "two");
+ baseMap.put(Integer.valueOf(3), "three");
+ baseMap.put(Integer.valueOf(4), "four");
+ baseMap.put(Integer.valueOf(5), "five");
fixedMap = new FixedSizeMap<Object, Object>(baseMap);
}
@@ -64,66 +63,65 @@
public void testCantPutNewPair() {
try {
- fixedMap.put("xyzzy","xyzzy");
+ fixedMap.put("xyzzy", "xyzzy");
fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
// expected
}
}
public void testCantPutNewPairViaPutAll() {
Map<Object, Object> map = new HashMap<Object, Object>();
- map.put(new Integer(1),"uno");
- map.put("xyzzy","xyzzy");
- map.put(new Integer(2),"dos");
+ map.put(Integer.valueOf(1), "uno");
+ map.put("xyzzy", "xyzzy");
+ map.put(Integer.valueOf(2), "dos");
try {
fixedMap.putAll(map);
fail("Expected IllegalArgumentException");
- } catch(IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
// expected
}
- assertEquals("one",fixedMap.get(new Integer(1)));
- assertEquals("two",fixedMap.get(new Integer(2)));
+ assertEquals("one", fixedMap.get(Integer.valueOf(1)));
+ assertEquals("two", fixedMap.get(Integer.valueOf(2)));
}
public void testCantClear() {
try {
fixedMap.clear();
fail("Expected UnsupportedOperationException");
- } catch(UnsupportedOperationException e) {
+ } catch (UnsupportedOperationException e) {
// expected
}
}
public void testCantRemove() {
try {
- fixedMap.remove(new Integer(1));
+ fixedMap.remove(Integer.valueOf(1));
fail("Expected UnsupportedOperationException");
- } catch(UnsupportedOperationException e) {
+ } catch (UnsupportedOperationException e) {
// expected
}
}
public void testCanAssociateNewValueWithOldKey() {
- fixedMap.put(new Integer(1),"uno");
- assertEquals("uno",fixedMap.get(new Integer(1)));
- assertEquals("two",fixedMap.get(new Integer(2)));
- assertEquals("three",fixedMap.get(new Integer(3)));
+ fixedMap.put(Integer.valueOf(1), "uno");
+ assertEquals("uno", fixedMap.get(Integer.valueOf(1)));
+ assertEquals("two", fixedMap.get(Integer.valueOf(2)));
+ assertEquals("three", fixedMap.get(Integer.valueOf(3)));
}
public void testCanAssociateNewValueWithOldKeyViaPutAll() {
Map<Object, Object> map = new HashMap<Object, Object>();
- map.put(new Integer(1),"uno");
- map.put(new Integer(2),"dos");
+ map.put(Integer.valueOf(1), "uno");
+ map.put(Integer.valueOf(2), "dos");
fixedMap.putAll(map);
- assertEquals("uno",fixedMap.get(new Integer(1)));
- assertEquals("dos",fixedMap.get(new Integer(2)));
- assertEquals("three",fixedMap.get(new Integer(3)));
+ assertEquals("uno", fixedMap.get(Integer.valueOf(1)));
+ assertEquals("dos", fixedMap.get(Integer.valueOf(2)));
+ assertEquals("three", fixedMap.get(Integer.valueOf(3)));
}
-
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java b/core/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java
index 16807d5..fa62acb 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/TestLazyMap.java
@@ -26,7 +26,6 @@
import org.apache.commons.functor.core.collection.Size;
-
/**
* @version $Revision$ $Date$
*/
@@ -48,14 +47,14 @@
public void setUp() throws Exception {
super.setUp();
expectedMap = new HashMap<Object, Integer>();
- expectedMap.put("one",new Integer(3));
- expectedMap.put("two",new Integer(3));
- expectedMap.put("three", new Integer(5));
- expectedMap.put("four", new Integer(4));
- expectedMap.put("five", new Integer(4));
+ expectedMap.put("one", Integer.valueOf(3));
+ expectedMap.put("two", Integer.valueOf(3));
+ expectedMap.put("three", Integer.valueOf(5));
+ expectedMap.put("four", Integer.valueOf(4));
+ expectedMap.put("five", Integer.valueOf(4));
baseMap = new HashMap<Object, Integer>();
- lazyMap = new LazyMap<Object, Integer>(baseMap,Size.instance());
+ lazyMap = new LazyMap<Object, Integer>(baseMap, Size.instance());
}
@Override
@@ -73,32 +72,31 @@
Object key = iter.next();
assertFalse(baseMap.containsKey(key));
assertFalse(lazyMap.containsKey(key));
- assertEquals(expectedMap.get(key),lazyMap.get(key));
- assertEquals(expectedMap.get(key),baseMap.get(key));
+ assertEquals(expectedMap.get(key), lazyMap.get(key));
+ assertEquals(expectedMap.get(key), baseMap.get(key));
assertTrue(lazyMap.containsKey(key));
assertTrue(baseMap.containsKey(key));
}
- assertEquals(expectedMap,lazyMap);
- assertEquals(expectedMap,baseMap);
+ assertEquals(expectedMap, lazyMap);
+ assertEquals(expectedMap, baseMap);
baseMap.clear();
for (Iterator<Object> iter = expectedMap.keySet().iterator(); iter.hasNext();) {
Object key = iter.next();
assertFalse(baseMap.containsKey(key));
assertFalse(lazyMap.containsKey(key));
- assertEquals(expectedMap.get(key),lazyMap.get(key));
- assertEquals(expectedMap.get(key),baseMap.get(key));
+ assertEquals(expectedMap.get(key), lazyMap.get(key));
+ assertEquals(expectedMap.get(key), baseMap.get(key));
assertTrue(lazyMap.containsKey(key));
assertTrue(baseMap.containsKey(key));
}
- assertEquals(expectedMap,lazyMap);
- assertEquals(expectedMap,baseMap);
+ assertEquals(expectedMap, lazyMap);
+ assertEquals(expectedMap, baseMap);
}
-
public void testBaseMapOverrides() {
- assertEquals(new Integer(5),lazyMap.get("xyzzy"));
- baseMap.put("xyzzy",new Integer(3));
- assertEquals(Integer.valueOf(3),lazyMap.get("xyzzy"));
+ assertEquals(Integer.valueOf(5), lazyMap.get("xyzzy"));
+ baseMap.put("xyzzy", Integer.valueOf(3));
+ assertEquals(Integer.valueOf(3), lazyMap.get("xyzzy"));
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java b/core/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java
index b61181f..e34743f 100644
--- a/core/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java
+++ b/core/src/test/java/org/apache/commons/functor/example/map/TestPredicatedMap.java
@@ -58,7 +58,7 @@
// tests
public void testCanPutMatchingPair() {
- predicatedMap.put("xyzzy", new Integer(17));
+ predicatedMap.put("xyzzy", Integer.valueOf(17));
}
public void testCantPutInvalidValue() {
try {
@@ -71,7 +71,7 @@
public void testCantPutInvalidKey() {
try {
- predicatedMap.put(new Long(1), new Integer(3));
+ predicatedMap.put(Long.valueOf(1), Integer.valueOf(3));
fail("Expected IllegalArgumentException");
} catch(IllegalArgumentException e) {
// expected
@@ -80,17 +80,13 @@
public void testOnlyValidPairsAreAddedInPutAll() {
HashMap<Object, Object> map = new HashMap<Object, Object>();
- map.put("one", new Integer(17));
+ map.put("one", Integer.valueOf(17));
map.put("two", "rejected");
- map.put(new Integer(17), "xyzzy");
- map.put(new Integer(7), new Integer(3));
+ map.put(Integer.valueOf(17), "xyzzy");
+ map.put(Integer.valueOf(7), Integer.valueOf(3));
predicatedMap.putAll(map);
- assertEquals(new Integer(17), predicatedMap.get("one"));
+ assertEquals(Integer.valueOf(17), predicatedMap.get("one"));
assertFalse(predicatedMap.containsKey("two"));
-/*
- assertFalse(predicatedMap.containsKey(new Integer(17)));
- assertFalse(predicatedMap.containsKey(new Integer(7)));
-*/
}
}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java b/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
index 7c3b0be..40a4f4c 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/TestBaseGenerator.java
@@ -45,8 +45,8 @@
public void setUp() throws Exception {
simpleGenerator = new BaseGenerator<Integer>() {
public void run(Procedure<? super Integer> proc) {
- for (int i=0;i<5;i++) {
- proc.run(new Integer(i));
+ for (int i = 0; i < 5; i++) {
+ proc.run(Integer.valueOf(i));
}
}
};
@@ -56,14 +56,14 @@
doubled = new ArrayList<Integer>();
listWithDuplicates = new ArrayList<Integer>();
sum = 0;
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- doubled.add(new Integer(i*2));
- listWithDuplicates.add(new Integer(i));
- listWithDuplicates.add(new Integer(i));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ doubled.add(Integer.valueOf(i * 2));
+ listWithDuplicates.add(Integer.valueOf(i));
+ listWithDuplicates.add(Integer.valueOf(i));
sum += i;
- if (i%2 == 0) {
- evens.add(new Integer(i));
+ if (i % 2 == 0) {
+ evens.add(Integer.valueOf(i));
}
}
}
@@ -82,7 +82,7 @@
@Test
public void testSimpleGenerator() {
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
simpleGenerator.run(new Procedure<Integer>() {
public void run(Integer obj) {
result.append(obj);
@@ -105,12 +105,12 @@
assertSame(fillThis, col);
assertEquals("[0, 1, 2, 3, 4]", col.toString());
- col = (Collection<Integer>)simpleGenerator.toCollection();
+ col = (Collection<Integer>) simpleGenerator.toCollection();
assertEquals("[0, 1, 2, 3, 4]", col.toString());
assertEquals("[0, 1, 2, 3, 4]", col.toString());
fillThis = new LinkedList<Integer>();
- col = (Collection<Integer>)simpleGenerator.to(fillThis);
+ col = (Collection<Integer>) simpleGenerator.to(fillThis);
assertSame(fillThis, col);
assertEquals("[0, 1, 2, 3, 4]", col.toString());
}
@@ -123,18 +123,6 @@
private List<Integer> listWithDuplicates = null;
@SuppressWarnings("unused")
private int sum = 0;
-// private Predicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
-// private Predicate equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
-// private Predicate isEven = new Predicate() {
-// public boolean test(Object obj) {
-// return ((Number) obj).intValue() % 2 == 0;
-// }
-// };
-// private Predicate isOdd = new Predicate() {
-// public boolean test(Object obj) {
-// return ((Number) obj).intValue() % 2 != 0;
-// }
-// };
// Classes
// ------------------------------------------------------------------------
@@ -143,6 +131,7 @@
public void run(Number that) {
sum += (that).intValue();
}
+
public int sum = 0;
}
-}
\ No newline at end of file
+}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java b/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
index ce8abc9..0c2459b 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateUntil.java
@@ -95,7 +95,7 @@
// Attributes
// ------------------------------------------------------------------------
- private static final Integer FIVE = new Integer(5);
+ private static final Integer FIVE = Integer.valueOf(5);
private Generator<Integer> wrappedGenerator = null;
private Predicate<Integer> isMoreThanFive = new Predicate<Integer>() {
diff --git a/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java b/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
index e67907f..91e8d10 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/loop/TestGenerateWhile.java
@@ -95,7 +95,7 @@
// Attributes
// ------------------------------------------------------------------------
- private static final Integer FIVE = new Integer(5);
+ private static final Integer FIVE = Integer.valueOf(5);
private Generator<Integer> wrappedGenerator = null;
private Predicate<Integer> isLessThanFive = new Predicate<Integer>()
diff --git a/core/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java b/core/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java
index 8417caa..557a707 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/loop/TestLoopGenerator.java
@@ -45,8 +45,8 @@
public void setUp() throws Exception {
simpleGenerator = new LoopGenerator<Integer>() {
public void run(Procedure<? super Integer> proc) {
- for (int i=0;i<5;i++) {
- proc.run(new Integer(i));
+ for (int i = 0; i < 5; i++) {
+ proc.run(Integer.valueOf(i));
if (isStopped()) {
break;
}
@@ -59,14 +59,14 @@
doubled = new ArrayList<Integer>();
listWithDuplicates = new ArrayList<Integer>();
sum = 0;
- for (int i=0;i<10;i++) {
- list.add(new Integer(i));
- doubled.add(new Integer(i*2));
- listWithDuplicates.add(new Integer(i));
- listWithDuplicates.add(new Integer(i));
+ for (int i = 0; i < 10; i++) {
+ list.add(Integer.valueOf(i));
+ doubled.add(Integer.valueOf(i * 2));
+ listWithDuplicates.add(Integer.valueOf(i));
+ listWithDuplicates.add(Integer.valueOf(i));
sum += i;
- if (i%2 == 0) {
- evens.add(new Integer(i));
+ if (i % 2 == 0) {
+ evens.add(Integer.valueOf(i));
}
}
}
@@ -85,7 +85,7 @@
@Test
public void testSimpleGenerator() {
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
simpleGenerator.run(new Procedure<Integer>() {
public void run(Integer obj) {
result.append(obj);
@@ -97,9 +97,10 @@
@Test
public void testStop() {
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
simpleGenerator.run(new Procedure<Integer>() {
- int i=0;
+ int i = 0;
+
public void run(Integer obj) {
result.append(obj);
if (i++ > 1) {
@@ -113,14 +114,14 @@
@Test
public void testWrappingGenerator() {
- final StringBuffer result = new StringBuffer();
+ final StringBuilder result = new StringBuilder();
final LoopGenerator<Integer> gen = new LoopGenerator<Integer>(simpleGenerator) {
public void run(final Procedure<? super Integer> proc) {
- LoopGenerator<Integer> wrapped = (LoopGenerator<Integer>)getWrappedGenerator();
+ LoopGenerator<Integer> wrapped = (LoopGenerator<Integer>) getWrappedGenerator();
assertSame(simpleGenerator, wrapped);
wrapped.run(new Procedure<Integer>() {
public void run(Integer obj) {
- proc.run(new Integer(obj.intValue() + 1));
+ proc.run(Integer.valueOf(obj.intValue() + 1));
}
});
}
@@ -135,9 +136,10 @@
assertEquals("12345", result.toString());
// try to stop the wrapped generator
- final StringBuffer result2 = new StringBuffer();
+ final StringBuilder result2 = new StringBuilder();
gen.run(new Procedure<Integer>() {
- int i=0;
+ int i = 0;
+
public void run(Integer obj) {
result2.append(obj);
if (i++ > 1) {
@@ -162,12 +164,12 @@
assertSame(fillThis, col);
assertEquals("[0, 1, 2, 3, 4]", col.toString());
- col = (Collection<Integer>)simpleGenerator.toCollection();
+ col = (Collection<Integer>) simpleGenerator.toCollection();
assertEquals("[0, 1, 2, 3, 4]", col.toString());
assertEquals("[0, 1, 2, 3, 4]", col.toString());
fillThis = new LinkedList<Integer>();
- col = (Collection<Integer>)simpleGenerator.to(fillThis);
+ col = (Collection<Integer>) simpleGenerator.to(fillThis);
assertSame(fillThis, col);
assertEquals("[0, 1, 2, 3, 4]", col.toString());
}
@@ -180,18 +182,6 @@
private List<Integer> listWithDuplicates = null;
@SuppressWarnings("unused")
private int sum = 0;
-// private UnaryPredicate equalsThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(3));
-// private UnaryPredicate equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(),new Integer(23));
-// private UnaryPredicate isEven = new UnaryPredicate() {
-// public boolean test(Object obj) {
-// return ((Number) obj).intValue() % 2 == 0;
-// }
-// };
-// private UnaryPredicate isOdd = new UnaryPredicate() {
-// public boolean test(Object obj) {
-// return ((Number) obj).intValue() % 2 != 0;
-// }
-// };
// Classes
// ------------------------------------------------------------------------
@@ -200,6 +190,7 @@
public void run(Number that) {
sum += (that).intValue();
}
+
public int sum = 0;
}
-}
\ No newline at end of file
+}
diff --git a/core/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java b/core/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java
index 181c0bb..440fd20 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/loop/TestTransformedGenerator.java
@@ -112,7 +112,7 @@
// Attributes
// ------------------------------------------------------------------------
- private static final Integer TWO = new Integer(2);
+ private static final Integer TWO = Integer.valueOf(2);
private Generator<Integer> wrappedGenerator = null;
private Function<Integer, Integer> sumsTwo = new Function<Integer, Integer>() {
diff --git a/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java b/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
index 6ff1243..fee0c51 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/loop/TestUntilGenerate.java
@@ -113,7 +113,7 @@
// Attributes
// ------------------------------------------------------------------------
- private static final Integer FIVE = new Integer(5);
+ private static final Integer FIVE = Integer.valueOf(5);
private Generator<Integer> wrappedGenerator = null;
private Predicate<Integer> isGreaterThanFive = new Predicate<Integer>() {
diff --git a/core/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java b/core/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java
index 33f3ac4..00d7a8d 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/loop/TestWhileGenerate.java
@@ -112,7 +112,7 @@
// Attributes
// ------------------------------------------------------------------------
- private static final Integer FIVE = new Integer(5);
+ private static final Integer FIVE = Integer.valueOf(5);
private Generator<Integer> wrappedGenerator = null;
private Predicate<Integer> isLessThanFive = new Predicate<Integer>() {
diff --git a/core/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java b/core/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
index 54cd101..5246094 100644
--- a/core/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
+++ b/core/src/test/java/org/apache/commons/functor/generator/util/TestEachElement.java
@@ -55,11 +55,11 @@
@Before
public void setUp() throws Exception {
list = new ArrayList<Integer>();
- list.add(new Integer(0));
- list.add(new Integer(1));
- list.add(new Integer(2));
- list.add(new Integer(3));
- list.add(new Integer(4));
+ list.add(Integer.valueOf(0));
+ list.add(Integer.valueOf(1));
+ list.add(Integer.valueOf(2));
+ list.add(Integer.valueOf(3));
+ list.add(Integer.valueOf(4));
map = new HashMap<String, String>();
map.put("1", "1-1");
diff --git a/core/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java b/core/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java
index c64ba8a..ce324e3 100644
--- a/core/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java
+++ b/core/src/test/java/org/apache/commons/functor/range/TestCharacterRange.java
@@ -117,11 +117,11 @@
@Test
public void testObjectConstructor() {
- CharacterRange range = Ranges.characterRange(new Character('a'),
- new Character('e'));
+ CharacterRange range = Ranges.characterRange(Character.valueOf('a'),
+ Character.valueOf('e'));
assertEquals("[a, b, c, d, e]", IteratorToGeneratorAdapter.adapt(range).toCollection().toString());
- range = Ranges.characterRange(new Character('a'), new Character('e'),
- new Integer(1));
+ range = Ranges.characterRange(Character.valueOf('a'), Character.valueOf('e'),
+ Integer.valueOf(1));
assertEquals("[a, b, c, d, e]", IteratorToGeneratorAdapter.adapt(range).toCollection().toString());
}
diff --git a/core/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java b/core/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java
index 56c65b1..56c183b 100644
--- a/core/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java
+++ b/core/src/test/java/org/apache/commons/functor/range/TestDoubleRange.java
@@ -92,7 +92,7 @@
IteratorToGeneratorAdapter.adapt(Ranges.doubleRange(0, 10))
.to(new ArrayList<Double>()));
for (int i = 0; i < 10; i++) {
- assertEquals(new Double(i), list.get(i));
+ assertEquals(Double.valueOf(i), list.get(i));
}
}
@@ -103,7 +103,7 @@
IteratorToGeneratorAdapter.adapt(Ranges.doubleRange(10, 0))
.to(new ArrayList<Double>()));
for (int i = 10; i > 0; i--) {
- assertEquals(new Double(i), list.get(10 - i));
+ assertEquals(Double.valueOf(i), list.get(10 - i));
}
}
}
@@ -149,11 +149,11 @@
@Test
public void testObjectConstructor() {
- DoubleRange range = Ranges.doubleRange(new Double(0),
- new Double(5));
+ DoubleRange range = Ranges.doubleRange(Double.valueOf(0),
+ Double.valueOf(5));
assertEquals("[0.0, 1.0, 2.0, 3.0, 4.0]", IteratorToGeneratorAdapter.adapt(range).toCollection()
.toString());
- range = Ranges.doubleRange(new Double(0), new Double(5), new Double(1));
+ range = Ranges.doubleRange(Double.valueOf(0), Double.valueOf(5), Double.valueOf(1));
}
@Test
diff --git a/core/src/test/java/org/apache/commons/functor/range/TestFloatRange.java b/core/src/test/java/org/apache/commons/functor/range/TestFloatRange.java
index 0966295..9e65eae 100644
--- a/core/src/test/java/org/apache/commons/functor/range/TestFloatRange.java
+++ b/core/src/test/java/org/apache/commons/functor/range/TestFloatRange.java
@@ -91,7 +91,7 @@
IteratorToGeneratorAdapter.adapt(Ranges.floatRange(0, 10))
.to(new ArrayList<Float>()));
for (int i = 0; i < 10; i++) {
- assertEquals(new Float(i), list.get(i));
+ assertEquals(Float.valueOf(i), list.get(i));
}
}
@@ -101,7 +101,7 @@
IteratorToGeneratorAdapter.adapt(Ranges.floatRange(10, 0))
.to(new ArrayList<Float>()));
for (int i = 10; i > 0; i--) {
- assertEquals(new Float(i), list.get(10 - i));
+ assertEquals(Float.valueOf(i), list.get(10 - i));
}
}
}
@@ -147,10 +147,10 @@
@Test
public void testObjectConstructor() {
- FloatRange range = Ranges.floatRange(new Float(0), new Float(5));
+ FloatRange range = Ranges.floatRange(Float.valueOf(0), Float.valueOf(5));
assertEquals("[0.0, 1.0, 2.0, 3.0, 4.0]", IteratorToGeneratorAdapter.adapt(range).toCollection()
.toString());
- range = Ranges.floatRange(new Float(0), new Float(5), new Float(1));
+ range = Ranges.floatRange(Float.valueOf(0), Float.valueOf(5), Float.valueOf(1));
assertEquals("[0.0, 1.0, 2.0, 3.0, 4.0]", IteratorToGeneratorAdapter.adapt(range).toCollection()
.toString());
}
diff --git a/core/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java b/core/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java
index 2991702..3619b83 100644
--- a/core/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java
+++ b/core/src/test/java/org/apache/commons/functor/range/TestIntegerRange.java
@@ -78,7 +78,7 @@
List<? super Integer> list = (List<? super Integer>) (
IteratorToGeneratorAdapter.adapt(Ranges.integerRange(0,10)).to(new ArrayList<Integer>()));
for (int i=0;i<10;i++) {
- assertEquals(new Integer(i),list.get(i));
+ assertEquals(Integer.valueOf(i),list.get(i));
}
}
@@ -87,7 +87,7 @@
List<? super Integer> list = (List<? super Integer>) (
IteratorToGeneratorAdapter.adapt(Ranges.integerRange(10,0)).to(new ArrayList<Integer>()));
for (int i=10;i>0;i--) {
- assertEquals(new Integer(i),list.get(10-i));
+ assertEquals(Integer.valueOf(i),list.get(10-i));
}
}
}
@@ -131,9 +131,9 @@
@Test
public void testObjectConstructor() {
- IntegerRange range = Ranges.integerRange(new Integer(0), new Integer(5));
+ IntegerRange range = Ranges.integerRange(Integer.valueOf(0), Integer.valueOf(5));
assertEquals("[0, 1, 2, 3, 4]", IteratorToGeneratorAdapter.adapt(range).toCollection().toString());
- range = Ranges.integerRange(new Integer(0), new Integer(5), new Integer(1));
+ range = Ranges.integerRange(Integer.valueOf(0), Integer.valueOf(5), Integer.valueOf(1));
assertEquals("[0, 1, 2, 3, 4]", IteratorToGeneratorAdapter.adapt(range).toCollection().toString());
}
diff --git a/core/src/test/java/org/apache/commons/functor/range/TestLongRange.java b/core/src/test/java/org/apache/commons/functor/range/TestLongRange.java
index 50a144b..2e1d78d 100644
--- a/core/src/test/java/org/apache/commons/functor/range/TestLongRange.java
+++ b/core/src/test/java/org/apache/commons/functor/range/TestLongRange.java
@@ -84,7 +84,7 @@
LongRange range = Ranges.longRange(0, 10);
Iterator<Long> iter = range.iterator();
for (int i=0;i<10;i++) {
- assertEquals(new Long(i), iter.next());
+ assertEquals(Long.valueOf(i), iter.next());
}
}
@@ -93,7 +93,7 @@
LongRange range = Ranges.longRange(10, 0);
Iterator<Long> iter = range.iterator();
for (int i=10;i>0;i--) {
- assertEquals(new Long(i), iter.next());
+ assertEquals(Long.valueOf(i), iter.next());
}
}
}
@@ -137,9 +137,9 @@
@Test
public void testObjectConstructor() {
- LongRange range = Ranges.longRange(new Long(0), new Long(5));
+ LongRange range = Ranges.longRange(Long.valueOf(0), Long.valueOf(5));
assertEquals("[0, 1, 2, 3, 4]", IteratorToGeneratorAdapter.adapt(range).toCollection().toString());
- range = Ranges.longRange(new Integer(0), new Long(5), new Long(1));
+ range = Ranges.longRange(Integer.valueOf(0), Long.valueOf(5), Long.valueOf(1));
assertEquals("[0, 1, 2, 3, 4]", IteratorToGeneratorAdapter.adapt(range).toCollection().toString());
}