You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2013/11/13 19:54:06 UTC
svn commit: r1541658 [2/3] - in
/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor:
./ adapter/ aggregator/ core/ core/algorithm/ core/collection/
core/comparator/ core/composite/ example/ example/kata/four/
example/kata/one/ e...
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java Wed Nov 13 18:54:05 2013
@@ -45,7 +45,7 @@ public class TestTransformedIterator ext
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 class TestTransformedIterator ext
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 @@ public class TestTransformedIterator ext
@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 @@ public class TestTransformedIterator ext
@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 @@ public class TestTransformedIterator ext
@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 @@ public class TestTransformedIterator ext
@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 @@ public class TestTransformedIterator ext
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 @@ public class TestTransformedIterator ext
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);
}
};
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/BaseComparisonPredicateTest.java Wed Nov 13 18:54:05 2013
@@ -33,23 +33,23 @@ public abstract class BaseComparisonPred
@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 @@ public abstract class BaseComparisonPred
@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
}
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java Wed Nov 13 18:54:05 2013
@@ -31,22 +31,24 @@ public class TestComparableComparator {
@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));
}
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java Wed Nov 13 18:54:05 2013
@@ -41,45 +41,45 @@ public class TestComparatorFunction exte
@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(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(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(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(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.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(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(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(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(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));
}
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java Wed Nov 13 18:54:05 2013
@@ -41,12 +41,12 @@ public class TestIsEquivalent extends Ba
@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 @@ public class TestIsEquivalent extends Ba
@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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java Wed Nov 13 18:54:05 2013
@@ -42,28 +42,28 @@ public class TestIsGreaterThan extends B
@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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java Wed Nov 13 18:54:05 2013
@@ -42,28 +42,28 @@ public class TestIsGreaterThanOrEqual ex
@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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java Wed Nov 13 18:54:05 2013
@@ -42,28 +42,28 @@ public class TestIsLessThan extends Base
@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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java Wed Nov 13 18:54:05 2013
@@ -42,17 +42,17 @@ public class TestIsLessThanOrEqual exten
@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
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java Wed Nov 13 18:54:05 2013
@@ -42,27 +42,27 @@ public class TestIsNotEquivalent extends
@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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestIsWithinRange.java Wed Nov 13 18:54:05 2013
@@ -32,7 +32,7 @@ public class TestIsWithinRange extends B
@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 @@ public class TestIsWithinRange extends B
@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)));
-
- assertTrue(!p.test(new Integer(4)));
- assertTrue(!p.test(new Integer(11)));
+ 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(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)));
-
- assertTrue(!p.test(new Integer(4)));
- assertTrue(!p.test(new Integer(11)));
+ 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(Integer.valueOf(4)));
+ assertTrue(!p.test(Integer.valueOf(11)));
}
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java Wed Nov 13 18:54:05 2013
@@ -38,11 +38,11 @@ public class TestMax extends BaseFunctor
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
// ------------------------------------------------------------------------
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java Wed Nov 13 18:54:05 2013
@@ -38,38 +38,39 @@ public class TestMin extends BaseFunctor
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));
}
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestBinaryOr.java Wed Nov 13 18:54:05 2013
@@ -45,61 +45,63 @@ public class TestBinaryOr extends BaseFu
@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 @@ public class TestBinaryOr extends BaseFu
@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);
- }
-
- 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));
+ 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));
assertTrue(!p.equals(null));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestCompositeFunction.java Wed Nov 13 18:54:05 2013
@@ -44,10 +44,10 @@ public class TestCompositeFunction exten
@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
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestNot.java Wed Nov 13 18:54:05 2013
@@ -47,17 +47,17 @@ public class TestNot extends BaseFunctor
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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java Wed Nov 13 18:54:05 2013
@@ -26,18 +26,21 @@ import org.junit.Test;
/**
* 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 class TestTransformedNullaryFunct
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 @@ public class TestTransformedNullaryFunct
@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 @@ public class TestTransformedNullaryFunct
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 @@ public class TestTransformedNullaryFunct
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));
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java Wed Nov 13 18:54:05 2013
@@ -26,18 +26,21 @@ import org.junit.Test;
/**
* 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 @@ public class TestTransformedNullaryProce
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 class TestTransformedNullaryProce
public void testRun() {
TransformedNullaryProcedure p = new TransformedNullaryProcedure(one, aggregator);
p.run();
- assertEquals(1,aggregator.getTotal());
+ assertEquals(1, aggregator.getTotal());
}
@Test
@@ -82,7 +89,7 @@ public class TestTransformedNullaryProce
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 @@ public class TestTransformedNullaryProce
// 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));
}
}
Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java
URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java?rev=1541658&r1=1541657&r2=1541658&view=diff
==============================================================================
--- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java (original)
+++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/example/FlexiMapExample.java Wed Nov 13 18:54:05 2013
@@ -63,14 +63,12 @@ import org.junit.Test;
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 @@ public class FlexiMapExample {
/* (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 @@ public class FlexiMapExample {
*/
/*
- * 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 @@ public class FlexiMapExample {
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 @@ public class FlexiMapExample {
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 @@ public class FlexiMapExample {
}
/*
- * 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 @@ public class FlexiMapExample {
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 @@ public class FlexiMapExample {
}
/*
- * ----------------------------------------------------------------------------
- * 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 @@ public class FlexiMapExample {
*/
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;