svn commit: r1354803 - in /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor: ./ core/algorithm/
Author: kinow Date: Thu Jun 28 02:59:23 2012 New Revision: 1354803 URL: http://svn.apache.org/viewvc?rev=1354803view=rev Log: Tests for functor core algorithms. Work related to FUNCTOR-12. A few algorithm classes weren't using BaseFunctorTest. It was changed in this commit. Some further work was needed to make test-objects serializable. And an extra test was included in BaseFunctorTest, to compare (using equals) a functor with a non-functor object. Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/BaseFunctorTest.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestInPlaceTransform.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestIndexOfInGenerator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestRemoveMatching.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestRetainMatching.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestWhileDo.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/BaseFunctorTest.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/BaseFunctorTest.java?rev=1354803r1=1354802r2=1354803view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/BaseFunctorTest.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/BaseFunctorTest.java Thu Jun 28 02:59:23 2012 @@ -55,6 +55,8 @@ public abstract class BaseFunctorTest { } else { assertTrue(equals must be symmetric,! obj2.equals(obj)); } + +assertTrue(a functor is not equal to an integer, ! obj.equals(new Integer(1))); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java?rev=1354803r1=1354802r2=1354803view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java Thu Jun 28 02:59:23 2012 @@ -17,35 +17,28 @@ package org.apache.commons.functor.core.algorithm; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import java.io.Serializable; + +import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.Procedure; import org.apache.commons.functor.core.Offset; -import org.apache.commons.functor.core.algorithm.DoUntil; import org.junit.Test; /** * Tests {@link DoUntil} algorithm. */ -public class TestDoUntil { +public class TestDoUntil extends BaseFunctorTest { -@Test -public final void testObjectEquals() throws Exception { +// Functor Testing Framework +// + +@Override +protected Object makeFunctor() throws Exception { Counter counter = new Counter(); -Object obj = new DoUntil(counter, new Offset(10)); -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 DoUntil(counter, new Offset(10)); -if (obj.equals(obj2)) { -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)); -} +return new DoUntil(counter, new Offset(10)); } - + @Test public void testDoUntil() { for(int i=0;i3;++i){ @@ -58,11 +51,32 @@ public class TestDoUntil { // Classes
svn commit: r1363382 - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/core/composite/UnarySequence.java test/java/org/apache/commons/functor/core/composite/TestUnarySequenc
Author: kinow Date: Thu Jul 19 15:23:19 2012 New Revision: 1363382 URL: http://svn.apache.org/viewvc?rev=1363382view=rev Log: FIXED FUNCTOR-21: Added an extra verification in the then() method of UnarySequence to avoid the NPE. Tests in place. Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java?rev=1363382r1=1363381r2=1363382view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/composite/UnarySequence.java Thu Jul 19 15:23:19 2012 @@ -98,7 +98,9 @@ public class UnarySequenceA implements * @return this */ public UnarySequenceA then(UnaryProcedure? super A p) { -list.add(p); +if (p != null) { +list.add(p); +} return this; } Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java?rev=1363382r1=1363381r2=1363382view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestUnarySequence.java Thu Jul 19 15:23:19 2012 @@ -17,6 +17,7 @@ package org.apache.commons.functor.core.composite; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.util.ArrayList; import java.util.List; @@ -44,6 +45,26 @@ public class TestUnarySequence extends B // @Test +public void testConstructors() throws Exception { +UnarySequenceObject seq1 = new UnarySequenceObject((UnaryProcedure? super Object)null); +UnarySequenceObject seq2 = new UnarySequenceObject(); +assertObjectsAreEqual(seq1, seq2); + +RunCounter p1 = new RunCounter(); +RunCounter p2 = new RunCounter(); +ListUnaryProcedure? super Object iterable = new ArrayListUnaryProcedure? super Object(); +iterable.add(p1); +iterable.add(p2); +UnarySequenceObject seq3 = new UnarySequenceObject(iterable); +UnarySequenceObject seq4 = new UnarySequenceObject(p1, p2); +assertObjectsAreEqual(seq3, seq4); + +UnarySequenceObject seq5 = new UnarySequenceObject((IterableUnaryProcedure? super Object)null); +UnarySequenceObject seq6 = new UnarySequenceObject((UnaryProcedure? super Object[])null); +assertObjectsAreEqual(seq5, seq6); +} + +@Test public void testRunZero() throws Exception { UnarySequenceString seq = new UnarySequenceString(); seq.run(null); @@ -110,6 +131,7 @@ public class TestUnarySequence extends B } assertObjectsAreNotEqual(p,new NoOp()); +assertFalse(p.equals(null)); } // Classes
svn propchange: r1363382 - svn:log
Author: kinow Revision: 1363382 Modified property: svn:log Modified: svn:log at Thu Jul 19 17:43:50 2012 -- --- svn:log (original) +++ svn:log Thu Jul 19 17:43:50 2012 @@ -1 +1 @@ -FIXED FUNCTOR-21: Added an extra verification in the then() method of UnarySequence to avoid the NPE. Tests in place. +[FUNCTOR-21] Added an extra verification in the then() method of UnarySequence to avoid the NPE. Tests in place.
svn commit: r1363443 - /commons/proper/functor/trunk/src/changes/changes.xml
Author: kinow Date: Thu Jul 19 17:57:46 2012 New Revision: 1363443 URL: http://svn.apache.org/viewvc?rev=1363443view=rev Log: [FUNCTOR-21] Updated changes.xml including the changes in this issue Modified: commons/proper/functor/trunk/src/changes/changes.xml Modified: commons/proper/functor/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/changes/changes.xml?rev=1363443r1=1363442r2=1363443view=diff == --- commons/proper/functor/trunk/src/changes/changes.xml (original) +++ commons/proper/functor/trunk/src/changes/changes.xml Thu Jul 19 17:57:46 2012 @@ -23,6 +23,9 @@ /properties body release version=1.0 date=2012-??-?? description=First release. + action dev=kinow issue=FUNCTOR-21 +Fix NPE in UnarySequence. + /action action dev=simonetripodi issue=FUNCTOR-19 due-to=Bruno P. Kinoshita Fix checkstyle warnings /action
svn commit: r1363514 [2/2] - in /commons/proper/functor/trunk/src: changes/ test/java/org/apache/commons/functor/ test/java/org/apache/commons/functor/core/collection/ test/java/org/apache/commons/fun
Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java?rev=1363514r1=1363513r2=1363514view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/example/map/FunctoredMap.java Thu Jul 19 20:13:49 2012 @@ -31,9 +31,9 @@ import org.apache.commons.functor.UnaryP * @version $Revision$ $Date$ */ @SuppressWarnings(unchecked) -public class FunctoredMap implements Map { -public FunctoredMap(Map map) { -this.map = map; +public class FunctoredMapK, V implements MapK, V { +public FunctoredMap(Map? super K, ? super V map) { +this.map = (MapK, V)map; } @Override @@ -46,16 +46,16 @@ public class FunctoredMap implements Map return map.toString(); } -public Collection values() { +public CollectionV values() { return map.values(); } -public Set keySet() { +public SetK keySet() { return map.keySet(); } -public Object get(Object key) { -return onget.evaluate(map,key); +public V get(Object key) { +return onget.evaluate(map, (K)key); } public void clear() { @@ -70,11 +70,11 @@ public class FunctoredMap implements Map return onput.evaluate(map, new Object[] { key, value }); } -public void putAll(Map src) { -onputall.run(map, src); +public void putAll(Map? extends K, ? extends V src) { +onputall.run(map, (MapK, V)src); } -public Set entrySet() { +public SetMap.EntryK, V entrySet() { return map.entrySet(); } @@ -86,8 +86,8 @@ public class FunctoredMap implements Map return map.isEmpty(); } -public Object remove(Object key) { -return onremove.evaluate(map,key); +public V remove(Object key) { +return onremove.evaluate(map, (K)key); } @Override @@ -101,80 +101,80 @@ public class FunctoredMap implements Map // protected -protected void setOnClear(UnaryProcedure procedure) { +protected void setOnClear(UnaryProcedureMapK, V procedure) { onclear = procedure; } -protected void setOnPut(BinaryFunction function) { +protected void setOnPut(BinaryFunctionMapK, V, Object[], V function) { onput = function; } -protected void setOnGet(BinaryFunction function) { +protected void setOnGet(BinaryFunctionMapK, V, K, V function) { onget = function; } -protected void setOnPutAll(BinaryProcedure procedure) { +protected void setOnPutAll(BinaryProcedureMapK, V, MapK, V procedure) { onputall = procedure; } -protected void setOnRemove(BinaryFunction function) { +protected void setOnRemove(BinaryFunctionMapK, V, K, V function) { onremove = function; } // attributes -protected static final BinaryFunction DEFAULT_ON_PUT = new BinaryFunction() { -public Object evaluate(Object a, Object b) { -Map map = (Map) a; -Object key = Array.get(b,0); -Object value = Array.get(b,1); +protected BinaryFunctionMapK, V, Object[], V DEFAULT_ON_PUT = new BinaryFunctionMapK, V, Object[], V() { +public V evaluate(MapK, V a, Object[] b) { +MapK, V map = a; +K key = (K)Array.get(b,0); +V value = (V)Array.get(b,1); return map.put(key,value); } }; -private BinaryFunction onput = DEFAULT_ON_PUT; +private BinaryFunctionMapK, V, Object[], V onput = DEFAULT_ON_PUT; -protected static final BinaryFunction DEFAULT_ON_GET = new BinaryFunction() { -public Object evaluate(Object map, Object key) { -return ((Map) map).get(key); +protected BinaryFunctionMapK, V, K, V DEFAULT_ON_GET = new BinaryFunctionMapK, V, K, V() { +public V evaluate(MapK, V map, K key) { +return map.get(key); } }; -private BinaryFunction onget = DEFAULT_ON_GET; - -protected static final BinaryProcedure DEFAULT_ON_PUT_ALL = new BinaryProcedure() { -public void run(Object a, Object b) { -Map dest = (Map) a; -Map src = (Map) b; +private BinaryFunctionMapK, V, K, V onget = DEFAULT_ON_GET; + +protected BinaryProcedureMapK, V, MapK, V DEFAULT_ON_PUT_ALL = new BinaryProcedureMapK, V, MapK, V() { +public void run(MapK, V a, MapK, V b) { +MapK, V dest = a; +MapK, V src = b; dest.putAll(src); } }; -private BinaryProcedure onputall = DEFAULT_ON_PUT_ALL; +private BinaryProcedureMapK, V, MapK, V onputall =
svn commit: r1364676 - in /commons/proper/functor/trunk/src: changes/ main/java/org/apache/commons/functor/core/comparator/ test/java/org/apache/commons/functor/core/comparator/
Author: kinow Date: Mon Jul 23 15:21:25 2012 New Revision: 1364676 URL: http://svn.apache.org/viewvc?rev=1364676view=rev Log: [FUNCTOR-22] Added generics to ComparableComparator. Few other classes that used the ComparableComparator were updated too. Tests were also updated accordingly. Modified: commons/proper/functor/trunk/src/changes/changes.xml commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Max.java commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/Min.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparableComparator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java Modified: commons/proper/functor/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/changes/changes.xml?rev=1364676r1=1364675r2=1364676view=diff == --- commons/proper/functor/trunk/src/changes/changes.xml (original) +++ commons/proper/functor/trunk/src/changes/changes.xml Mon Jul 23 15:21:25 2012 @@ -23,6 +23,9 @@ /properties body release version=1.0 date=2012-??-?? description=First release. + action dev=kinow issue=FUNCTOR-22 +Generify ComparableComparator. + /action action dev=kinow issue=FUNCTOR-3 Reduce the use of raw types in test classes. /action Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java?rev=1364676r1=1364675r2=1364676view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java Mon Jul 23 15:21:25 2012 @@ -20,33 +20,37 @@ import java.io.Serializable; import java.util.Comparator; /** - * See Commons-Collections for a public version - * of this class. + * A {@link Comparator Comparator} that compares {@link Comparable Comparable} + * objects. + * p + * This class was created based on commons-collection's ComparableComparator. * + * @param E the comparable type * @version $Revision$ $Date$ */ -@SuppressWarnings({ unchecked, rawtypes }) -final class ComparableComparator implements Comparator, Serializable { +final class ComparableComparatorE extends Comparable? super E implements ComparatorE, Serializable { /** Singleton. */ -public static final ComparableComparator INSTANCE = new ComparableComparator(); +@SuppressWarnings(rawtypes) +public static final ComparableComparator? INSTANCE = new ComparableComparator(); /** * serialVersionUID declaration. */ -private static final long serialVersionUID = -5849476573719561212L
svn commit: r1364704 - /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/
Author: kinow Date: Mon Jul 23 16:40:49 2012 New Revision: 1364704 URL: http://svn.apache.org/viewvc?rev=1364704view=rev Log: [FUNCTOR-12] Tests for functor core comparators. Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThanOrEqual.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsNotEquivalent.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestMax.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestMin.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java?rev=1364704r1=1364703r2=1364704view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsEquivalent.java Mon Jul 23 16:40:49 2012 @@ -17,6 +17,7 @@ package org.apache.commons.functor.core.comparator; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.apache.commons.functor.core.Constant; @@ -59,9 +60,10 @@ public class TestIsEquivalent extends Ba IsEquivalentComparable? p = IsEquivalent.INSTANCE; assertEquals(p,p); -assertObjectsAreEqual(p,IsEquivalent.instance()); +assertObjectsAreEqual(p,new IsEquivalentComparable?()); assertObjectsAreEqual(p,new IsEquivalentInteger(ComparableComparator.Integerinstance())); assertObjectsAreNotEqual(p,Constant.FALSE); +assertFalse(p.equals(null)); } } Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java?rev=1364704r1=1364703r2=1364704view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThan.java Mon Jul 23 16:40:49 2012 @@ -64,6 +64,7 @@ public class TestIsGreaterThan extends B assertObjectsAreEqual(p,new IsGreaterThanInteger(ComparableComparator.Integerinstance())); assertObjectsAreEqual(p,IsGreaterThan.instance()); assertObjectsAreNotEqual(p,Constant.FALSE); +assertFalse(p.equals(null)); } } Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java?rev=1364704r1=1364703r2=1364704view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsGreaterThanOrEqual.java Mon Jul 23 16:40:49 2012 @@ -64,6 +64,7 @@ public class TestIsGreaterThanOrEqual ex assertObjectsAreEqual(p,new IsGreaterThanOrEqualInteger(ComparableComparator.Integerinstance())); assertObjectsAreEqual(p,IsGreaterThanOrEqual.instance()); assertObjectsAreNotEqual(p,Constant.FALSE); +assertFalse(p.equals(null)); } } Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java?rev=1364704r1=1364703r2=1364704view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestIsLessThan.java (original) +++ commons/proper/functor/trunk
svn commit: r1364742 - in /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection: TestFilteredIterable.java TestFilteredIterator.java TestTransformedIterator.java
Author: kinow Date: Mon Jul 23 18:20:48 2012 New Revision: 1364742 URL: http://svn.apache.org/viewvc?rev=1364742view=rev Log: [FUNCTOR-12] Tests for functor core collections. Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestTransformedIterator.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java?rev=1364742r1=1364741r2=1364742view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/collection/TestFilteredIterable.java Mon Jul 23 18:20:48 2012 @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEqu import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.math.BigInteger; import java.util.ArrayList; @@ -90,11 +89,14 @@ public class TestFilteredIterable extend public void testSomePass() { IteratorInteger expected = evens.iterator(); -for (Integer i : FilteredIterable.of(list).retain(isEven)) { +FilteredIterableInteger filter = FilteredIterable.of(list); + +for (Integer i : filter.retain(isEven)) { assertTrue(expected.hasNext()); assertEquals(expected.next(), i); } assertFalse(expected.hasNext()); +assertEquals(filter,filter.retain(isEven)); } @Test @@ -120,7 +122,11 @@ public class TestFilteredIterable extend @Test public void testEmptyFilteredIterable() { -assertFalse(FilteredIterable.empty().iterator().hasNext()); +FilteredIterableInteger emptyFilter = FilteredIterable.empty(); +assertFalse(emptyFilter.iterator().hasNext()); +assertEquals(emptyFilter,emptyFilter.retain(isEven)); +assertEquals(emptyFilter,emptyFilter.retain(Integer.class)); + assertEquals(emptyFilter,emptyFilter.retain(Integer.class,Number.class)); } @Test @@ -143,53 +149,33 @@ public class TestFilteredIterable extend assertFalse(testing.hasNext()); } -@Test +@Test(expected=NoSuchElementException.class) public void testNextAfterEndOfList() { IteratorInteger testing = FilteredIterable.of(list).retain(isEven).iterator(); IteratorInteger expected = evens.iterator(); while (expected.hasNext()) { assertEquals(expected.next(), testing.next()); } -try { -testing.next(); -fail(Expected NoSuchElementException); -} catch (NoSuchElementException e) { -// expected -} +testing.next(); } -@Test +@Test(expected=NoSuchElementException.class) public void testNextOnEmptyList() { -try { -FilteredIterable.empty().iterator().next(); -fail(Expected NoSuchElementException); -} catch (NoSuchElementException e) { -// expected -} +FilteredIterable.empty().iterator().next(); } -@Test +@Test(expected=IllegalStateException.class) public void testRemoveBeforeNext() { IteratorInteger testing = FilteredIterable.of(list).retain(isEven).iterator(); -try { -testing.remove(); -fail(Expected IllegalStateException); -} catch (IllegalStateException e) { -// expected -} +testing.remove(); } -@Test +@Test(expected=IllegalStateException.class) public void testRemoveAfterNext() { IteratorInteger testing = FilteredIterable.of(list).retain(isEven).iterator(); testing.next(); testing.remove(); -try { -testing.remove(); -fail(Expected IllegalStateException); -} catch (IllegalStateException e) { -// expected -} +testing.remove(); } @Test @@ -228,6 +214,12 @@ public class TestFilteredIterable extend } @Test +public void testFilterWithFilteredIterableReturnsItself() { +FilteredIterableInteger filter = FilteredIterable.of(list); +assertEquals(filter,FilteredIterable.of(filter)); +} + +@Test public void testRetainOneType() { IterableObject objects = Arrays.asList((Object) foo, bar, baz, 2L, BigInteger.ZERO); IterableString strings
svn commit: r1365325 - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java test/java/org/apache/commons/functor/aggregator/AbstractN
Author: kinow Date: Tue Jul 24 22:14:33 2012 New Revision: 1365325 URL: http://svn.apache.org/viewvc?rev=1365325view=rev Log: [FUNCTOR-12] Added test for AbstractListBackedAggregator no args constructor (created for JavaBean compatibility). Replaced the not-null-verification by Validate.notNull(). Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java Modified: commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java?rev=1365325r1=1365324r2=1365325view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java (original) +++ commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.java Tue Jul 24 22:14:33 2012 @@ -19,6 +19,7 @@ package org.apache.commons.functor.aggre import java.util.List; import org.apache.commons.functor.UnaryFunction; +import org.apache.commons.lang3.Validate; /** * An aggregator which stores the data series in a List. Every call to @@ -99,10 +100,7 @@ public abstract class AbstractListBacked public AbstractListBackedAggregator(UnaryFunctionListT, T aggregationFunction, long interval, boolean useSharedTimer) { super(interval, useSharedTimer); -if (aggregationFunction == null) { -throw new NullPointerException(no function specified for aggregation); -} -this.aggregationFunction = aggregationFunction; +this.aggregationFunction = Validate.notNull(aggregationFunction, UnaryFunction argument must not be null); this.series = createList(); } Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java?rev=1365325r1=1365324r2=1365325view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/aggregator/AbstractNoStoreAggregatorTest.java Tue Jul 24 22:14:33 2012 @@ -117,6 +117,11 @@ public class AbstractNoStoreAggregatorTe } } +@Test +public void testDataSize() { +assertEquals(0, new TestNoStoreAggregatorObject(new Object()).retrieveDataSize()); +} + /** * Dummy binary function which always returns the first parameter. */
svn commit: r1365326 - in /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core: TestLeftIdentity.java TestRightIdentity.java
Author: kinow Date: Tue Jul 24 22:15:31 2012 New Revision: 1365326 URL: http://svn.apache.org/viewvc?rev=1365326view=rev Log: Added tests to LeftIdentity and RightIdentity no args constructors (created for compatibility with tools using JavaBeans). Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java?rev=1365326r1=1365325r2=1365326view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestLeftIdentity.java Tue Jul 24 22:15:31 2012 @@ -17,6 +17,7 @@ package org.apache.commons.functor.core; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -43,6 +44,11 @@ public class TestLeftIdentity extends Ba // @Test +public void testJavabeanConstructor() { +assertNotNull(new LeftIdentity()); // Public constructor for JavaBean +} + +@Test public void testEvaluate() throws Exception { BinaryFunctionObject, Object, Object f = LeftIdentity.FUNCTION; assertNull(f.evaluate(null,null)); Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java?rev=1365326r1=1365325r2=1365326view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/TestRightIdentity.java Tue Jul 24 22:15:31 2012 @@ -17,6 +17,7 @@ package org.apache.commons.functor.core; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -43,6 +44,11 @@ public class TestRightIdentity extends B // @Test +public void testJavabeanConstructor() { +assertNotNull(new RightIdentity()); // Public constructor for JavaBean +} + +@Test public void testEvaluate() throws Exception { BinaryFunctionObject, Object, Object f = RightIdentity.FUNCTION; assertNull(f.evaluate(null,null));
svn commit: r1365327 - /commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java
Author: kinow Date: Tue Jul 24 22:16:56 2012 New Revision: 1365327 URL: http://svn.apache.org/viewvc?rev=1365327view=rev Log: [FUNCTOR-12] Added tests for FindWithinGenerator that cover untested branches. Replaced a try/catch + fail() by @Test(expected=SomeClass.class). Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java?rev=1365327r1=1365326r2=1365327view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/algorithm/TestFindWithinGenerator.java Tue Jul 24 22:16:56 2012 @@ -19,7 +19,6 @@ package org.apache.commons.functor.core. import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.Arrays; import java.util.List; @@ -29,7 +28,6 @@ import org.apache.commons.functor.BaseFu import org.apache.commons.functor.UnaryPredicate; import org.apache.commons.functor.adapter.LeftBoundPredicate; import org.apache.commons.functor.core.IsEqual; -import org.apache.commons.functor.core.algorithm.FindWithinGenerator; import org.apache.commons.functor.generator.IteratorToGeneratorAdapter; import org.junit.Test; @@ -76,14 +74,19 @@ public class TestFindWithinGenerator ext } @Test +public void testEquals() { +FindWithinGeneratorObject f = new FindWithinGeneratorObject(); +assertEquals(f,f); + +assertObjectsAreEqual(f,new FindWithinGeneratorObject()); +assertObjectsAreEqual(new FindWithinGeneratorObject(new Double(0)),new FindWithinGeneratorObject(new Double(0))); +assertObjectsAreNotEqual(f, new FindWithinGeneratorObject(new Integer(0))); +} + +@Test(expected=NoSuchElementException.class) public void testDetect() { assertEquals(new Integer(3),new FindWithinGeneratorInteger().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsThree)); -try { -new FindWithinGeneratorInteger().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsTwentyThree); -fail(Expected NoSuchElementException); -} catch(NoSuchElementException e) { -// expected -} +new FindWithinGeneratorInteger().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()),equalsTwentyThree); } @Test
svn commit: r1365329 [2/2] - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/core/composite/ test/java/org/apache/commons/functor/core/composite/
Added: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java?rev=1365329view=auto == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java (added) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java Tue Jul 24 22:34:23 2012 @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.functor.core.composite; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.Serializable; + +import org.apache.commons.functor.BaseFunctorTest; +import org.apache.commons.functor.BinaryFunction; +import org.apache.commons.functor.UnaryFunction; +import org.junit.Test; + + +/** + * Tests for TransformedBinaryFunction. + * @version $Revision: $ $Date: $ + */ +public class TestTransformedBinaryFunction extends BaseFunctorTest { + +private static class Sum implements BinaryFunctionInteger, Integer, Integer, Serializable { +private static final long serialVersionUID = 2255396324585938931L; +public Integer evaluate(Integer left, Integer right) { +return left+right; +} +@Override +public boolean equals(Object obj) { +return obj == this || obj != null obj instanceof Sum; +} +@Override +public int hashCode() { +return Sum.hashCode(); +} +} + +private static class AddOne implements UnaryFunctionInteger, Integer, Serializable { +private static final long serialVersionUID = 8759620198239402369L; +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(); +} +} + +@Override +protected Object makeFunctor() throws Exception { +return new TransformedBinaryFunctionInteger, Integer, Integer(new Sum(), new AddOne()); +} + +@Test +public void testRun() { +TransformedBinaryFunctionInteger, Integer, Integer transform = new TransformedBinaryFunctionInteger, Integer, Integer(new Sum(), new AddOne()); +assertEquals(Integer.valueOf(4), transform.evaluate(1, 2)); +} + +@Test +public void testEquals() { +TransformedBinaryFunctionInteger, Integer, Integer t = new TransformedBinaryFunctionInteger, Integer, Integer(new Sum(), new AddOne()); +BinaryFunctionInteger, Integer, Integer f = new BinaryFunctionInteger, Integer, Integer() { +public Integer evaluate(Integer left, Integer right) { +return left-right; +} +}; +UnaryFunctionInteger, Integer p = new UnaryFunctionInteger, Integer() { +public Integer evaluate(Integer obj) { +return obj-1; +} +}; +assertEquals(t,t); +assertObjectsAreEqual(t,new TransformedBinaryFunctionInteger, Integer, Integer(new Sum(), new AddOne())); +assertObjectsAreNotEqual(t,new TransformedBinaryFunctionInteger, Integer, Integer(f, new AddOne())); +assertObjectsAreNotEqual(t,new TransformedBinaryFunctionInteger, Integer, Integer(new Sum(), p)); +assertTrue(!t.equals(null)); +} + +} Propchange: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java -- svn:mime-type = text/plain Added: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java URL:
svn commit: r1365377 [2/2] - in /commons/proper/functor/trunk/src: main/java/org/apache/commons/functor/adapter/ test/java/org/apache/commons/functor/adapter/
Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java?rev=1365377r1=1365376r2=1365377view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestProcedureUnaryProcedure.java Wed Jul 25 00:59:23 2012 @@ -19,11 +19,13 @@ package org.apache.commons.functor.adapt import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.UnaryProcedure; import org.apache.commons.functor.core.Constant; import org.apache.commons.functor.core.NoOp; +import org.apache.commons.functor.core.composite.Sequence; import org.junit.Test; /** @@ -54,6 +56,8 @@ public class TestProcedureUnaryProcedure assertEquals(p,p); assertObjectsAreEqual(p,new ProcedureUnaryProcedureObject(NoOp.INSTANCE)); assertObjectsAreNotEqual(p,NoOp.INSTANCE); +assertObjectsAreNotEqual(p,new ProcedureUnaryProcedureObject(new Sequence())); +assertTrue(!p.equals(null)); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java?rev=1365377r1=1365376r2=1365377view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundFunction.java Wed Jul 25 00:59:23 2012 @@ -19,6 +19,7 @@ package org.apache.commons.functor.adapt import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.UnaryFunction; @@ -57,6 +58,9 @@ public class TestRightBoundFunction exte assertObjectsAreNotEqual(f,Constant.of(xyzzy)); assertObjectsAreNotEqual(f,new RightBoundFunctionObject, Object(RightIdentity.FUNCTION,xyzzy)); assertObjectsAreNotEqual(f,new RightBoundFunctionObject, Object(LeftIdentity.FUNCTION,bar)); +assertObjectsAreNotEqual(f,new RightBoundFunctionObject, Object(LeftIdentity.FUNCTION,null)); +assertObjectsAreEqual(new RightBoundFunctionObject, Object(LeftIdentity.FUNCTION,null),new RightBoundFunctionObject, Object(LeftIdentity.FUNCTION,null)); +assertTrue(!f.equals(null)); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java?rev=1365377r1=1365376r2=1365377view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundPredicate.java Wed Jul 25 00:59:23 2012 @@ -61,6 +61,8 @@ public class TestRightBoundPredicate ext assertObjectsAreNotEqual(f, new RightBoundPredicateBoolean(Constant.FALSE, xyzzy)); assertObjectsAreNotEqual(f, new RightBoundPredicateBoolean(Constant.TRUE, foo)); assertObjectsAreNotEqual(f, new RightBoundPredicateBoolean(Constant.TRUE, null)); +assertObjectsAreEqual(new RightBoundPredicateBoolean(Constant.TRUE, null), new RightBoundPredicateBoolean(Constant.TRUE, null)); +assertTrue(!f.equals(null)); } @Test Modified: commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java?rev=1365377r1=1365376r2=1365377view=diff == --- commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java (original) +++ commons/proper/functor/trunk/src/test/java/org/apache/commons/functor/adapter/TestRightBoundProcedure.java Wed
svn commit: r1373984 - in /commons/proper/functor/branches/generators-FUNCTOR-14: ./ src/main/java/org/apache/commons/functor/generator/util/ src/test/java/org/apache/commons/functor/ src/test/java/or
Author: kinow Date: Thu Aug 16 19:09:10 2012 New Revision: 1373984 URL: http://svn.apache.org/viewvc?rev=1373984view=rev Log: Creating a branch to work on FUNCTOR-14 issue: Enhancements on the Generator API Added: commons/proper/functor/branches/generators-FUNCTOR-14/ - copied from r1373171, commons/proper/functor/trunk/ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java - copied, changed from r1373171, commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongGenerator.java - copied, changed from r1373171, commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/LongRange.java Removed: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/LongRange.java Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/TestAlgorithms.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/example/kata/two/TestBinaryChop.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestFilteredGenerator.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateUntil.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestGenerateWhile.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestTransformedGenerator.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestUntilGenerate.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/TestWhileGenerate.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestIntegerRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/util/TestLongRange.java Copied: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java (from r1373171, commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java) URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java?p2=commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.javap1=commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.javar1=1373171r2=1373984rev=1373984view=diff == --- commons/proper/functor/trunk/src/main/java/org/apache/commons/functor/generator/util/IntegerRange.java (original) +++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/generator/util/IntegerGenerator.java Thu Aug 16 19:09:10 2012 @@ -24,7 +24,7 @@ import org.apache.commons.functor.genera * @since 1.0 * @version $Revision$ $Date$ */ -public final class IntegerRange extends BaseGeneratorInteger { +public final class IntegerGenerator extends BaseGeneratorInteger { // attributes //--- @@ -50,7 +50,7 @@ public final class IntegerRange extends * @param from start * @param to end */ -public IntegerRange(Number from, Number to) { +public IntegerGenerator(Number from, Number to) { this(from.intValue(), to.intValue()); } @@ -60,7 +60,7 @@ public final class IntegerRange extends * @param to end * @param step increment */ -public IntegerRange(Number from, Number to, Number step) { +public IntegerGenerator(Number from, Number to, Number step) { this(from.intValue(), to.intValue(), step.intValue()); } @@ -69,7 +69,7 @@ public final class IntegerRange extends * @param from start * @param to end */ -public IntegerRange(int from, int to) { +public IntegerGenerator(int from, int to) { this(from, to, defaultStep(from, to)); } @@ -79,7 +79,7 @@ public final class IntegerRange extends * @param to end * @param step increment */ -public IntegerRange(int from, int to, int step) { +public IntegerGenerator(int from
svn commit: r1385335 [4/4] - in /commons/proper/functor/branches/generators-FUNCTOR-14: ./ src/changes/ src/main/java/org/apache/commons/functor/generator/range/ src/site/xdoc/ src/test/java/org/apach
Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/TestLongRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/TestLongRange.java?rev=1385335r1=1385334r2=1385335view=diff == --- commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/TestLongRange.java (original) +++ commons/proper/functor/branches/generators-FUNCTOR-14/src/test/java/org/apache/commons/functor/generator/range/TestLongRange.java Sun Sep 16 18:08:31 2012 @@ -17,13 +17,22 @@ package org.apache.commons.functor.generator.range; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; import org.apache.commons.functor.BaseFunctorTest; -import org.apache.commons.functor.generator.range.LongRange; +import org.apache.commons.functor.UnaryFunction; +import org.apache.commons.functor.UnaryProcedure; +import org.apache.commons.functor.generator.Generator; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** @@ -31,19 +40,47 @@ import org.junit.Test; */ public class TestLongRange extends BaseFunctorTest { +// A base range with all longs between -6 and 6 +private final ListLong fullRange = Collections.unmodifiableList(Arrays +.asList(-6L, -5L, -4L, -3L, -2L, -1L, 0L, 1L, 2L, 3L, 4L, 5L, 6L)); + +// Attributes +// +private LongRange ascLongRange = null; +private LongRange descLongRange = null; +private CollectionLong expectedAsc = null; +private CollectionLong expectedDesc = null; + +// Test set up +// +@Before +public void setUp() { +ascLongRange = Ranges.longRange(0L, 10L); +descLongRange = Ranges.longRange(10L, 0L); +expectedAsc = Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L); +expectedDesc = Arrays.asList(10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L); +} + +@After +public void tearDown() { +ascLongRange = null; +descLongRange = null; +} + @Override -protected Object makeFunctor() throws Exception { -return new LongRange(10, 20); +protected Object makeFunctor() +throws Exception { +return Ranges.longRange(10, 20); } -// Tests +// Generator tests // @Test public void testGenerateListExample() { // generates a collection of Integers from 0 (inclusive) to 10 (exclusive) { -List? super Long list = (List? super Long)(new LongRange(0,10).to(new ArrayListLong())); +List? super Long list = (List? super Long)(Ranges.longRange(0,10).to(new ArrayListLong())); for (int i=0;i10;i++) { assertEquals(new Long(i),list.get(i)); } @@ -51,7 +88,7 @@ public class TestLongRange extends BaseF // generates a collection of Integers from 10 (inclusive) to 0 (exclusive) { -List? super Long list = (List? super Long)(new LongRange(10,0).to(new ArrayListLong())); +List? super Long list = (List? super Long)(Ranges.longRange(10,0).to(new ArrayListLong())); for (int i=10;i0;i--) { assertEquals(new Long(i),list.get(10-i)); } @@ -61,34 +98,34 @@ public class TestLongRange extends BaseF @Test public void testStepChecking() { { -new LongRange(2, 2, 0); // step of 0 is ok when range is empty +Ranges.longRange(2, 2, 0); // step of 0 is ok when range is empty } { -new LongRange(2, 2, 1); // positive step is ok when range is empty +Ranges.longRange(2, 2, 1); // positive step is ok when range is empty } { -new LongRange(2, 2, -1); // negative step is ok when range is empty +Ranges.longRange(2, 2, -1); // negative step is ok when range is empty } { -new LongRange(0, 1, 10); // big steps are ok +Ranges.longRange(0, 1, 10); // big steps are ok } { -new LongRange(1, 0, -10); // big steps are ok +Ranges.longRange(1, 0, -10); // big steps are ok } try { -new LongRange(0, 1, 0); +Ranges.longRange(0, 1, 0); fail(Expected IllegalArgumentException); }
svn commit: r1424224 - /commons/proper/functor/trunk/src/site/xdoc/aggregator.xml
Author: kinow Date: Wed Dec 19 23:38:32 2012 New Revision: 1424224 URL: http://svn.apache.org/viewvc?rev=1424224view=rev Log: FUNCTOR-23 reverting changes from PATCH-23 as the %23 was breaking URL's in chrome and not really fixing the javadoc links Modified: commons/proper/functor/trunk/src/site/xdoc/aggregator.xml Modified: commons/proper/functor/trunk/src/site/xdoc/aggregator.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/site/xdoc/aggregator.xml?rev=1424224r1=1424223r2=1424224view=diff == --- commons/proper/functor/trunk/src/site/xdoc/aggregator.xml (original) +++ commons/proper/functor/trunk/src/site/xdoc/aggregator.xml Wed Dec 19 23:38:32 2012 @@ -15,10 +15,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY See the License for the specific language governing permissions and limitations under the License. -- -!-- -See https://jira.codehaus.org/browse/MSITE-646, the links to JavaDoc methods have to -have the hash URL-escaped. --- document properties titleAggregator/title @@ -52,7 +48,7 @@ have the hash URL-escaped. /p p The framework allows for any codeList/code-based implementation to be plugged in, by -implementing a href=apidocs/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.html%23createList()createList()/a, +implementing a href=apidocs/org/apache/commons/functor/aggregator/AbstractListBackedAggregator.html#createList()createList()/a, however, there is also an codeArrayList/code-based implementation provided in a href=apidocs/org/apache/commons/functor/aggregator/ArrayListBackedAggregator.htmlArrayListBackedAggregator/a which can be used out-of-the-box. @@ -61,17 +57,17 @@ have the hash URL-escaped. While the istore/i implementation stores the data in a list, the inostore/i one stores just a single object -- every time data is fed into the codeAggregator/code, the data stored in this object and the data -a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html%23add(T)passed in/a +a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html#add(T)passed in/a are aggregated there and then using the supplied a href=apidocs/org/apache/commons/functor/BinaryFunction.htmlformula/a and the result of this operation is stored back in the object this implementation uses to store data. /p p This has the implication that unlike the list-backed storage implementation (where the -result of aggregating the data is not known until a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html%23evaluate()evaluate()/a +result of aggregating the data is not known until a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html#evaluate()evaluate()/a is called), with the inostore/i implementation the result is known (and saved back) at any moment. This arguably makes this class faster, however this comes at the cost of a -slower a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html%23add(T)add()/a +slower a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html#add(T)add()/a operation, as the aggregation formula is applied. Also, let's remind ourselves that not all formulas can be implemented using the inostore/i implementation (see above). /p @@ -96,9 +92,9 @@ have the hash URL-escaped. a href=apidocs/org/apache/commons/functor/aggregator/AbstractTimedAggregator.htmlAbstractTimedAggregator/a offers support to start a timer internally to do that. The class offers a ilistener/i mechanism where classes can register to receive a href=apidocs/org/apache/commons/functor/aggregator/TimedAggregatorListener.htmltimer notifications/a (if timer support was configured) and after all listeners have been - notified the aggregator is a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html%23reset()reset/a. + notified the aggregator is a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html#reset()reset/a. The result of - a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html%23evaluate()evaluate()/a + a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.html#evaluate()evaluate()/a (the result of aggregating data) is passed in to the listeners. This allows for an object to simply register itself as a timer listener to the aggregator and only react to the timer notifications (e.g. write the result to a file for offline analysis etc) while the @@ -108,7 +104,7 @@ have the hash URL-escaped. When the data is being flushed/reset, a a href=apidocs/org/apache/commons/functor
svn commit: r1424226 - /commons/proper/functor/trunk/src/site/xdoc/examples.xml
Author: kinow Date: Wed Dec 19 23:39:27 2012 New Revision: 1424226 URL: http://svn.apache.org/viewvc?rev=1424226view=rev Log: Adding link to Aggregators javadoc in the examples page Modified: commons/proper/functor/trunk/src/site/xdoc/examples.xml Modified: commons/proper/functor/trunk/src/site/xdoc/examples.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/site/xdoc/examples.xml?rev=1424226r1=1424225r2=1424226view=diff == --- commons/proper/functor/trunk/src/site/xdoc/examples.xml (original) +++ commons/proper/functor/trunk/src/site/xdoc/examples.xml Wed Dec 19 23:39:27 2012 @@ -28,8 +28,9 @@ p This page contains basic examples using a href=apidocs/org/apache/commons/functor/Predicate.htmlPredicates/a, a href=apidocs/org/apache/commons/functor/Function.htmlFunctions/a, - a href=apidocs/org/apache/commons/functor/Procedure.htmlProcedures/a and - a href=apidocs/org/apache/commons/functor/generator/Generator.htmlGenerators/a. + a href=apidocs/org/apache/commons/functor/Procedure.htmlProcedures/a, + a href=apidocs/org/apache/commons/functor/generator/Generator.htmlGenerators/a and + a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.htmlAggregators/a. There are also examples using composition and more practical examples at the bottom of this page. /p
svn commit: r1445005 - /commons/proper/functor/trunk/api/pom.xml
Author: kinow Date: Tue Feb 12 00:47:23 2013 New Revision: 1445005 URL: http://svn.apache.org/r1445005 Log: Remove duplicated groupId Modified: commons/proper/functor/trunk/api/pom.xml Modified: commons/proper/functor/trunk/api/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/api/pom.xml?rev=1445005r1=1445004r2=1445005view=diff == --- commons/proper/functor/trunk/api/pom.xml (original) +++ commons/proper/functor/trunk/api/pom.xml Tue Feb 12 00:47:23 2013 @@ -22,7 +22,6 @@ artifactIdcommons-functor-parent/artifactId version1.0-SNAPSHOT/version /parent - groupIdorg.apache.commons/groupId artifactIdcommons-functor-api/artifactId nameCommons Functor API/name descriptionProvide the basic APIs/description
svn commit: r1445397 - in /commons/proper/functor/trunk: build-tools/pom.xml pom.xml
Author: kinow Date: Tue Feb 12 21:34:47 2013 New Revision: 1445397 URL: http://svn.apache.org/r1445397 Log: Setting groupId org.apache.commons in parent POM, and removing it from modules Modified: commons/proper/functor/trunk/build-tools/pom.xml commons/proper/functor/trunk/pom.xml Modified: commons/proper/functor/trunk/build-tools/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/build-tools/pom.xml?rev=1445397r1=1445396r2=1445397view=diff == --- commons/proper/functor/trunk/build-tools/pom.xml (original) +++ commons/proper/functor/trunk/build-tools/pom.xml Tue Feb 12 21:34:47 2013 @@ -21,9 +21,7 @@ version9/version /parent modelVersion4.0.0/modelVersion - groupIdorg.apache.commons/groupId artifactIdcommons-functor-build-tools/artifactId - version1.0-SNAPSHOT/version nameCommons Functor Build Tools/name descriptionProvide common setup, from http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html/description /project Modified: commons/proper/functor/trunk/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/pom.xml?rev=1445397r1=1445396r2=1445397view=diff == --- commons/proper/functor/trunk/pom.xml (original) +++ commons/proper/functor/trunk/pom.xml Tue Feb 12 21:34:47 2013 @@ -23,6 +23,7 @@ artifactIdcommons-parent/artifactId version28/version /parent + groupIdorg.apache.commons/groupId artifactIdcommons-functor-parent/artifactId version1.0-SNAPSHOT/version packagingpom/packaging
svn commit: r1482663 - in /commons/proper/functor/trunk: core/src/main/java/org/apache/commons/functor/core/Limit.java core/src/test/java/org/apache/commons/functor/core/TestLimit.java src/changes/cha
Author: kinow Date: Wed May 15 02:34:45 2013 New Revision: 1482663 URL: http://svn.apache.org/r1482663 Log: [FUNCTOR-27] add static method to Limit to create new instances Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/Limit.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/TestLimit.java commons/proper/functor/trunk/src/changes/changes.xml Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/Limit.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/Limit.java?rev=1482663r1=1482662r2=1482663view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/Limit.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/Limit.java Wed May 15 02:34:45 2013 @@ -121,4 +121,17 @@ public final class Limit implements Pred } //default == equals/hashCode due to statefulness + +// static methods +// + +/** + * Get a Limit instance for the specified value. + * @param count limit + * @return Limit + */ +public static Limit of(int count) { +return new Limit(count); +} + } Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/TestLimit.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/TestLimit.java?rev=1482663r1=1482662r2=1482663view=diff == --- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/TestLimit.java (original) +++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/TestLimit.java Wed May 15 02:34:45 2013 @@ -16,6 +16,7 @@ */ package org.apache.commons.functor.core; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -94,4 +95,13 @@ public class TestLimit extends BaseFunct assertObjectsAreNotEqual(new Limit(2), limit); assertTrue(!limit.equals(null)); } + +@Test +public void testLimits() { +Limit limit = new Limit(1); +assertEquals(Limit.of(1), limit); + +assertObjectsAreEqual(Limit.of(1), limit); +assertObjectsAreNotEqual(Limit.of(3), limit); +} } Modified: commons/proper/functor/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/changes/changes.xml?rev=1482663r1=1482662r2=1482663view=diff == --- commons/proper/functor/trunk/src/changes/changes.xml (original) +++ commons/proper/functor/trunk/src/changes/changes.xml Wed May 15 02:34:45 2013 @@ -23,6 +23,9 @@ /properties body release version=1.0 date=2012-??-?? description=First release. + action issue=FUNCTOR-27 dev=kinow +Add static Limit#of method to create new Limit's. + /action action issue=FUNCTOR-23 dev=simonetripodi due-to=Liviu Tudor aggregator.xml generates broken JavaDoc links /action
svn commit: r1508708 - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator: Generator.java util/CollectionTransformer.java
Author: kinow Date: Wed Jul 31 01:52:11 2013 New Revision: 1508708 URL: http://svn.apache.org/r1508708 Log: [FUNCTOR-28] Fix checkstyle errors in the generator package Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java?rev=1508708r1=1508707r2=1508708view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/Generator.java Wed Jul 31 01:52:11 2013 @@ -55,6 +55,7 @@ public interface GeneratorE { /** * Same as to(new CollectionTransformer(collection)). + * @param C the collection type * @param collection Collection to which my elements should be added * @return codecollection/code */ Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java?rev=1508708r1=1508707r2=1508708view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java Wed Jul 31 01:52:11 2013 @@ -27,6 +27,7 @@ import org.apache.commons.lang3.Validate * the constructor an ArrayList will be returned from the transform method. * * @param E the type of elements held in the adapted collection. + * @param C the type of the adapted collection * @since 1.0 * @version $Revision$ $Date$ */ @@ -72,6 +73,7 @@ public class CollectionTransformerE, C /** * Get a {@link CollectionTransformer} instance that simply returns any {@link Collection}. + * @param E the collection type * @return {@link CollectionTransformer} */ public static E CollectionTransformerE, CollectionE toCollection() {
svn commit: r1517162 - in /commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range: CharacterRange.java DoubleRange.java FloatRange.java IntegerRange.java
Author: kinow Date: Sat Aug 24 16:33:02 2013 New Revision: 1517162 URL: http://svn.apache.org/r1517162 Log: Move Iterable and Iterator to Range interface Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/LongRange.java commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/Range.java Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java?rev=1517162r1=1517161r2=1517162view=diff == --- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java (original) +++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/CharacterRange.java Sat Aug 24 16:33:02 2013 @@ -29,7 +29,7 @@ import org.apache.commons.lang3.Validate * @since 1.0 * @version $Revision: $ $Date: $ */ -public final class CharacterRange implements RangeCharacter, Integer, IterableCharacter, IteratorCharacter { +public final class CharacterRange implements RangeCharacter, Integer { // attributes // --- Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java?rev=1517162r1=1517161r2=1517162view=diff == --- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java (original) +++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/DoubleRange.java Sat Aug 24 16:33:02 2013 @@ -28,7 +28,7 @@ import org.apache.commons.lang3.Validate * @since 1.0 * @version $Revision: $ $Date: $ */ -public class DoubleRange extends NumericRangeDouble implements IterableDouble, IteratorDouble { +public class DoubleRange extends NumericRangeDouble { // attributes // --- Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java?rev=1517162r1=1517161r2=1517162view=diff == --- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java (original) +++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/FloatRange.java Sat Aug 24 16:33:02 2013 @@ -28,7 +28,7 @@ import org.apache.commons.lang3.Validate * @since 1.0 * @version $Revision: $ $Date: $ */ -public class FloatRange extends NumericRangeFloat implements IterableFloat, IteratorFloat { +public class FloatRange extends NumericRangeFloat { // attributes // --- Modified: commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java?rev=1517162r1=1517161r2=1517162view=diff == --- commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java (original) +++ commons/proper/functor/branches/generators-FUNCTOR-14/src/main/java/org/apache/commons/functor/range/IntegerRange.java Sat Aug 24 16:33:02 2013 @@ -28,7 +28,7 @@ import org.apache.commons.lang3.Validate * @since 1.0 * @version $Revision: 1385335 $ $Date: 2012-09-16 15:08:31 -0300 (Sun, 16 Sep 2012) $ */ -public class IntegerRange extends NumericRangeInteger implements
svn commit: r1522355 [5/5] - in /commons/proper/functor/trunk: core/src/main/java/org/apache/commons/functor/adapter/ core/src/main/java/org/apache/commons/functor/core/algorithm/ core/src/main/java/o
range = Ranges.longRange(-2, BoundType.OPEN, 2, +BoundType.CLOSED, 1); +assertEquals(Wrong string value, LongRange(-2, 2], 1, + range.toString()); +} + +@Test +public void testConstructorUsingSameEndpoint() { +EndpointLong uniqueEndpoint = new EndpointLong(10L, + BoundType.CLOSED); +try { +Ranges.longRange(uniqueEndpoint, uniqueEndpoint, 1L); +} catch (IllegalArgumentException e) { +fail(Not expected to get here); +} +} + +@Test +public void testInvalidRange() { +try { +Ranges.longRange(10, BoundType.OPEN, -5, BoundType.CLOSED, 10); +fail(Not expected to get here); +} catch (IllegalArgumentException e) { +// Do nothing +} +EndpointLong leftEndpoint = new EndpointLong(10L, BoundType.CLOSED); +EndpointLong rightEndpoint = new EndpointLong(-5L, BoundType.OPEN); +try { +Ranges.longRange(leftEndpoint, rightEndpoint, 1L); +fail(Not expected to get here); +} catch (IllegalArgumentException e) { +// Do nothing +} +} + +@Test +public void testDefaultStep() { +assertEquals(Invalid default step, Long.valueOf(-1L), + LongRange.DEFAULT_STEP.evaluate(10L, 1L)); +assertEquals(Invalid default step, Long.valueOf(1L), + LongRange.DEFAULT_STEP.evaluate(1L, 10L)); +} + +} \ No newline at end of file Modified: commons/proper/functor/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/changes/changes.xml?rev=1522355r1=1522354r2=1522355view=diff == --- commons/proper/functor/trunk/src/changes/changes.xml (original) +++ commons/proper/functor/trunk/src/changes/changes.xml Thu Sep 12 04:29:46 2013 @@ -23,6 +23,9 @@ /properties body release version=1.0 date=2012-??-?? description=First release. + action issue=FUNCTOR-14 dev=kinow +Enhancements on the Generator API + /action action issue=FUNCTOR-28 dev=kinow Fix checkstyle errors in the generator package /action Modified: commons/proper/functor/trunk/src/site/xdoc/examples.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/site/xdoc/examples.xml?rev=1522355r1=1522354r2=1522355view=diff == --- commons/proper/functor/trunk/src/site/xdoc/examples.xml (original) +++ commons/proper/functor/trunk/src/site/xdoc/examples.xml Thu Sep 12 04:29:46 2013 @@ -29,7 +29,8 @@ This page contains basic examples using a href=apidocs/org/apache/commons/functor/Predicate.htmlPredicates/a, a href=apidocs/org/apache/commons/functor/Function.htmlFunctions/a, a href=apidocs/org/apache/commons/functor/Procedure.htmlProcedures/a, - a href=apidocs/org/apache/commons/functor/generator/Generator.htmlGenerators/a and + a href=apidocs/org/apache/commons/functor/generator/Generator.htmlGenerators/a, + a href=apidocs/org/apache/commons/functor/range/Range.htmlRanges/a and a href=apidocs/org/apache/commons/functor/aggregator/Aggregator.htmlAggregators/a. There are also examples using composition and more practical examples at the bottom of this page. @@ -105,6 +106,129 @@ for( Integer number : numbers ) { /p /subsection +subsection name=Generators + p + Apache Functor includes other objects that you can can use to code in + a less imperative way, like emGenerators/em. In the following + example, we create an emInteger Generator/em that generates + integers from 1 to 4 (the right argument is non-inclusive). The + generator is wrapped within a emFiltered Generator/em that applies + the isEven predicate to each integer generated by the former generator. + Finally, we execute a emComposite Unary Procedure/em that uses + a function to double the value of the integer before printing it. + /p +source +Generatorlt;Integergt; integerGenerator = new IntegerRange(1, 5); // inclusive, exclusive + +UnaryPredicatelt;Integergt; isEven = new UnaryPredicatelt;Integergt;() { +public boolean test(Integer obj) { +return obj % 2 == 0; +} +}; + +FilteredGeneratorlt;Integergt; filteredGenerator = +new FilteredGeneratorlt;Integergt;(integerGenerator, isEven); + +UnaryFunctionlt;Integer, Integergt; doubler = new UnaryFunctionlt;Integer, Integergt;() { +public Integer evaluate(Integer obj) { +return obj * 2; +} +}; + +UnaryProcedurelt;Integergt; print = new UnaryProcedurelt;Integergt;() { +public void run(Integer obj
svn commit: r1532290 - /commons/trunks-proper/CHALLENGE.txt
Author: kinow Date: Tue Oct 15 11:20:29 2013 New Revision: 1532290 URL: http://svn.apache.org/r1532290 Log: (empty) Modified: commons/trunks-proper/CHALLENGE.txt Modified: commons/trunks-proper/CHALLENGE.txt URL: http://svn.apache.org/viewvc/commons/trunks-proper/CHALLENGE.txt?rev=1532290r1=1532289r2=1532290view=diff == --- commons/trunks-proper/CHALLENGE.txt (original) +++ commons/trunks-proper/CHALLENGE.txt Tue Oct 15 11:20:29 2013 @@ -24,12 +24,12 @@ el= email= exec= fileupload= -functor= +functor=kinow imaging= io=joehni jci= jcs= -jelly=polx +jelly=polx,kinow jexl= jxpath= lang=bayard,joehni
svn commit: r1536009 [2/2] - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor: adapter/ core/ core/comparator/ core/composite/
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java?rev=1536009r1=1536008r2=1536009view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinaryOr.java Sat Oct 26 17:55:27 2013 @@ -99,16 +99,14 @@ public final class BinaryOrL, R extend * {@inheritDoc} */ @Override -public boolean equals(Object that) { -return that == this || (that instanceof BinaryOr?, ? equals((BinaryOr?, ?) that)); -} - -/** - * Learn whether another BinaryOr is equal to this. - * @param that BinaryOr to test - * @return boolean - */ -public boolean equals(BinaryOr?, ? that) { +public boolean equals(Object obj) { +if (obj == this) { +return true; +} +if (!(obj instanceof BinaryOr?, ?)) { +return false; +} +BinaryOr?, ? that = (BinaryOr?, ?) obj; return getBinaryPredicateListEquals(that); } Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java?rev=1536009r1=1536008r2=1536009view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BinarySequence.java Sat Oct 26 17:55:27 2013 @@ -117,18 +117,15 @@ public class BinarySequenceL, R implem * {@inheritDoc} */ @Override -public final boolean equals(Object that) { -return that == this || (that instanceof BinarySequence?, ? equals((BinarySequence?, ?) that)); -} - -/** - * Learn whether another BinarySequence is equal to this. - * @param that BinarySequence to test - * @return boolean - */ -public final boolean equals(BinarySequence?, ? that) { -// by construction, list is never null -return null != that list.equals(that.list); +public final boolean equals(Object obj) { +if (obj == this) { +return true; +} +if (!(obj instanceof BinarySequence?, ?)) { +return false; +} +BinarySequence?, ? that = (BinarySequence?, ?) obj; +return this.list.equals(that.list); } /** Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java?rev=1536009r1=1536008r2=1536009view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryFunction.java Sat Oct 26 17:55:27 2013 @@ -137,21 +137,17 @@ public class CompositeBinaryFunctionL, * {@inheritDoc} */ @Override -public boolean equals(Object that) { -return that == this || (that instanceof CompositeBinaryFunction?, ?, ? - equals((CompositeBinaryFunction?, ?, ?) that)); -} - -/** - * Learn whether a given CompositeBinaryFunction is equal to this. - * @param that CompositeBinaryFunction to test - * @return boolean - */ -public boolean equals(CompositeBinaryFunction?, ?, ? that) { -return null != that - helper.f.equals(that.helper.f) - helper.g.equals(that.helper.g) - helper.h.equals(that.helper.h); +public boolean equals(Object obj) { +if (obj == this) { +return true; +} +if (!(obj instanceof CompositeBinaryFunction?, ?, ?)) { +return false; +} +CompositeBinaryFunction?, ?, ? that = (CompositeBinaryFunction?, ?, ?) obj; +return this.helper.f.equals(that.helper.f) + this.helper.g.equals(that.helper.g) + this.helper.h.equals(that.helper.h); } /** Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java URL:
svn commit: r1536047 - /commons/proper/functor/trunk/pom.xml
Author: kinow Date: Sun Oct 27 03:26:19 2013 New Revision: 1536047 URL: http://svn.apache.org/r1536047 Log: Update to latest commons-parent and fix maven compiler property name Modified: commons/proper/functor/trunk/pom.xml Modified: commons/proper/functor/trunk/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/pom.xml?rev=1536047r1=1536046r2=1536047view=diff == --- commons/proper/functor/trunk/pom.xml (original) +++ commons/proper/functor/trunk/pom.xml Sun Oct 27 03:26:19 2013 @@ -21,7 +21,7 @@ parent groupIdorg.apache.commons/groupId artifactIdcommons-parent/artifactId -version28/version +version32/version /parent groupIdorg.apache.commons/groupId artifactIdcommons-functor-parent/artifactId @@ -120,8 +120,8 @@ properties project.build.sourceEncodingUTF-8/project.build.sourceEncoding -maven.compile.source1.5/maven.compile.source -maven.compile.target1.5/maven.compile.target +maven.compiler.source1.5/maven.compiler.source +maven.compiler.target1.5/maven.compiler.target commons.componentidfunctor/commons.componentid commons.release.version1.0/commons.release.version commons.rc.versionRC1/commons.rc.version
svn commit: r1537901 - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core: collection/ comparator/
Author: kinow Date: Fri Nov 1 11:30:19 2013 New Revision: 1537901 URL: http://svn.apache.org/r1537901 Log: FUNCTOR-29 removing serializable from the collection and comparator packages Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/Size.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/ComparableComparator.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsEquivalent.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThan.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsGreaterThanOrEqual.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThan.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsLessThanOrEqual.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsNotEquivalent.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/IsWithinRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/Max.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/comparator/Min.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java?rev=1537901r1=1537900r2=1537901view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java Fri Nov 1 11:30:19 2013 @@ -16,7 +16,6 @@ */ package org.apache.commons.functor.core.collection; -import java.io.Serializable; import java.lang.reflect.Array; import java.util.Collection; @@ -35,15 +34,11 @@ import org.apache.commons.lang3.Validate * @since 1.0 * @version $Revision$ $Date$ */ -public final class IsElementOfL, R implements BinaryPredicateL, R, Serializable { +public final class IsElementOfL, R implements BinaryPredicateL, R { // static members //--- -/** - * serialVersionUID declaration. - */ -private static final long serialVersionUID = -7639051806015321070L; -/** + /** * A static {@link IsElementOf} instance reference. */ private static final IsElementOfObject, Object INSTANCE = new IsElementOfObject, Object(); Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java?rev=1537901r1=1537900r2=1537901view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java Fri Nov 1 11:30:19 2013 @@ -16,7 +16,6 @@ */ package org.apache.commons.functor.core.collection; -import java.io.Serializable; import java.lang.reflect.Array; import java.util.Collection; import java.util.Map; @@ -28,7 +27,7 @@ import org.apache.commons.lang3.Validate * @param A the predicate argument type. * @version $Revision$ $Date$ */ -public final class IsEmptyA implements PredicateA, Serializable { +public final class IsEmptyA implements PredicateA { // class variables // @@ -38,11 +37,6 @@ public final class IsEmptyA implements */ public static final IsEmptyObject INSTANCE = new IsEmptyObject(); -/** - * serialVersionUID declaration. - */ -private static final long serialVersionUID = 6555097970639642373L; - // constructor // /** Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/Size.java URL: http://svn.apache.org
svn commit: r1537906 [2/2] - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor: adapter/ core/ core/algorithm/
Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java?rev=1537906r1=1537905r2=1537906view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoUntil.java Fri Nov 1 11:47:33 2013 @@ -27,11 +27,6 @@ import org.apache.commons.functor.Nullar public class DoUntil extends PredicatedLoop { /** - * serialVersionUID declaration. - */ -private static final long serialVersionUID = -961919312045591167L; - -/** * Create a new DoUntil. * @param body to execute * @param test whether to keep going Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java?rev=1537906r1=1537905r2=1537906view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/DoWhile.java Fri Nov 1 11:47:33 2013 @@ -27,11 +27,6 @@ import org.apache.commons.functor.Nullar public class DoWhile extends PredicatedLoop { /** - * serialVersionUID declaration. - */ -private static final long serialVersionUID = -5439107633846597703L; - -/** * Create a new DoWhile. * @param body to execute * @param test whether to keep going Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java?rev=1537906r1=1537905r2=1537906view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FindWithinGenerator.java Fri Nov 1 11:47:33 2013 @@ -16,7 +16,6 @@ */ package org.apache.commons.functor.core.algorithm; -import java.io.Serializable; import java.util.NoSuchElementException; import org.apache.commons.functor.BinaryFunction; @@ -31,7 +30,7 @@ import org.apache.commons.functor.genera * @version $Revision$ $Date$ */ public final class FindWithinGeneratorE -implements BinaryFunctionGenerator? extends E, Predicate? super E, E, Serializable { +implements BinaryFunctionGenerator? extends E, Predicate? super E, E { /** * Basic instance. @@ -39,11 +38,6 @@ public final class FindWithinGeneratorE public static final FindWithinGeneratorObject INSTANCE = new FindWithinGeneratorObject(); /** - * serialVersionUID declaration. - */ -private static final long serialVersionUID = -2824239991638326134L; - -/** * Helper procedure. * * @param T the argument type. Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java?rev=1537906r1=1537905r2=1537906view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/algorithm/FoldLeft.java Fri Nov 1 11:47:33 2013 @@ -16,8 +16,6 @@ */ package org.apache.commons.functor.core.algorithm; -import java.io.Serializable; - import org.apache.commons.functor.BinaryFunction; import org.apache.commons.functor.Function; import org.apache.commons.functor.Procedure; @@ -32,12 +30,7 @@ import org.apache.commons.functor.genera * @param T the returned evaluation type. * @version $Revision$ $Date$ */ -public class FoldLeftT implements FunctionGeneratorT, T, BinaryFunctionGeneratorT, T, T, Serializable { - -/** - * serialVersionUID declaration. - */ -private static final long serialVersionUID = 2473542974105910450L; +public class FoldLeftT implements FunctionGeneratorT, T, BinaryFunctionGeneratorT, T, T { /** * Helper procedure. Modified:
svn commit: r1537907 - in /commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core: algorithm/ composite/
Author: kinow Date: Fri Nov 1 12:01:22 2013 New Revision: 1537907 URL: http://svn.apache.org/r1537907 Log: FUNCTOR-29 removing Serializable from test classes Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldRight.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestRecursiveEvaluation.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestUntilDo.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestWhileDo.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestAbstractLoopNullaryProcedure.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryFunction.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedBinaryProcedure.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryFunction.java commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/composite/TestTransformedNullaryProcedure.java Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java?rev=1537907r1=1537906r2=1537907view=diff == --- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java (original) +++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoUntil.java Fri Nov 1 12:01:22 2013 @@ -18,8 +18,6 @@ package org.apache.commons.functor.core. import static org.junit.Assert.assertEquals; -import java.io.Serializable; - import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.NullaryProcedure; import org.apache.commons.functor.core.Offset; @@ -51,8 +49,7 @@ public class TestDoUntil extends BaseFun // Classes // -static class Counter implements NullaryProcedure, Serializable { -private static final long serialVersionUID = 1L; +static class Counter implements NullaryProcedure { public void run() { count++; } Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java?rev=1537907r1=1537906r2=1537907view=diff == --- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java (original) +++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestDoWhile.java Fri Nov 1 12:01:22 2013 @@ -18,8 +18,6 @@ package org.apache.commons.functor.core. import static org.junit.Assert.assertEquals; -import java.io.Serializable; - import org.apache.commons.functor.BaseFunctorTest; import org.apache.commons.functor.NullaryProcedure; import org.apache.commons.functor.core.Limit; @@ -51,8 +49,7 @@ public class TestDoWhile extends BaseFun // Classes // -static class Counter implements NullaryProcedure, Serializable { -private static final long serialVersionUID = 1L; +static class Counter implements NullaryProcedure { public void run() { count++; } Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java?rev=1537907r1=1537906r2=1537907view=diff == --- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java (original) +++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/core/algorithm/TestFoldLeft.java Fri Nov 1 12:01:22 2013 @@ -18,7 +18,6 @@ package
svn commit: r1537909 - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core: collection/IsElementOf.java composite/BaseBinaryPredicateList.java composite/CompositeBinary
Author: kinow Date: Fri Nov 1 12:24:41 2013 New Revision: 1537909 URL: http://svn.apache.org/r1537909 Log: FUNCTOR-29 fix checkstyle errors (tabs) Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java?rev=1537909r1=1537908r2=1537909view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsElementOf.java Fri Nov 1 12:24:41 2013 @@ -38,7 +38,7 @@ public final class IsElementOfL, R imp // static members //--- - /** +/** * A static {@link IsElementOf} instance reference. */ private static final IsElementOfObject, Object INSTANCE = new IsElementOfObject, Object(); Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java?rev=1537909r1=1537908r2=1537909view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/BaseBinaryPredicateList.java Fri Nov 1 12:24:41 2013 @@ -30,7 +30,7 @@ import org.apache.commons.functor.Binary */ abstract class BaseBinaryPredicateListL, R implements BinaryPredicateL, R { - // attributes +// attributes // /** * A list to maintain all the adapted predicates. Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java?rev=1537909r1=1537908r2=1537909view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/CompositeBinaryPredicate.java Fri Nov 1 12:24:41 2013 @@ -32,7 +32,7 @@ import org.apache.commons.lang3.Validate */ public class CompositeBinaryPredicateL, R implements BinaryPredicateL, R { - /** Base hash integer used to shift hash. */ +/** Base hash integer used to shift hash. */ private static final int HASH_SHIFT = 4; /** Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java?rev=1537909r1=1537908r2=1537909view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/composite/NullaryNot.java Fri Nov 1 12:24:41 2013 @@ -26,7 +26,7 @@ import org.apache.commons.lang3.Validate */ public final class NullaryNot implements NullaryPredicate { - // attributes +// attributes // /** * The adapted predicate has to be negated.
svn commit: r1537908 - /commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java
Author: kinow Date: Fri Nov 1 12:24:04 2013 New Revision: 1537908 URL: http://svn.apache.org/r1537908 Log: FUNCTOR-29 Remove serializable test from base test class Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java Modified: commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java?rev=1537908r1=1537907r2=1537908view=diff == --- commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java (original) +++ commons/proper/functor/trunk/core/src/test/java/org/apache/commons/functor/BaseFunctorTest.java Fri Nov 1 12:24:04 2013 @@ -60,23 +60,6 @@ public abstract class BaseFunctorTest { } @Test -public final void testSerializeDeserializeThenCompare() throws Exception { -Object obj = makeFunctor(); -if (obj instanceof Serializable) { -ByteArrayOutputStream buffer = new ByteArrayOutputStream(); -ObjectOutputStream out = new ObjectOutputStream(buffer); -out.writeObject(obj); -out.close(); - -ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); -Object dest = in.readObject(); -in.close(); -assertEquals(obj != deserialize(serialize(obj)),obj,dest); -assertEquals(obj.hash != deserialize(serialize(obj.hash)),obj.hashCode(),dest.hashCode()); -} -} - -@Test public void testToStringIsOverridden() throws Exception { Object obj = makeFunctor(); assertNotNull(toString should never return null,obj.toString());
svn commit: r1537917 - /commons/proper/functor/trunk/src/changes/changes.xml
Author: kinow Date: Fri Nov 1 12:51:10 2013 New Revision: 1537917 URL: http://svn.apache.org/r1537917 Log: Updated changes.xml Modified: commons/proper/functor/trunk/src/changes/changes.xml Modified: commons/proper/functor/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/src/changes/changes.xml?rev=1537917r1=1537916r2=1537917view=diff == --- commons/proper/functor/trunk/src/changes/changes.xml (original) +++ commons/proper/functor/trunk/src/changes/changes.xml Fri Nov 1 12:51:10 2013 @@ -23,6 +23,15 @@ /properties body release version=1.0 date=2012-??-?? description=First release. + action issue=FUNCTOR-29 dev=kinow +Drop support to serialization + /action + action issue=FUNCTOR-11 dev=kinow +Reduce API clutter by removing or reducing scope of FunctorType.equals(FunctorType) methods + /action + action issue=FUNCTOR-25 dev=kinow +Update site after new project structure + /action action issue=FUNCTOR-14 dev=kinow Enhancements on the Generator API /action
svn commit: r1538565 - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection: FilteredIterable.java IsEmpty.java
Author: kinow Date: Mon Nov 4 11:39:54 2013 New Revision: 1538565 URL: http://svn.apache.org/r1538565 Log: Add Javadocs Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java?rev=1538565r1=1538564r2=1538565view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/FilteredIterable.java Mon Nov 4 11:39:54 2013 @@ -28,7 +28,6 @@ import org.apache.commons.functor.core.c * Adds a fluent filtering API to any {@link Iterable}. * * @version $Revision$ $Date$ - * * @param T the Iterable generic type */ public class FilteredIterableT implements IterableT { Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java?rev=1538565r1=1538564r2=1538565view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/core/collection/IsEmpty.java Mon Nov 4 11:39:54 2013 @@ -24,6 +24,8 @@ import org.apache.commons.functor.Predic import org.apache.commons.lang3.Validate; /** + * A {@link Predicate} that checks to see if the specified object is empty. + * * @param A the predicate argument type. * @version $Revision$ $Date$ */
svn commit: r1541567 - /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java
Author: kinow Date: Wed Nov 13 15:50:33 2013 New Revision: 1541567 URL: http://svn.apache.org/r1541567 Log: Add missing license header Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java?rev=1541567r1=1541566r2=1541567view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java Wed Nov 13 15:50:33 2013 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.commons.functor.range; import java.util.Collection;
svn commit: r1541597 - in /commons/proper/functor/trunk: build-tools/src/main/resources/org/apache/commons/functor/ core/src/main/java/org/apache/commons/functor/range/
Author: kinow Date: Wed Nov 13 16:38:00 2013 New Revision: 1541597 URL: http://svn.apache.org/r1541597 Log: Fix checkstyle errors for JavaDocs and Visibility Modifier (fixed using commons-lang as ref) Modified: commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle-suppressions.xml commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle.xml commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java Modified: commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle-suppressions.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle-suppressions.xml?rev=1541597r1=1541596r2=1541597view=diff == --- commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle-suppressions.xml (original) +++ commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle-suppressions.xml Wed Nov 13 16:38:00 2013 @@ -24,4 +24,5 @@ suppress checks=HiddenField files=.+\.java lines=0- / suppress checks=DesignForExtension files=.+\.java lines=0- / suppress checks=HideUtilityClassConstructor files=.+\.java lines=0- / + suppress checks=VisibilityModifier files=.+\.java lines=0- / /suppressions Modified: commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle.xml URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle.xml?rev=1541597r1=1541596r2=1541597view=diff == --- commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle.xml (original) +++ commons/proper/functor/trunk/build-tools/src/main/resources/org/apache/commons/functor/checkstyle.xml Wed Nov 13 16:38:00 2013 @@ -90,7 +90,9 @@ !-- Checks for Javadoc comments. -- !-- See http://checkstyle.sf.net/config_javadoc.html -- -module name=JavadocMethod/ +module name=JavadocMethod +property name=allowUndeclaredRTE value=true/ +/module module name=JavadocType/ module name=JavadocVariable/ module name=JavadocStyle/ Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java?rev=1541597r1=1541596r2=1541597view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java Wed Nov 13 16:38:00 2013 @@ -22,8 +22,8 @@ import org.apache.commons.lang3.Validate import org.apache.commons.lang3.builder.EqualsBuilder; /** - * Abstract {@link Range} - * + * Abstract {@link Range}. + * * @param T * @param S */ @@ -46,10 +46,10 @@ public abstract class AbstractRangeT ex /** * Create a new {@link AbstractRange}. - * - * @param leftEndpoint - * @param rightEndpoint - * @param step + * + * @param leftEndpoint left endpoint + * @param rightEndpoint right endpoint + * @param step increment step */ protected AbstractRange(EndpointT leftEndpoint, EndpointT rightEndpoint, S step) { super(); Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java?rev=1541597r1=1541596r2=1541597view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java Wed Nov 13 16:38:00 2013 @@ -33,9 +33,9 @@ public abstract class NumericRangeT ext /** * Construct a new {@link NumericRange}. - * @param leftEndpoint - * @param rightEndpoint - * @param step + * @param leftEndpoint left endpoint + * @param rightEndpoint right endpoint + * @param step increment step */ protected NumericRange(EndpointT leftEndpoint, EndpointT rightEndpoint, T step) { super(leftEndpoint
svn commit: r1541614 - /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java
Author: kinow Date: Wed Nov 13 17:06:01 2013 New Revision: 1541614 URL: http://svn.apache.org/r1541614 Log: Update Javadoc for CollectionTransformer Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java?rev=1541614r1=1541613r2=1541614view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/util/CollectionTransformer.java Wed Nov 13 17:06:01 2013 @@ -23,8 +23,7 @@ import org.apache.commons.functor.genera import org.apache.commons.lang3.Validate; /** - * Transforms a generator into a collection. If a collection is not passed into - * the constructor an ArrayList will be returned from the transform method. + * Transforms a generator into a collection. * * @param E the type of elements held in the adapted collection. * @param C the type of the adapted collection @@ -32,13 +31,6 @@ import org.apache.commons.lang3.Validate * @version $Revision$ $Date$ */ public class CollectionTransformerE, C extends Collection? super E implements FunctionGenerator? extends E, C { -/* - * TODO revisit this class... it could stand a more-descriptive name. Also, it's a little - * hard to say whether, for an instance constructed without a specific target collection, - * #evaluate() should return a new ArrayList for each call, or continue adding to - * a single ArrayList instance (the current behavior). - * Perhaps this is more a documentation issue than anything. - */ // instance methods //--- @@ -52,6 +44,7 @@ public class CollectionTransformerE, C /** * Create a new CollectionTransformer. * @param toFill Collection to fill + * @throws NullPointerException if the collection is {@code null} */ public CollectionTransformer(C toFill) { this.toFill = Validate.notNull(toFill, toFill); @@ -60,7 +53,10 @@ public class CollectionTransformerE, C // instance methods //--- /** - * {@inheritDoc} + * Run the {@link Generator} adding each element produced into the + * collection. + * @param generator the generator + * @return the C collection filled with the elements produced by the generator */ public C evaluate(Generator? extends E generator) { generator.run(new ProcedureE() {
svn commit: r1541662 - /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java
Author: kinow Date: Wed Nov 13 19:09:03 2013 New Revision: 1541662 URL: http://svn.apache.org/r1541662 Log: Back off from Java 7 methods in LongRange Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java?rev=1541662r1=1541661r2=1541662view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/LongRange.java Wed Nov 13 19:09:03 2013 @@ -189,7 +189,7 @@ public final class LongRange extends Num } public boolean hasNext() { -final int cmp = Long.compare(currentValue, rightEndpoint.getValue()); +final int cmp = Long.valueOf(currentValue).compareTo(rightEndpoint.getValue()); if (cmp == 0) { return rightEndpoint.getBoundType() == BoundType.CLOSED;
svn commit: r1541690 - in /commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor: generator/loop/IteratorToGeneratorAdapter.java range/AbstractRange.java range/IntegerRange.java r
Author: kinow Date: Wed Nov 13 20:14:17 2013 New Revision: 1541690 URL: http://svn.apache.org/r1541690 Log: Fix checkstyle issues Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/IntegerRange.java commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/NumericRange.java Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java?rev=1541690r1=1541689r2=1541690view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/generator/loop/IteratorToGeneratorAdapter.java Wed Nov 13 20:14:17 2013 @@ -27,44 +27,73 @@ import org.apache.commons.lang3.Validate * @version $Revision: 1508677 $ $Date: 2013-07-30 19:48:02 -0300 (Tue, 30 Jul 2013) $ */ public final class IteratorToGeneratorAdapterE extends LoopGeneratorE { +/** + * Helper iterator. + * @param E the type of elements in this iterator. + */ private static class EqualityIteratorE implements IteratorE { +/** + * Iterable that owns this iterator. + */ final Iterable? extends E owner; +/** + * Wrapped iterator. + */ final Iterator? extends E wrapped; - +/** + * Create a new EqualityIterator. + * @param owner iterable that owns this iterator + */ EqualityIterator(Iterable? extends E owner) { super(); this.owner = Validate.notNull(owner); this.wrapped = owner.iterator(); } +/** + * {@inheritDoc} + */ public boolean hasNext() { return wrapped.hasNext(); } +/** + * {@inheritDoc} + */ public E next() { return wrapped.next(); } +/** + * {@inheritDoc} + */ public void remove() { wrapped.remove(); } +/** + * {@inheritDoc} + */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } -if (obj instanceof EqualityIterator? == false) { +if (!(obj instanceof EqualityIterator)) { return false; } return ((EqualityIterator?) obj).owner.equals(owner); } - + +/** + * {@inheritDoc} + */ @Override public int hashCode() { -int result = 71 4; -result |= owner.hashCode(); -return result; +int hash = IteratorToGeneratorAdapater$EqualityIterator.hashCode(); +hash = 2; +hash ^= owner.hashCode(); +return hash; } } Modified: commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java URL: http://svn.apache.org/viewvc/commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java?rev=1541690r1=1541689r2=1541690view=diff == --- commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java (original) +++ commons/proper/functor/trunk/core/src/main/java/org/apache/commons/functor/range/AbstractRange.java Wed Nov 13 20:14:17 2013 @@ -48,6 +48,9 @@ public abstract class AbstractRangeT ex */ protected final S step; +/** + * Function to implement the taking of a step. + */ private final BinaryFunctionT, S, T nextValue; /** @@ -58,7 +61,8 @@ public abstract class AbstractRangeT ex * @param step increment step * @param nextValue function to implement the taking of a step */ -protected AbstractRange(EndpointT leftEndpoint, EndpointT rightEndpoint, S step, BinaryFunctionT, S, T nextValue) { +protected AbstractRange(EndpointT leftEndpoint, EndpointT rightEndpoint, S step, +BinaryFunctionT, S, T nextValue) { super(); this.leftEndpoint = Validate.notNull(leftEndpoint, Left Endpoint argument must not be null); this.rightEndpoint = Validate.notNull(rightEndpoint, Right Endpoint argument must not be null); @@ -121,7 +125,7 @@ public abstract class
svn commit: r1569028 - in /commons/proper/lang/trunk/src: changes/ main/java/org/apache/commons/lang3/builder/ test/java/org/apache/commons/lang3/builder/
Author: kinow Date: Mon Feb 17 15:45:17 2014 New Revision: 1569028 URL: http://svn.apache.org/r1569028 Log: LANG-621: ReflectionToStringBuilder.toString does not debug 3rd party object fields within 3rd party object. Suggested by Philip Hodges. Final patch from Thomas Neidhart. Added: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/RecursiveToStringStyle.java commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/RecursiveToStringStyleTest.java Modified: commons/proper/lang/trunk/src/changes/changes.xml commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java Modified: commons/proper/lang/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1569028r1=1569027r2=1569028view=diff == --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original) +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Mon Feb 17 15:45:17 2014 @@ -22,6 +22,7 @@ body release version=3.3 date=TBA description=Bugfix and Feature release +action issue=LANG-621 type=fix dev=kinow due-to=Philip Hodges, Thomas NeidhartReflectionToStringBuilder.toString does not debug 3rd party object fields within 3rd party object/action action issue=LANG-955 type=add dev=britter due-to=Adam HooperAdd methods for removing all invalid characters according to XML 1.0 and XML 1.1 in an input string to StringEscapeUtils/action action issue=LANG-977 type=fix dev=britter due-to=Chris KarcherNumericEntityEscaper incorrectly encodes supplementary characters/action action issue=LANG-973 type=fix dev=sebbMake some private fields final/action Added: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/RecursiveToStringStyle.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/RecursiveToStringStyle.java?rev=1569028view=auto == --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/RecursiveToStringStyle.java (added) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/RecursiveToStringStyle.java Mon Feb 17 15:45:17 2014 @@ -0,0 +1,84 @@ +package org.apache.commons.lang3.builder; + +import java.util.Collection; + +import org.apache.commons.lang3.ClassUtils; + +/** + * pWorks with {@link ToStringBuilder} to create a deep codetoString/code./p + * + * pTo use this class write code as follows:/p + * + * pre + * public class Job { + * String title; + * ... + * } + * + * public class Person { + * String name; + * int age; + * boolean smoker; + * Job job; + * + * ... + * + * public String toString() { + * return new ReflectionToStringBuilder(this, new RecursiveToStringStyle()).toString(); + * } + * } + * /pre + * + * pThis will produce a toString of the format: + * codePerson@7f54[name=Stephen,age=29,smoker=false,job=Job@43cd2[title=Manager]]/code/p + * + * @since 3.2 + * @version $Id$ + */ +public class RecursiveToStringStyle extends ToStringStyle { + +/** + * Required for serialization support. + * + * @see java.io.Serializable + */ +private static final long serialVersionUID = 1L; + +/** + * pConstructor./p + */ +public RecursiveToStringStyle() { +super(); +} + +@Override +public void appendDetail(StringBuffer buffer, String fieldName, Object value) { +if (!ClassUtils.isPrimitiveWrapper(value.getClass()) +!String.class.equals(value.getClass()) +accept(value.getClass())) { +buffer.append(ReflectionToStringBuilder.toString(value, this)); +} else { +super.appendDetail(buffer, fieldName, value); +} +} + +@Override +protected void appendDetail(StringBuffer buffer, String fieldName, Collection? coll) { +appendClassName(buffer, coll); +appendIdentityHashCode(buffer, coll); +appendDetail(buffer, fieldName, coll.toArray()); +} + +/** + * Returns whether or not to recursively format the given codeClass/code. + * By default, this method always returns {@code true}, but may be overwritten by + * sub-classes to filter specific classes. + * + * @param clazz + *The class to test. + * @return Whether or not to recursively format the given codeClass/code. + */ +protected boolean accept(final Class? clazz) { +return true; +} +} Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java?rev=1569028r1=1569027r2
svn commit: r898710 - in /websites/production/commons/content/proper/commons-email: ./ apidocs/ apidocs/org/apache/commons/mail/ apidocs/org/apache/commons/mail/class-use/ apidocs/org/apache/commons/m
Author: kinow Date: Fri Feb 21 00:30:44 2014 New Revision: 898710 Log: Site checkin for project Apache Commons Email [This commit notification would consist of 55 parts, which exceeds the limit of 50 ones, so it was shortened to the summary.]
svn commit: r898711 - in /websites/production/commons/content/proper/commons-email: pmd.xml rat-report.html surefire-report.html
Author: kinow Date: Fri Feb 21 00:33:54 2014 New Revision: 898711 Log: Site checkin for project Apache Commons Email Modified: websites/production/commons/content/proper/commons-email/pmd.xml websites/production/commons/content/proper/commons-email/rat-report.html websites/production/commons/content/proper/commons-email/surefire-report.html Modified: websites/production/commons/content/proper/commons-email/pmd.xml == Binary files - no diff available. Modified: websites/production/commons/content/proper/commons-email/rat-report.html == --- websites/production/commons/content/proper/commons-email/rat-report.html (original) +++ websites/production/commons/content/proper/commons-email/rat-report.html Fri Feb 21 00:33:54 2014 @@ -262,7 +262,7 @@ * Summary --- -Generated at: 2014-02-21T00:25:06+00:00 +Generated at: 2014-02-21T00:33:13+00:00 Notes: 4 Binaries: 8 Archives: 0 Modified: websites/production/commons/content/proper/commons-email/surefire-report.html == --- websites/production/commons/content/proper/commons-email/surefire-report.html (original) +++ websites/production/commons/content/proper/commons-email/surefire-report.html Fri Feb 21 00:33:54 2014 @@ -289,7 +289,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td9.433/td/tr/tablebr / +td12.85/td/tr/tablebr / pNote: failures are anticipated and checked for with assertions while errors are unanticipated./pbr //div div class=section h2Package Lista name=Package_List/a/h2a name=Package_List/a @@ -310,7 +310,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td1.684/td/tr +td3.599/td/tr tr class=a tda href=#org.apache.commons.mail.utilorg.apache.commons.mail.util/a/td td9/td @@ -318,7 +318,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.084/td/tr +td0.071/td/tr tr class=b tda href=#org.apache.commons.mailorg.apache.commons.mail/a/td td150/td @@ -326,7 +326,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td7.665/td/tr/tablebr / +td9.18/td/tr/tablebr / pNote: package statistics are not computed recursively, they only sum up all of its testsuites numbers./p div class=section h3org.apache.commons.mail.resolvera name=org.apache.commons.mail.resolver/a/h3a name=org.apache.commons.mail.resolver/a @@ -348,7 +348,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td1.283/td/tr +td2.645/td/tr tr class=a tda href=#org.apache.commons.mail.resolverDataSourceCompositeResolverTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mail.resolverDataSourceCompositeResolverTestDataSourceCompositeResolverTest/a/td @@ -357,7 +357,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.401/td/tr +td0.954/td/tr tr class=b tda href=#org.apache.commons.mail.resolverDataSourceFileResolverTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mail.resolverDataSourceFileResolverTestDataSourceFileResolverTest/a/td @@ -396,7 +396,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.084/td/tr/table/div +td0.071/td/tr/table/div div class=section h3org.apache.commons.maila name=org.apache.commons.mail/a/h3a name=org.apache.commons.mail/a table border=1 class=bodyTable @@ -417,7 +417,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.404/td/tr +td0.353/td/tr tr class=a tda href=#org.apache.commons.mailInvalidInternetAddressTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailInvalidInternetAddressTestInvalidInternetAddressTest/a/td @@ -435,7 +435,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td4.713/td/tr +td6.249/td/tr tr class=a tda href=#org.apache.commons.mailHtmlEmailTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailHtmlEmailTestHtmlEmailTest/a/td @@ -444,7 +444,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td1.203/td/tr +td1.321/td/tr tr class=b tda href=#org.apache.commons.mailEmailUtilsTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailEmailUtilsTestEmailUtilsTest/a/td @@ -462,7 +462,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.021/td/tr +td0.005/td/tr tr class=b tda href=#org.apache.commons.mailSendWithAttachmentsTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailSendWithAttachmentsTestSendWithAttachmentsTest/a/td @@ -471,7 +471,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.091/td/tr +td0.059/td/tr tr class=a tda href=#org.apache.commons.mailEmailTestimg src=images
svn commit: r898712 - in /websites/production/commons/content/proper/commons-email: pmd.xml rat-report.html surefire-report.html
Author: kinow Date: Fri Feb 21 00:36:10 2014 New Revision: 898712 Log: Site checkin for project Apache Commons Email Modified: websites/production/commons/content/proper/commons-email/pmd.xml websites/production/commons/content/proper/commons-email/rat-report.html websites/production/commons/content/proper/commons-email/surefire-report.html Modified: websites/production/commons/content/proper/commons-email/pmd.xml == Binary files - no diff available. Modified: websites/production/commons/content/proper/commons-email/rat-report.html == --- websites/production/commons/content/proper/commons-email/rat-report.html (original) +++ websites/production/commons/content/proper/commons-email/rat-report.html Fri Feb 21 00:36:10 2014 @@ -262,7 +262,7 @@ * Summary --- -Generated at: 2014-02-21T00:33:13+00:00 +Generated at: 2014-02-21T00:35:21+00:00 Notes: 4 Binaries: 8 Archives: 0 Modified: websites/production/commons/content/proper/commons-email/surefire-report.html == --- websites/production/commons/content/proper/commons-email/surefire-report.html (original) +++ websites/production/commons/content/proper/commons-email/surefire-report.html Fri Feb 21 00:36:10 2014 @@ -289,7 +289,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td12.85/td/tr/tablebr / +td12.052/td/tr/tablebr / pNote: failures are anticipated and checked for with assertions while errors are unanticipated./pbr //div div class=section h2Package Lista name=Package_List/a/h2a name=Package_List/a @@ -310,7 +310,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td3.599/td/tr +td3.518/td/tr tr class=a tda href=#org.apache.commons.mail.utilorg.apache.commons.mail.util/a/td td9/td @@ -318,7 +318,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.071/td/tr +td0.064/td/tr tr class=b tda href=#org.apache.commons.mailorg.apache.commons.mail/a/td td150/td @@ -326,7 +326,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td9.18/td/tr/tablebr / +td8.47/td/tr/tablebr / pNote: package statistics are not computed recursively, they only sum up all of its testsuites numbers./p div class=section h3org.apache.commons.mail.resolvera name=org.apache.commons.mail.resolver/a/h3a name=org.apache.commons.mail.resolver/a @@ -348,7 +348,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td2.645/td/tr +td2.577/td/tr tr class=a tda href=#org.apache.commons.mail.resolverDataSourceCompositeResolverTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mail.resolverDataSourceCompositeResolverTestDataSourceCompositeResolverTest/a/td @@ -357,7 +357,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.954/td/tr +td0.941/td/tr tr class=b tda href=#org.apache.commons.mail.resolverDataSourceFileResolverTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mail.resolverDataSourceFileResolverTestDataSourceFileResolverTest/a/td @@ -396,7 +396,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.071/td/tr/table/div +td0.064/td/tr/table/div div class=section h3org.apache.commons.maila name=org.apache.commons.mail/a/h3a name=org.apache.commons.mail/a table border=1 class=bodyTable @@ -417,7 +417,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.353/td/tr +td0.365/td/tr tr class=a tda href=#org.apache.commons.mailInvalidInternetAddressTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailInvalidInternetAddressTestInvalidInternetAddressTest/a/td @@ -435,7 +435,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td6.249/td/tr +td5.747/td/tr tr class=a tda href=#org.apache.commons.mailHtmlEmailTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailHtmlEmailTestHtmlEmailTest/a/td @@ -444,7 +444,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td1.321/td/tr +td1.076/td/tr tr class=b tda href=#org.apache.commons.mailEmailUtilsTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailEmailUtilsTestEmailUtilsTest/a/td @@ -462,7 +462,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.005/td/tr +td0.019/td/tr tr class=b tda href=#org.apache.commons.mailSendWithAttachmentsTestimg src=images/icon_success_sml.gif alt= //a/td tda href=#org.apache.commons.mailSendWithAttachmentsTestSendWithAttachmentsTest/a/td @@ -471,7 +471,7 @@ function toggleDisplay(elementId) { td0/td td0/td td100%/td -td0.059/td/tr +td0.063/td/tr tr class=a tda href=#org.apache.commons.mailEmailTestimg src=images
svn commit: r1645101 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/StringUtils.java test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
Author: kinow Date: Sat Dec 13 02:00:18 2014 New Revision: 1645101 URL: http://svn.apache.org/r1645101 Log: LANG-1077 StringUtils.ordinalIndexOf(aa, aa, 2) != 3 in StringUtils Modified: commons/proper/lang/trunk/src/changes/changes.xml commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java Modified: commons/proper/lang/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1645101r1=1645100r2=1645101view=diff == --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original) +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Sat Dec 13 02:00:18 2014 @@ -22,6 +22,7 @@ body release version=3.4 date=tba description=tba +action issue=LANG-1077 type=fix dev=kinow due-to=haiyang liStringUtils.ordinalIndexOf(aa, aa, 2) != 3 in StringUtils/action action issue=LANG-1072 type=fix dev=sebb due-to=haiyang liDuplicated 0x check in createBigInteger in NumberUtils/action action issue=LANG-1064 type=fix dev=djones due-to=B.J. HerbisonStringUtils.abbreviate description doesn't agree with the examples/action action issue=LANG-1052 type=add dev=britter due-to=Jan MatèrneMultiline recursive to string style/action Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1645101r1=1645100r2=1645101view=diff == --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Sat Dec 13 02:00:18 2014 @@ -1023,9 +1023,9 @@ public class StringUtils { int index = lastIndex ? str.length() : INDEX_NOT_FOUND; do { if (lastIndex) { -index = CharSequenceUtils.lastIndexOf(str, searchStr, index - 1); +index = CharSequenceUtils.lastIndexOf(str, searchStr, index - searchStr.length()); } else { -index = CharSequenceUtils.indexOf(str, searchStr, index + 1); +index = CharSequenceUtils.indexOf(str, searchStr, index + searchStr.length()); } if (index 0) { return index; Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java?rev=1645101r1=1645100r2=1645101view=diff == --- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java (original) +++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java Sat Dec 13 02:00:18 2014 @@ -1006,6 +1006,9 @@ public class StringUtilsEqualsIndexOfTes assertEquals(7, StringUtils.ordinalIndexOf(a, a, 8)); assertEquals(8, StringUtils.ordinalIndexOf(a, a, 9)); assertEquals(-1, StringUtils.ordinalIndexOf(a, a, 10)); + +assertEquals(3, StringUtils.ordinalIndexOf(aa, aa, 2)); +assertEquals(-1, StringUtils.ordinalIndexOf(aa, aa, 3)); } }
[text] SANDBOX-485 Add Hamming distance
Repository: commons-text Updated Branches: refs/heads/master 413aeeb1a - 87b789fbe SANDBOX-485 Add Hamming distance Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/87b789fb Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/87b789fb Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/87b789fb Branch: refs/heads/master Commit: 87b789fbec0360a7e2c54f7cb45225e238530ee8 Parents: 413aeeb Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Dec 13 01:09:40 2014 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Dec 13 01:12:01 2014 -0200 -- src/changes/changes.xml | 1 + .../text/similarity/HammingDistance.java| 77 .../text/similarity/HammingDistanceTest.java| 58 +++ 3 files changed, 136 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/87b789fb/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 416f579..d8c3fdf 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-485 type=add dev=kinowAdd Hamming distance/action /release /body http://git-wip-us.apache.org/repos/asf/commons-text/blob/87b789fb/src/main/java/org/apache/commons/text/similarity/HammingDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/HammingDistance.java b/src/main/java/org/apache/commons/text/similarity/HammingDistance.java new file mode 100644 index 000..13621b4 --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/HammingDistance.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +/** + * p + * The hamming distance between two strings of equal length is the number of + * positions at which the corresponding symbols are different. + * /p + * + * p + * For further explanation about the hamming distance, take a look at its + * Wikipedia page at http://en.wikipedia.org/wiki/Hamming_distance. + * /p + * + * @since 1.0 + */ +public class HammingDistance implements StringMetricInteger { + +/** + * pFind the hamming distance between two strings with the same + * length./p + * + * pThe distance starts with zero, and for each occurrence of a + * different character in either String, it increments the distance + * by 1, and finally return its value./p + * + * pre + * distance.compare(, ) = 0 + * distance.compare(pappa, pappa) = 0 + * distance.compare(1011101, 101) = 1 + * distance.compare(ATCG, ACCC) = 2 + * distance.compare(karolin, kerstin = 3 + * /pre + * + * @param left the first string, must not be null + * @param right the second string, must not be null + * @return distance + * @throws IllegalArgumentException if either String input {@code null} or + * if they do not have the same length + */ +@Override +public Integer compare(CharSequence left, CharSequence right) { +if (left == null || right == null) { +throw new IllegalArgumentException(Strings must not be null); +} + +if (left.length() != right.length()) { +throw new IllegalArgumentException(Strings must have the same length); +} + +int distance = 0; + +for (int i = 0; i left.length(); i++) { +if (left.charAt(i) != right.charAt(i)) { +distance++; +} +} + +return distance; +} + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/87b789fb/src/test/java/org/apache/commons/text/similarity/HammingDistanceTest.java -- diff
[text] SANDBOX-483 Add changes and fix old Javadocs from [lang] that remained after the code porting
Repository: commons-text Updated Branches: refs/heads/master 87b789fbe - 7570eb016 SANDBOX-483 Add changes and fix old Javadocs from [lang] that remained after the code porting Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/7570eb01 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/7570eb01 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/7570eb01 Branch: refs/heads/master Commit: 7570eb0163cab027b444ca55e6d4c9768fcd0d34 Parents: 87b789f Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Dec 13 01:21:11 2014 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Dec 13 01:21:11 2014 -0200 -- src/changes/changes.xml | 1 + .../commons/text/similarity/FuzzyDistance.java | 20 ++-- .../text/similarity/JaroWrinklerDistance.java | 103 +-- .../text/similarity/LevenshteinDistance.java| 44 4 files changed, 83 insertions(+), 85 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/7570eb01/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d8c3fdf..f890519 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -23,6 +23,7 @@ release version=1.0 date=tba description=tba action issue=SANDBOX-485 type=add dev=kinowAdd Hamming distance/action +action issue=SANDBOX-483 type=add dev=kinow due-to=britterIncorporate String algorithms from Commons Lang/action /release /body http://git-wip-us.apache.org/repos/asf/commons-text/blob/7570eb01/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java b/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java index 8e9228a..f4299ea 100644 --- a/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java @@ -26,6 +26,10 @@ import java.util.Locale; * indicates a higher similarity. * /p * + * p + * This code has been adapted from Apache Commons Lang 3.3. + * /p + * * @since 1.0 */ public class FuzzyDistance implements StringMetricInteger { @@ -54,14 +58,14 @@ public class FuzzyDistance implements StringMetricInteger { * /p * * pre - * StringUtils.getFuzzyDistance(null, null, null) = IllegalArgumentException - * StringUtils.getFuzzyDistance(, , Locale.ENGLISH) = 0 - * StringUtils.getFuzzyDistance(Workshop, b, Locale.ENGLISH) = 0 - * StringUtils.getFuzzyDistance(Room, o, Locale.ENGLISH) = 1 - * StringUtils.getFuzzyDistance(Workshop, w, Locale.ENGLISH) = 1 - * StringUtils.getFuzzyDistance(Workshop, ws, Locale.ENGLISH) = 2 - * StringUtils.getFuzzyDistance(Workshop, wo, Locale.ENGLISH) = 4 - * StringUtils.getFuzzyDistance(Apache Software Foundation, asf, Locale.ENGLISH) = 3 + * distance.getFuzzyDistance(null, null, null) = IllegalArgumentException + * distance.getFuzzyDistance(, , Locale.ENGLISH) = 0 + * distance.getFuzzyDistance(Workshop, b, Locale.ENGLISH) = 0 + * distance.getFuzzyDistance(Room, o, Locale.ENGLISH) = 1 + * distance.getFuzzyDistance(Workshop, w, Locale.ENGLISH) = 1 + * distance.getFuzzyDistance(Workshop, ws, Locale.ENGLISH) = 2 + * distance.getFuzzyDistance(Workshop, wo, Locale.ENGLISH) = 4 + * distance.getFuzzyDistance(Apache Software Foundation, asf, Locale.ENGLISH) = 3 * /pre * * @param term a full term that should be matched against, must not be null http://git-wip-us.apache.org/repos/asf/commons-text/blob/7570eb01/src/main/java/org/apache/commons/text/similarity/JaroWrinklerDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/JaroWrinklerDistance.java b/src/main/java/org/apache/commons/text/similarity/JaroWrinklerDistance.java index 3a94969..67aa2b8 100644 --- a/src/main/java/org/apache/commons/text/similarity/JaroWrinklerDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/JaroWrinklerDistance.java @@ -49,20 +49,20 @@ public class JaroWrinklerDistance implements StringMetricDouble { * /p * * pre
[text] Update .gitignore, using [lang]'s as basis
Repository: commons-text Updated Branches: refs/heads/master 7570eb016 - 182154e5b Update .gitignore, using [lang]'s as basis Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/182154e5 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/182154e5 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/182154e5 Branch: refs/heads/master Commit: 182154e5bd4f7f52ffba3728fc03987ff0afda4c Parents: 7570eb0 Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Dec 13 01:22:12 2014 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Dec 13 01:22:12 2014 -0200 -- .gitignore | 16 +++- 1 file changed, 15 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/182154e5/.gitignore -- diff --git a/.gitignore b/.gitignore index c2b8af5..338a65b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,17 @@ -target/ +# Maven build files +target +*.log +maven-eclipse.xml +build.properties site-content +# IntelliJ IDEA files +.idea +.iws +*.iml +*.ipr + +# Eclipse files +.settings +.classpath +.project
svn commit: r1645483 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/ArrayUtils.java
Author: kinow Date: Sun Dec 14 18:22:06 2014 New Revision: 1645483 URL: http://svn.apache.org/r1645483 Log: LANG-1073 Read wrong component type of array in add in ArrayUtils Modified: commons/proper/lang/trunk/src/changes/changes.xml commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Modified: commons/proper/lang/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1645483r1=1645482r2=1645483view=diff == --- commons/proper/lang/trunk/src/changes/changes.xml [utf-8] (original) +++ commons/proper/lang/trunk/src/changes/changes.xml [utf-8] Sun Dec 14 18:22:06 2014 @@ -22,6 +22,7 @@ body release version=3.4 date=tba description=tba +action issue=LANG-1073 type=fix dev=kinow due-to=haiyang liRead wrong component type of array in add in ArrayUtils/action action issue=LANG-1077 type=fix dev=kinow due-to=haiyang liStringUtils.ordinalIndexOf(aa, aa, 2) != 3 in StringUtils/action action issue=LANG-1072 type=fix dev=sebb due-to=haiyang liDuplicated 0x check in createBigInteger in NumberUtils/action action issue=LANG-1064 type=fix dev=djones due-to=B.J. HerbisonStringUtils.abbreviate description doesn't agree with the examples/action Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java?rev=1645483r1=1645482r2=1645483view=diff == --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Sun Dec 14 18:22:06 2014 @@ -4008,7 +4008,7 @@ public class ArrayUtils { public static T T[] add(final T[] array, final T element) { Class? type; if (array != null){ -type = array.getClass(); +type = array.getClass().getComponentType(); } else if (element != null) { type = element.getClass(); } else {
[text] Document .gitignore strategy
Repository: commons-text Updated Branches: refs/heads/master 9b1b436b2 - 1a236bada Document .gitignore strategy Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/1a236bad Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/1a236bad Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/1a236bad Branch: refs/heads/master Commit: 1a236bada5163388a3051083fba454b19edc1fb8 Parents: 9b1b436 Author: Bruno P. Kinoshita ki...@apache.org Authored: Mon Dec 15 23:03:46 2014 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Mon Dec 15 23:03:46 2014 -0200 -- .gitignore | 1 + 1 file changed, 1 insertion(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/1a236bad/.gitignore -- diff --git a/.gitignore b/.gitignore index c2b8af5..c8130e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +# Include only files generated during build, and avoid IDE specific files target/ site-content
[2/2] [text] Finish adapting code to commons-text, adding missing header and fixing Javadocs
Finish adapting code to commons-text, adding missing header and fixing Javadocs Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/a7e88eef Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/a7e88eef Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/a7e88eef Branch: refs/heads/myers-algo Commit: a7e88eef1a77649648a7fc6e9015448eb97c4572 Parents: cca1f19 Author: Bruno P. Kinoshita ki...@apache.org Authored: Thu Feb 5 00:33:14 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Thu Feb 5 00:33:14 2015 -0200 -- .../commons/text/diff/CommandVisitor.java | 12 +- .../apache/commons/text/diff/DeleteCommand.java | 6 +- .../apache/commons/text/diff/EditCommand.java | 9 +- .../apache/commons/text/diff/EditScript.java| 7 +- .../apache/commons/text/diff/InsertCommand.java | 6 +- .../apache/commons/text/diff/KeepCommand.java | 6 +- .../commons/text/diff/ReplacementsFinder.java | 10 +- .../commons/text/diff/ReplacementsHandler.java | 3 +- .../commons/text/diff/StringsComparator.java| 137 +++ .../apache/commons/text/diff/package-info.java | 3 + 10 files changed, 147 insertions(+), 52 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/a7e88eef/src/main/java/org/apache/commons/text/diff/CommandVisitor.java -- diff --git a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java index ae3833c..d73dde8 100644 --- a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java +++ b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java @@ -28,14 +28,17 @@ package org.apache.commons.text.diff; * it will perform the loop over all commands in the script and the * proper methods of the user class will be called as the commands are * encountered. + * /p * p * The implementation of the user visitor class will depend on the * need. Here are two examples. + * /p * p * The first example is a visitor that build the longest common * subsequence: + * /p * pre - * import org.apache.commons.collections4.comparators.sequence.CommandVisitor; + * import org.apache.commons.text.diff.CommandVisitor; * * import java.util.ArrayList; * @@ -67,7 +70,7 @@ package org.apache.commons.text.diff; * The second example is a visitor that shows the commands and the way * they transform the first sequence into the second one: * pre - * import org.apache.commons.collections4.comparators.sequence.CommandVisitor; + * import org.apache.commons.text.diff.CommandVisitor; * * import java.util.Arrays; * import java.util.ArrayList; @@ -97,7 +100,7 @@ package org.apache.commons.text.diff; * } * * private void display(String commandName, Object object) { - * System.out.println(commandName + + object + - + this); + * System.out.println(commandName + + object + : + this); * } * * public String toString() { @@ -114,8 +117,7 @@ package org.apache.commons.text.diff; * } * /pre * - * @since 4.0 - * @version $Id: CommandVisitor.java 1477760 2013-04-30 18:34:03Z tn $ + * @since 1.0 */ public interface CommandVisitorT { http://git-wip-us.apache.org/repos/asf/commons-text/blob/a7e88eef/src/main/java/org/apache/commons/text/diff/DeleteCommand.java -- diff --git a/src/main/java/org/apache/commons/text/diff/DeleteCommand.java b/src/main/java/org/apache/commons/text/diff/DeleteCommand.java index 0de3a43..7494002 100644 --- a/src/main/java/org/apache/commons/text/diff/DeleteCommand.java +++ b/src/main/java/org/apache/commons/text/diff/DeleteCommand.java @@ -24,12 +24,12 @@ package org.apache.commons.text.diff; * transforming the first sequence into the second sequence uses an instance of * this class to represent the deletion of this object. The objects embedded in * these type of commands always come from the first sequence. + * /p * - * @see SequencesComparator + * @see StringsComparator * @see EditScript * - * @since 4.0 - * @version $Id: DeleteCommand.java 1477760 2013-04-30 18:34:03Z tn $ + * @since 1.0 */ public class DeleteCommandT extends EditCommandT { http://git-wip-us.apache.org/repos/asf/commons-text/blob/a7e88eef/src/main/java/org/apache/commons/text/diff/EditCommand.java -- diff --git a/src/main/java/org/apache/commons/text/diff/EditCommand.java b/src/main/java/org/apache/commons/text/diff/EditCommand.java index 7c5ff76..627db4d 100644 --- a/src/main/java/org/apache/commons/text/diff/EditCommand.java +++
[1/2] [text] Migrating Myers algorithm from [collections]
Repository: commons-text Updated Branches: refs/heads/myers-algo [created] a7e88eef1 Migrating Myers algorithm from [collections] Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/cca1f199 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/cca1f199 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/cca1f199 Branch: refs/heads/myers-algo Commit: cca1f19918760d4e538ff4d70d875878418f6f1a Parents: 37c7804 Author: Bruno P. Kinoshita ki...@apache.org Authored: Sun Dec 14 23:41:43 2014 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sun Dec 14 23:41:43 2014 -0200 -- .../commons/text/diff/CommandVisitor.java | 143 ++ .../apache/commons/text/diff/DeleteCommand.java | 55 .../apache/commons/text/diff/EditCommand.java | 82 ++ .../apache/commons/text/diff/EditScript.java| 133 + .../apache/commons/text/diff/InsertCommand.java | 57 .../apache/commons/text/diff/KeepCommand.java | 57 .../commons/text/diff/ReplacementsFinder.java | 109 +++ .../commons/text/diff/ReplacementsHandler.java | 52 .../commons/text/diff/StringsComparator.java| 281 +++ .../apache/commons/text/diff/package-info.java | 22 ++ 10 files changed, 991 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/cca1f199/src/main/java/org/apache/commons/text/diff/CommandVisitor.java -- diff --git a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java new file mode 100644 index 000..ae3833c --- /dev/null +++ b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.diff; + +/** + * This interface should be implemented by user object to walk + * through {@link EditScript EditScript} objects. + * p + * Users should implement this interface in order to walk through + * the {@link EditScript EditScript} object created by the comparison + * of two sequences. This is a direct application of the visitor + * design pattern. The {@link EditScript#visit EditScript.visit} + * method takes an object implementing this interface as an argument, + * it will perform the loop over all commands in the script and the + * proper methods of the user class will be called as the commands are + * encountered. + * p + * The implementation of the user visitor class will depend on the + * need. Here are two examples. + * p + * The first example is a visitor that build the longest common + * subsequence: + * pre + * import org.apache.commons.collections4.comparators.sequence.CommandVisitor; + * + * import java.util.ArrayList; + * + * public class LongestCommonSubSequence implements CommandVisitor { + * + * public LongestCommonSubSequence() { + * a = new ArrayList(); + * } + * + * public void visitInsertCommand(Object object) { + * } + * + * public void visitKeepCommand(Object object) { + * a.add(object); + * } + * + * public void visitDeleteCommand(Object object) { + * } + * + * public Object[] getSubSequence() { + * return a.toArray(); + * } + * + * private ArrayList a; + * + * } + * /pre + * p + * The second example is a visitor that shows the commands and the way + * they transform the first sequence into the second one: + * pre + * import org.apache.commons.collections4.comparators.sequence.CommandVisitor; + * + * import java.util.Arrays; + * import java.util.ArrayList; + * import java.util.Iterator; + * + * public class ShowVisitor implements CommandVisitor { + * + * public ShowVisitor(Object[] sequence1) { + * v = new ArrayList(); + * v.addAll(Arrays.asList(sequence1)); + * index = 0; + * } + * + * public void visitInsertCommand(Object object) { + * v.insertElementAt(object, index++); + * display(insert, object); + * } + * + * public void
[text] Fix Javadocs and include initial tests
Repository: commons-text Updated Branches: refs/heads/myers-algo a7e88eef1 - 38f79f914 Fix Javadocs and include initial tests Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/38f79f91 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/38f79f91 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/38f79f91 Branch: refs/heads/myers-algo Commit: 38f79f914c73d902ad720d3bb7e46cad5063b1be Parents: a7e88ee Author: Bruno P. Kinoshita ki...@apache.org Authored: Thu Feb 5 21:36:49 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Thu Feb 5 21:36:49 2015 -0200 -- .../apache/commons/text/diff/EditCommand.java | 4 + .../commons/text/diff/StringsComparator.java| 44 +-- .../text/diff/StringsComparatorTest.java| 121 +++ 3 files changed, 126 insertions(+), 43 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/38f79f91/src/main/java/org/apache/commons/text/diff/EditCommand.java -- diff --git a/src/main/java/org/apache/commons/text/diff/EditCommand.java b/src/main/java/org/apache/commons/text/diff/EditCommand.java index 627db4d..972cebb 100644 --- a/src/main/java/org/apache/commons/text/diff/EditCommand.java +++ b/src/main/java/org/apache/commons/text/diff/EditCommand.java @@ -41,6 +41,10 @@ package org.apache.commons.text.diff; * and the codeequals/code method is specialized. * /p * + * p + * This code has been adapted from Apache Commons Collections 4.0. + * /p + * * @see StringsComparator * @see EditScript * http://git-wip-us.apache.org/repos/asf/commons-text/blob/38f79f91/src/main/java/org/apache/commons/text/diff/StringsComparator.java -- diff --git a/src/main/java/org/apache/commons/text/diff/StringsComparator.java b/src/main/java/org/apache/commons/text/diff/StringsComparator.java index c2fbfab..b2940fa 100644 --- a/src/main/java/org/apache/commons/text/diff/StringsComparator.java +++ b/src/main/java/org/apache/commons/text/diff/StringsComparator.java @@ -42,7 +42,7 @@ package org.apache.commons.text.diff; * the second one. * * p - * This class has been adapted from the commons-collections implementation. + * This code has been adapted from Apache Commons Collections 4.0. * /p * * @see EditScript @@ -325,46 +325,4 @@ public class StringsComparator { } } -public static void main(String[] args) { -StringsComparator sc = new StringsComparator(O Bruno eh um bom rapaz. Ele eh do Brasil., O Bruno foi um bom rapaz. Ele eh do Brasil .); -EditScriptCharacter es = sc.getScript(); -es.visit(new CommandVisitorCharacter() { - -boolean nlAdd = true; -boolean nlRemove = true; - -@Override -public void visitInsertCommand(Character object) { -if (nlAdd) { -System.out.println(); -System.out.print( ); -nlAdd = false; -} -System.out.print(object); -} - -@Override -public void visitKeepCommand(Character object) { -if (!nlAdd) { -nlAdd = true; -} -if (!nlRemove) { -nlRemove = true; -System.out.println(); -} -System.out.print(object); -} - -@Override -public void visitDeleteCommand(Character object) { -if (nlRemove) { -System.out.println(); -System.out.print( ); -nlRemove = false; -} -System.out.print(object); -} -}); -} - } http://git-wip-us.apache.org/repos/asf/commons-text/blob/38f79f91/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java -- diff --git a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java new file mode 100644 index 000..a988581 --- /dev/null +++ b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may
[text] Tests for ReplacementFinder
Repository: commons-text Updated Branches: refs/heads/myers-algo 38f79f914 - f3cff64cc Tests for ReplacementFinder Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/f3cff64c Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/f3cff64c Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/f3cff64c Branch: refs/heads/myers-algo Commit: f3cff64cca0be82d9974ae210ff6cd3369819fbe Parents: 38f79f9 Author: Bruno P. Kinoshita ki...@apache.org Authored: Mon Feb 9 23:38:06 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Mon Feb 9 23:38:06 2015 -0200 -- .../text/diff/ReplacementsFinderTest.java | 107 +++ .../text/diff/StringsComparatorTest.java| 3 + 2 files changed, 110 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/f3cff64c/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java -- diff --git a/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java new file mode 100644 index 000..d611475 --- /dev/null +++ b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.diff; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +/** + * Tests for the ReplacementsFinder. + */ +@RunWith(Parameterized.class) +public class ReplacementsFinderTest { +private SimpleHandler handler = null; +private String left; +private String right; +private int skipped; +private Character[] from; +private Character[] to; +@Before +public void setUp() { +handler = new SimpleHandler(); +} +@Parameters +public static CollectionObject[] data() { +return Arrays.asList(new Object[][] { +{ +branco, +blanco, +1, +new Character[] {'r'}, +new Character[] {'l'}}, +{ +test the blocks before you use it, +try the blocks before you put it, +25, +new Character[] {'e', 's', 't', 's', 'e'}, +new Character[] {'r', 'y', 'p', 't'} +} +}); +} +public ReplacementsFinderTest(String left, String right, int skipped, +Character[] from, Character[] to) { +this.left = left; +this.right = right; +this.skipped = skipped; +this.from = from; +this.to = to; +} +@Test +public void testReplacementsHandler() { +final StringsComparator sc = new StringsComparator(left, right); +final ReplacementsFinderCharacter replacementFinder = new ReplacementsFinder(handler); +sc.getScript().visit(replacementFinder); +assertEquals(Skipped characters do not match, skipped, handler.getSkipped()); +assertArrayEquals(From characters do not match, from, +handler.getFrom().toArray(new Character[0])); +assertArrayEquals(To characters do not match, to, +handler.getTo().toArray(new Character[0])); +} +// Helper RecplacementsHandler implementation for testing +private class SimpleHandler implements ReplacementsHandlerCharacter { +private int skipped; +private ListCharacter from; +private ListCharacter to; +public SimpleHandler() { +skipped = 0; +from = new ArrayList(); +to = new ArrayList(); +} +public int
[text] SANDBOX-488 remove distances from StringMetric javadocs for consistency
Repository: commons-text Updated Branches: refs/heads/master 93fb453cc - 9dd58bce9 SANDBOX-488 remove distances from StringMetric javadocs for consistency Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/9dd58bce Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/9dd58bce Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/9dd58bce Branch: refs/heads/master Commit: 9dd58bce9ca43b836ae0a8bd1916daad3f458327 Parents: 93fb453 Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 14 11:21:30 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Feb 14 11:21:30 2015 -0200 -- .../org/apache/commons/text/similarity/StringMetric.java | 11 +-- 1 file changed, 5 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/9dd58bce/src/main/java/org/apache/commons/text/similarity/StringMetric.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/StringMetric.java b/src/main/java/org/apache/commons/text/similarity/StringMetric.java index 6c7b9ce..fd6880a 100644 --- a/src/main/java/org/apache/commons/text/similarity/StringMetric.java +++ b/src/main/java/org/apache/commons/text/similarity/StringMetric.java @@ -17,15 +17,14 @@ package org.apache.commons.text.similarity; /** - * Interface for a - * href='http://en.wikipedia.org/wiki/String_metric'String Metrics/a. + * Interface for a href='http://en.wikipedia.org/wiki/String_metric'String Metrics/a. * * p - * A string metric measures the distance between two character sequences. The higher the distance, the lesser the - * similarity between the two character sequences. + * A string metric measures the similarity between two character sequences. Depending on + * the algorithm, higher values can mean closer strings, or more distant strings. * /p * - * @param R The type of score used by this StringMetric. + * @param R The type of similarity score unit used by this StringMetric. */ public interface StringMetricR { @@ -34,7 +33,7 @@ public interface StringMetricR { * * @param left the first CharSequence * @param right the second CharSequence - * @return the distance between to two CharSequences + * @return the similarity score between two CharSequences */ R compare(CharSequence left, CharSequence right);
[text] SANDBOX-488 rename FuzzyDistance to FuzzyScore
Repository: commons-text Updated Branches: refs/heads/master 9dd58bce9 - 1e7d2aa50 SANDBOX-488 rename FuzzyDistance to FuzzyScore Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/1e7d2aa5 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/1e7d2aa5 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/1e7d2aa5 Branch: refs/heads/master Commit: 1e7d2aa5057ad5e067ec9cd762ab8772546bc777 Parents: 9dd58bc Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 14 13:56:55 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Feb 14 13:56:55 2015 -0200 -- .../commons/text/similarity/FuzzyDistance.java | 133 --- .../commons/text/similarity/FuzzyScore.java | 133 +++ .../text/similarity/FuzzyDistanceTest.java | 75 --- .../commons/text/similarity/FuzzyScoreTest.java | 75 +++ 4 files changed, 208 insertions(+), 208 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/1e7d2aa5/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java b/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java deleted file mode 100644 index 4d175a0..000 --- a/src/main/java/org/apache/commons/text/similarity/FuzzyDistance.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the License); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.text.similarity; - -import java.util.Locale; - -/** - * A matching algorithm that is similar to the searching algorithms implemented in editors such - * as Sublime Text, TextMate, Atom and others. - * - * p - * One point is given for every matched character. Subsequent matches yield two bonus points. A higher score - * indicates a higher similarity. - * /p - * - * p - * This code has been adapted from Apache Commons Lang 3.3. - * /p - */ -public class FuzzyDistance implements StringMetricInteger { - -/** - * p - * Find the Fuzzy Distance which indicates the similarity score between two - * Strings. This method uses the default locale. - * /p - * - * @param term a full term that should be matched against, must not be null - * @param query the query that will be matched against a term, must not be - *null - * @return result score - * @throws IllegalArgumentException if either String input {@code null} - */ -@Override -public Integer compare(CharSequence term, CharSequence query) { -return compare(term, query, Locale.getDefault()); -} - -/** - * p - * Find the Fuzzy Distance which indicates the similarity score between two - * Strings. - * /p - * - * pre - * distance.compare(null, null, null)= IllegalArgumentException - * distance.compare(, , Locale.ENGLISH) = 0 - * distance.compare(Workshop, b, Locale.ENGLISH) = 0 - * distance.compare(Room, o, Locale.ENGLISH) = 1 - * distance.compare(Workshop, w, Locale.ENGLISH) = 1 - * distance.compare(Workshop, ws, Locale.ENGLISH)= 2 - * distance.compare(Workshop, wo, Locale.ENGLISH)= 4 - * distance.compare(Apache Software Foundation, asf, Locale.ENGLISH) = 3 - * /pre - * - * @param term a full term that should be matched against, must not be null - * @param query the query that will be matched against a term, must not be - *null - * @param locale This string matching logic is case insensitive. A locale is - *necessary to normalize both Strings to lower case. - * @return result score - * @throws IllegalArgumentException if either String input {@code null} or - * Locale input {@code null} - */ -public
[2/2] [text] Jaccard index and distance
Jaccard index and distance Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e099c56e Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e099c56e Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e099c56e Branch: refs/heads/NEW-METRICS Commit: e099c56ea1ce584f0aac9679ebcf51c4bdeec6fb Parents: 886bff0 Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 14 14:23:54 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Feb 14 14:23:54 2015 -0200 -- .../text/similarity/JaccardDistance.java| 21 .../commons/text/similarity/JaccardIndex.java | 21 2 files changed, 42 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/e099c56e/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java b/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java new file mode 100644 index 000..7237244 --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +public class JaccardDistance { + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/e099c56e/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java b/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java new file mode 100644 index 000..ceaa468 --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +public class JaccardIndex { + +}
[1/2] [text] Coside similarity and distance
Repository: commons-text Updated Branches: refs/heads/NEW-METRICS [created] e099c56ea Coside similarity and distance Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/886bff09 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/886bff09 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/886bff09 Branch: refs/heads/NEW-METRICS Commit: 886bff091df593203ce79369a0180fd58d9d9a85 Parents: 1e7d2aa Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 14 14:23:42 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Feb 14 14:23:42 2015 -0200 -- .../commons/text/similarity/CosineDistance.java | 21 .../text/similarity/CosineSimilarity.java | 21 2 files changed, 42 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/886bff09/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java new file mode 100644 index 000..ad19745 --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +public class CosineDistance { + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/886bff09/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java new file mode 100644 index 000..4589c2d --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +public class CosineSimilarity { + +}
[text] Migrating Myers algorithm from [collections]
Repository: commons-text Updated Branches: refs/heads/master 1a236bada - 93fb453cc Migrating Myers algorithm from [collections] Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/93fb453c Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/93fb453c Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/93fb453c Branch: refs/heads/master Commit: 93fb453ccc2b4d048e416de55c28e33d0327daeb Parents: 1a236ba Author: Bruno P. Kinoshita ki...@apache.org Authored: Sun Dec 14 23:41:43 2014 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Tue Feb 10 22:27:19 2015 -0200 -- .../commons/text/diff/CommandVisitor.java | 145 .../apache/commons/text/diff/DeleteCommand.java | 55 .../apache/commons/text/diff/EditCommand.java | 87 + .../apache/commons/text/diff/EditScript.java| 132 .../apache/commons/text/diff/InsertCommand.java | 57 .../apache/commons/text/diff/KeepCommand.java | 57 .../commons/text/diff/ReplacementsFinder.java | 111 +++ .../commons/text/diff/ReplacementsHandler.java | 51 +++ .../commons/text/diff/StringsComparator.java| 328 +++ .../apache/commons/text/diff/package-info.java | 25 ++ .../text/diff/ReplacementsFinderTest.java | 107 ++ .../text/diff/StringsComparatorTest.java| 122 +++ 12 files changed, 1277 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/93fb453c/src/main/java/org/apache/commons/text/diff/CommandVisitor.java -- diff --git a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java new file mode 100644 index 000..d73dde8 --- /dev/null +++ b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.diff; + +/** + * This interface should be implemented by user object to walk + * through {@link EditScript EditScript} objects. + * p + * Users should implement this interface in order to walk through + * the {@link EditScript EditScript} object created by the comparison + * of two sequences. This is a direct application of the visitor + * design pattern. The {@link EditScript#visit EditScript.visit} + * method takes an object implementing this interface as an argument, + * it will perform the loop over all commands in the script and the + * proper methods of the user class will be called as the commands are + * encountered. + * /p + * p + * The implementation of the user visitor class will depend on the + * need. Here are two examples. + * /p + * p + * The first example is a visitor that build the longest common + * subsequence: + * /p + * pre + * import org.apache.commons.text.diff.CommandVisitor; + * + * import java.util.ArrayList; + * + * public class LongestCommonSubSequence implements CommandVisitor { + * + * public LongestCommonSubSequence() { + * a = new ArrayList(); + * } + * + * public void visitInsertCommand(Object object) { + * } + * + * public void visitKeepCommand(Object object) { + * a.add(object); + * } + * + * public void visitDeleteCommand(Object object) { + * } + * + * public Object[] getSubSequence() { + * return a.toArray(); + * } + * + * private ArrayList a; + * + * } + * /pre + * p + * The second example is a visitor that shows the commands and the way + * they transform the first sequence into the second one: + * pre + * import org.apache.commons.text.diff.CommandVisitor; + * + * import java.util.Arrays; + * import java.util.ArrayList; + * import java.util.Iterator; + * + * public class ShowVisitor implements CommandVisitor { + * + * public ShowVisitor(Object[] sequence1) { + * v = new ArrayList(); + * v.addAll(Arrays.asList(sequence1)); + * index = 0; + * } + * + * public void visitInsertCommand(Object object) { + *
[text] Add tests for longest common subsequence
Repository: commons-text Updated Branches: refs/heads/myers-algo f3cff64cc - 300b82630 Add tests for longest common subsequence Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/300b8263 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/300b8263 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/300b8263 Branch: refs/heads/myers-algo Commit: 300b82630789255ae3f443bce9102add247908b7 Parents: f3cff64 Author: Bruno P. Kinoshita ki...@apache.org Authored: Tue Feb 10 22:15:54 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Tue Feb 10 22:15:54 2015 -0200 -- .../text/diff/StringsComparatorTest.java| 40 ++-- 1 file changed, 19 insertions(+), 21 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/300b8263/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java -- diff --git a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java index 02b77be..d5d7690 100644 --- a/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java +++ b/src/test/java/org/apache/commons/text/diff/StringsComparatorTest.java @@ -15,24 +15,20 @@ * limitations under the License. */ package org.apache.commons.text.diff; - import java.util.Arrays; import java.util.List; - import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; - /** * Tests for the StringsComparator. */ public class StringsComparatorTest { - private ListString before; private ListString after; private int[]length; - +private int[]lcs; @Test public void testLength() { for (int i = 0; i before.size(); ++i) { @@ -40,7 +36,13 @@ public class StringsComparatorTest { Assert.assertEquals(length[i], comparator.getScript().getModifications()); } } - +@Test +public void testLongestCommonSubsequence() { +for (int i = 0; i before.size(); ++i) { +final StringsComparator comparator = new StringsComparator(before.get(i), after.get(i)); +Assert.assertEquals(lcs[i], comparator.getScript().getLCSLength()); +} +} @Test public void testExecution() { for (int i = 0; i before.size(); ++i) { @@ -49,35 +51,25 @@ public class StringsComparatorTest { Assert.assertEquals(after.get(i), ev.getString()); } } - private class ExecutionVisitorT implements CommandVisitorT { - private StringBuilder v; - public ExecutionVisitor() { v = new StringBuilder(); } - public void visitInsertCommand(final T object) { v.append(object); } - public void visitKeepCommand(final T object) { v.append(object); } - public void visitDeleteCommand(final T object) { } - public String getString() { return v.toString(); } - } - @Before public void setUp() { - before = Arrays.asList( bottle, nematode knowledge, @@ -88,7 +80,6 @@ public class StringsComparatorTest { glop glop, coq, spider-man); - after = Arrays.asList( noodle, empty bottle, @@ -99,7 +90,6 @@ public class StringsComparatorTest { pas glop pas glop, ane, klingon); - length = new int[] { 6, 16, @@ -111,14 +101,22 @@ public class StringsComparatorTest { 6, 13 }; - +lcs = new int[] { +3, +7, +0, +0, +6, +4, +9, +0, +2 +}; } - @After public void tearDown() { before = null; after = null; length = null; } - }
[text] SANDBOX-491: Allow extra information (e.g. Levenshtein threshold) to be stored as (final) fields in the StringMetric instance. This fixes #1 from github. Thanks to Jonathan Baker.
Repository: commons-text Updated Branches: refs/heads/master d9d330542 - 75cdc00af SANDBOX-491: Allow extra information (e.g. Levenshtein threshold) to be stored as (final) fields in the StringMetric instance. This fixes #1 from github. Thanks to Jonathan Baker. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/75cdc00a Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/75cdc00a Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/75cdc00a Branch: refs/heads/master Commit: 75cdc00afc674aca39a4fca4c1745d029da43648 Parents: d9d3305 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Thu Mar 19 22:28:44 2015 -0300 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Thu Mar 19 22:30:02 2015 -0300 -- src/changes/changes.xml | 1 + .../commons/text/similarity/FuzzyScore.java | 36 +-- .../text/similarity/LevenshteinDistance.java| 229 +++ .../commons/text/similarity/FuzzyScoreTest.java | 47 ++-- .../similarity/JaroWrinklerDistanceTest.java| 2 +- .../similarity/LevenshteinDistanceTest.java | 113 ++--- .../ParameterizedLevenshteinDistanceTest.java | 125 ++ 7 files changed, 372 insertions(+), 181 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/75cdc00a/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2f87c53..fa6417f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-491 type=fix dev=kinow due-to=Jonathan BakerAllow extra information (e.g. Levenshtein threshold) to be stored as (final) fields in the StringMetric instance./action action issue=SANDBOX-486 type=add dev=kinowPort Myers algorithm from [collections]/action action issue=SANDBOX-485 type=add dev=kinowAdd Hamming distance/action action issue=SANDBOX-483 type=add dev=kinow due-to=britterIncorporate String algorithms from Commons Lang/action http://git-wip-us.apache.org/repos/asf/commons-text/blob/75cdc00a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java b/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java index 3e72d05..3cf6df2 100644 --- a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java +++ b/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java @@ -33,21 +33,22 @@ import java.util.Locale; */ public class FuzzyScore implements StringMetricInteger { +private final Locale locale; + + /** - * p - * Find the Fuzzy Score which indicates the similarity score between two - * Strings. This method uses the default locale. - * /p + * pThis returns a {@link Locale}-specific {@link FuzzyScore}./p * - * @param term a full term that should be matched against, must not be null - * @param query the query that will be matched against a term, must not be - *null - * @return result score - * @throws IllegalArgumentException if either String input {@code null} + * @param locale The string matching logic is case insensitive. + A {@link Locale} is necessary to normalize both Strings to lower case. + * @throws IllegalArgumentException + * This is thrown if the {@link Locale} parameter is {@code null}. */ -@Override -public Integer compare(CharSequence term, CharSequence query) { -return compare(term, query, Locale.getDefault()); +public FuzzyScore(final Locale locale) { +if (locale == null) { +throw new IllegalArgumentException(Locale must not be null); +} +this.locale = locale; } /** @@ -70,17 +71,14 @@ public class FuzzyScore implements StringMetricInteger { * @param term a full term that should be matched against, must not be null * @param query the query that will be matched against a term, must not be *null - * @param locale This string matching logic is case insensitive. A locale is - *necessary to normalize both Strings to lower case. * @return result score * @throws IllegalArgumentException if either String input {@code null} or * Locale input {@code null} */ -public Integer compare(CharSequence term, CharSequence query, Locale locale) { +@Override +public Integer compare(CharSequence term, CharSequence query) { if (term == null || query == null
[text] Fix Java 8 javadocs
Repository: commons-text Updated Branches: refs/heads/master 75cdc00af - 2f0052334 Fix Java 8 javadocs Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/2f005233 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/2f005233 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/2f005233 Branch: refs/heads/master Commit: 2f0052334cba8e793e9d864cb0f31f280b70e4a0 Parents: 75cdc00 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Thu Mar 19 22:44:42 2015 -0300 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Thu Mar 19 22:44:42 2015 -0300 -- .../org/apache/commons/text/similarity/LevenshteinDistance.java| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/2f005233/src/main/java/org/apache/commons/text/similarity/LevenshteinDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/LevenshteinDistance.java b/src/main/java/org/apache/commons/text/similarity/LevenshteinDistance.java index 38e5f14..920dddb 100644 --- a/src/main/java/org/apache/commons/text/similarity/LevenshteinDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/LevenshteinDistance.java @@ -43,7 +43,7 @@ public class LevenshteinDistance implements StringMetricInteger { * of the algorithm that does not use a threshold parameter. * /p * - * @see {@link #getDefaultInstance()} + * @see LevenshteinDistance#getDefaultInstance() */ public LevenshteinDistance() { this(null);
[text] SANDBOX-493: Change (R) StringMetric.compare(CS left, CS right) to apply so that it is consistent with BiFunction.This fixes #2 from github. Thanks to Jonathan Baker.
Repository: commons-text Updated Branches: refs/heads/master 2f0052334 - 980791b69 SANDBOX-493: Change (R) StringMetric.compare(CS left, CS right) to apply so that it is consistent with BiFunction.This fixes #2 from github. Thanks to Jonathan Baker. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/980791b6 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/980791b6 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/980791b6 Branch: refs/heads/master Commit: 980791b69dc4cb1a639e835ea3b151d9d107ea7f Parents: 2f00523 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Thu Mar 19 23:39:04 2015 -0300 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Thu Mar 19 23:39:04 2015 -0300 -- src/changes/changes.xml | 1 + .../commons/text/similarity/FuzzyScore.java | 18 ++-- .../text/similarity/HammingDistance.java| 12 +-- .../text/similarity/JaroWrinklerDistance.java | 30 +++--- .../text/similarity/LevenshteinDistance.java| 24 ++--- .../commons/text/similarity/StringMetric.java | 9 +- .../commons/text/similarity/FuzzyScoreTest.java | 22 ++-- .../text/similarity/HammingDistanceTest.java| 20 ++-- .../similarity/JaroWrinklerDistanceTest.java| 20 ++-- .../similarity/LevenshteinDistanceTest.java | 100 --- .../ParameterizedLevenshteinDistanceTest.java | 2 +- 11 files changed, 168 insertions(+), 90 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/980791b6/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index fa6417f..553d55b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-493 type=fix dev=kinow due-to=Jonathan BakerChange (R) StringMetric.compare(CS left, CS right) to apply so that it is consistent with BiFunction./action action issue=SANDBOX-491 type=fix dev=kinow due-to=Jonathan BakerAllow extra information (e.g. Levenshtein threshold) to be stored as (final) fields in the StringMetric instance./action action issue=SANDBOX-486 type=add dev=kinowPort Myers algorithm from [collections]/action action issue=SANDBOX-485 type=add dev=kinowAdd Hamming distance/action http://git-wip-us.apache.org/repos/asf/commons-text/blob/980791b6/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java b/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java index 3cf6df2..e7e5b09 100644 --- a/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java +++ b/src/main/java/org/apache/commons/text/similarity/FuzzyScore.java @@ -58,14 +58,14 @@ public class FuzzyScore implements StringMetricInteger { * /p * * pre - * score.compare(null, null, null)= IllegalArgumentException - * score.compare(, , Locale.ENGLISH) = 0 - * score.compare(Workshop, b, Locale.ENGLISH) = 0 - * score.compare(Room, o, Locale.ENGLISH) = 1 - * score.compare(Workshop, w, Locale.ENGLISH) = 1 - * score.compare(Workshop, ws, Locale.ENGLISH)= 2 - * score.compare(Workshop, wo, Locale.ENGLISH)= 4 - * score.compare(Apache Software Foundation, asf, Locale.ENGLISH) = 3 + * score.apply(null, null, null)= IllegalArgumentException + * score.apply(, , Locale.ENGLISH) = 0 + * score.apply(Workshop, b, Locale.ENGLISH) = 0 + * score.apply(Room, o, Locale.ENGLISH) = 1 + * score.apply(Workshop, w, Locale.ENGLISH) = 1 + * score.apply(Workshop, ws, Locale.ENGLISH)= 2 + * score.apply(Workshop, wo, Locale.ENGLISH)= 4 + * score.apply(Apache Software Foundation, asf, Locale.ENGLISH) = 3 * /pre * * @param term a full term that should be matched against, must not be null @@ -76,7 +76,7 @@ public class FuzzyScore implements StringMetricInteger { * Locale input {@code null} */ @Override -public Integer compare(CharSequence term, CharSequence query) { +public Integer apply(CharSequence term, CharSequence query) { if (term == null || query == null) { throw new IllegalArgumentException(Strings must
[text] Tracking changes for SANDBOX-486
Repository: commons-text Updated Branches: refs/heads/master 2592024dd - d9d330542 Tracking changes for SANDBOX-486 Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/d9d33054 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/d9d33054 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/d9d33054 Branch: refs/heads/master Commit: d9d330542ea2bc648d0f453e83d41628d2a11621 Parents: 2592024 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sat Mar 14 13:56:57 2015 -0300 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sat Mar 14 13:56:57 2015 -0300 -- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/d9d33054/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f890519..2f87c53 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-486 type=add dev=kinowPort Myers algorithm from [collections]/action action issue=SANDBOX-485 type=add dev=kinowAdd Hamming distance/action action issue=SANDBOX-483 type=add dev=kinow due-to=britterIncorporate String algorithms from Commons Lang/action /release
Git Push Summary
Repository: commons-text Updated Branches: refs/heads/myers-algo [deleted] 300b82630
[text] Use tokenizers in internal package, and add more tests
Repository: commons-text Updated Branches: refs/heads/NEW-METRICS ff1959c84 - 81f679dea Use tokenizers in internal package, and add more tests Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/81f679de Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/81f679de Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/81f679de Branch: refs/heads/NEW-METRICS Commit: 81f679dea1eb4c1d90d7173547ff98f7d14110a4 Parents: ff1959c Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Fri Mar 27 03:25:51 2015 -0300 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Fri Mar 27 03:25:51 2015 -0300 -- .../commons/text/similarity/CosineDistance.java | 28 ++- .../text/similarity/CosineSimilarity.java | 77 ++-- .../similarity/internal/CharacterTokenizer.java | 43 +++ .../text/similarity/internal/Counter.java | 44 +++ .../similarity/internal/SimpleTokenizer.java| 50 + .../similarity/internal/StringTokenizer.java| 36 + .../text/similarity/internal/Tokenizer.java | 36 + .../internal/WhiteSpaceTokenizer.java | 46 .../text/similarity/internal/package-info.java | 21 ++ .../text/similarity/CosineDistanceTest.java | 55 ++ .../text/similarity/CosineSimilarityTest.java | 51 - 11 files changed, 414 insertions(+), 73 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/81f679de/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java index ad19745..54970e4 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -16,6 +16,32 @@ */ package org.apache.commons.text.similarity; -public class CosineDistance { +import java.util.Map; + +import org.apache.commons.text.similarity.internal.Counter; +import org.apache.commons.text.similarity.internal.SimpleTokenizer; +import org.apache.commons.text.similarity.internal.Tokenizer; + +/** + * p + * Calcules the cosine distance. + * /p + */ +public class CosineDistance implements StringMetricDouble { + +private final TokenizerString tokenizer = new SimpleTokenizer(); + +private final CosineSimilarity cosineSimilarity = new CosineSimilarity(); + +@Override +public Double compare(CharSequence left, CharSequence right) { +String[] leftTokens = tokenizer.tokenize(left); +String[] rightTokens = tokenizer.tokenize(right); + +MapString, Integer leftVector = Counter.of(leftTokens); +MapString, Integer rightVector = Counter.of(rightTokens); +double similarity = cosineSimilarity.cosineSimilarity(leftVector, rightVector); +return 1.0 - similarity; +} } http://git-wip-us.apache.org/repos/asf/commons-text/blob/81f679de/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java index ca9d087..992e5e9 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java @@ -16,9 +16,16 @@ */ package org.apache.commons.text.similarity; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + + /** - * pMeasures the Cosine similarity of two CharSequences. It treats the CharSequences as - * two vectors of an inner product space and compares the angle between them./p + * p + * Measures the Cosine similarity of two vectors of an inner product space and + * compares the angle between them. + * /p * * p * For further explanation about the Cosine Similarity, take a look at its @@ -27,39 +34,67 @@ package org.apache.commons.text.similarity; * * @since 0.1 */ -public class CosineSimilarity implements StringMetricDouble { +public class CosineSimilarity { -@Override -public Double compare(CharSequence left, CharSequence right) { -if (left == null || right == null) { -throw new IllegalArgumentException(String parameters must not be null); +/** + * Calculates the cosine similarity for two given vectors. + * + * @param leftVector left vector + * @param rightVector right vector + * @return cosine similarity between the two vectors + */ +
[text] Remove redundant groupId (already defined by parent)
Repository: commons-text Updated Branches: refs/heads/master bea47ca76 - 2592024dd Remove redundant groupId (already defined by parent) Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/2592024d Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/2592024d Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/2592024d Branch: refs/heads/master Commit: 2592024dd205376d65db6c74954e3d950a3c249e Parents: bea47ca Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Mon Mar 2 21:42:30 2015 -0300 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Mon Mar 2 21:42:30 2015 -0300 -- pom.xml | 1 - 1 file changed, 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/2592024d/pom.xml -- diff --git a/pom.xml b/pom.xml index cb16421..2f46e9a 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,6 @@ version37/version /parent modelVersion4.0.0/modelVersion - groupIdorg.apache.commons/groupId artifactIdcommons-text/artifactId version0.1-SNAPSHOT/version nameApache Commons Text/name
[text] Fix package in Javadoc
Repository: commons-text Updated Branches: refs/heads/NEW-METRICS e099c56ea - 0404dbf4b Fix package in Javadoc Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/0404dbf4 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/0404dbf4 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/0404dbf4 Branch: refs/heads/NEW-METRICS Commit: 0404dbf4b15782634b6816d8499ebd64c7aafc48 Parents: e099c56 Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 21 22:21:39 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Feb 21 22:21:39 2015 -0200 -- .../java/org/apache/commons/text/similarity/FuzzyScoreTest.java| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/0404dbf4/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java -- diff --git a/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java b/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java index b2fab14..b6519e8 100644 --- a/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java +++ b/src/test/java/org/apache/commons/text/similarity/FuzzyScoreTest.java @@ -24,7 +24,7 @@ import org.junit.BeforeClass; import org.junit.Test; /** - * Unit tests for {@link org.apache.commons.text.FuzzyScore}. + * Unit tests for {@link org.apache.commons.text.similarity.FuzzyScore}. */ public class FuzzyScoreTest {
[text] Initial implementation of the cosine distance for strings (not sequences)
Repository: commons-text Updated Branches: refs/heads/NEW-METRICS 0404dbf4b - ff1959c84 Initial implementation of the cosine distance for strings (not sequences) Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/ff1959c8 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/ff1959c8 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/ff1959c8 Branch: refs/heads/NEW-METRICS Commit: ff1959c84dce2eac6f2e8432623d2a2a270a5f32 Parents: 0404dbf Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 21 22:22:28 2015 -0200 Committer: Bruno P. Kinoshita ki...@apache.org Committed: Sat Feb 21 22:22:28 2015 -0200 -- .../text/similarity/CosineSimilarity.java | 48 +- .../text/similarity/CosineSimilarityTest.java | 51 2 files changed, 98 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/ff1959c8/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java index 4589c2d..ca9d087 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java @@ -16,6 +16,52 @@ */ package org.apache.commons.text.similarity; -public class CosineSimilarity { +/** + * pMeasures the Cosine similarity of two CharSequences. It treats the CharSequences as + * two vectors of an inner product space and compares the angle between them./p + * + * p + * For further explanation about the Cosine Similarity, take a look at its + * Wikipedia page at http://en.wikipedia.org/wiki/Cosine_similarity. + * /p + * + * @since 0.1 + */ +public class CosineSimilarity implements StringMetricDouble { + +@Override +public Double compare(CharSequence left, CharSequence right) { +if (left == null || right == null) { +throw new IllegalArgumentException(String parameters must not be null); +} +long dotProduct = dot(left, right); +double d1 = 0.0d; +for (int i = 0; i left.length(); ++i) { +d1 += Math.pow(((int) left.charAt(i)), 2); +} +double d2 = 0.0d; +for (int i = 0; i right.length(); ++i) { +d2 += Math.pow(((int) right.charAt(i)), 2); +} +double cosineSimilarity = dotProduct / (double) (Math.sqrt(d1) * Math.sqrt(d2)); +return cosineSimilarity; +} + +/** + * Computes the dot product of two CharSequences. It ignores remaining characters. It means + * that if a string is longer than other, then a smaller part of it will be used to compute + * the dot product. + * + * @param left left string + * @param right right string + * @return the dot product + */ +protected long dot(CharSequence left, CharSequence right) { +long dotProduct = 0; +for (int i = 0; i left.length() i right.length(); ++i) { +dotProduct += (((int) left.charAt(i)) * ((int) right.charAt(i))); +} +return dotProduct; +} } http://git-wip-us.apache.org/repos/asf/commons-text/blob/ff1959c8/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java -- diff --git a/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java b/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java new file mode 100644 index 000..aa08057 --- /dev/null +++ b/src/test/java/org/apache/commons/text/similarity/CosineSimilarityTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +import static org.junit.Assert.assertEquals; + +import java.math.BigDecimal; +import java.math.RoundingMode;
[text] SANDBOX-497 IP clearance for the names package
Repository: commons-text Updated Branches: refs/heads/SANDBOX-497 [created] be2bcda21 SANDBOX-497 IP clearance for the names package Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/be2bcda2 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/be2bcda2 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/be2bcda2 Branch: refs/heads/SANDBOX-497 Commit: be2bcda218bdaf0bce78dac8bb60efb46027f74f Parents: c4e8a3e Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sun Apr 19 21:59:12 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 19 21:59:12 2015 +1200 -- NOTICE.txt | 4 src/changes/changes.xml | 1 + 2 files changed, 5 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/be2bcda2/NOTICE.txt -- diff --git a/NOTICE.txt b/NOTICE.txt index 283320b..f6f4633 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -3,3 +3,7 @@ Copyright 2001-2015 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (http://www.apache.org/). + +This product includes software from the HumanNameParser.php +(https://github.com/jasonpriem/HumanNameParser.php) library, +under the Apache License 2.0 (see: the o.a.c.t.names package). http://git-wip-us.apache.org/repos/asf/commons-text/blob/be2bcda2/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2768608..fbb60b9 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-497 type=fix dev=kinowIP clearance for the names package/action action issue=SANDBOX-496 type=add dev=kinowWrite user guide/action action issue=SANDBOX-488 type=fix dev=kinowWork on the string metric, distance, and similarity definitions for the project/action action issue=SANDBOX-487 type=add dev=kinowHuman name parser/action
[12/13] [text] Add SANDBOX-498 to the list of fixed issues
Add SANDBOX-498 to the list of fixed issues Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/c1372c1f Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/c1372c1f Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/c1372c1f Branch: refs/heads/master Commit: c1372c1f9754434995c9a91fe47508946ff5744f Parents: 6d047a4 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 17:14:22 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 17:14:22 2015 +0200 -- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/c1372c1f/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index fbb60b9..0a77677 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-498 type=update dev=britterImprove HumanNameParser/action action issue=SANDBOX-497 type=fix dev=kinowIP clearance for the names package/action action issue=SANDBOX-496 type=add dev=kinowWrite user guide/action action issue=SANDBOX-488 type=fix dev=kinowWork on the string metric, distance, and similarity definitions for the project/action
[11/13] [text] Better JavaDoc for HumanNameParser
Better JavaDoc for HumanNameParser Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/6d047a46 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/6d047a46 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/6d047a46 Branch: refs/heads/master Commit: 6d047a461f83017c8b723f4b28c0ad10f3f1dc36 Parents: b1c7e56 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 17:13:11 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 17:13:11 2015 +0200 -- .../commons/text/names/HumanNameParser.java | 99 +--- 1 file changed, 64 insertions(+), 35 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/6d047a46/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index b5c0aa3..5407d15 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -24,58 +24,87 @@ import java.util.Objects; import org.apache.commons.lang3.StringUtils; /** - * pA parser capable of parsing name parts out of a single string./p + * A parser capable of parsing name parts out of a single string. * + * h3Parsing examples/h3 + * * pThe code works by basically applying several Regexes in a certain order - * and removing (chopping) tokens off the original string. The parser consumes - * the tokens during its creation./p + * and removing (chopping) tokens off the original string. The parser creates + * a {@link Name} object representing the parse result. Note that passing null + * to the {@link #parse(String)} method will result in an exception./p * - * ul - * liJ. Walter Weatherman /li - * lide la Cruz, Ana M./li - * liJames C. ('Jimmy') O'Dell, Jr./li - * /ul - * - * pand parses out the:/p - * - * ul - * lileading initial (Like J. in J. Walter Weatherman)/li - * lifirst name (or first initial in a name like 'R. Crumb')/li - * linicknames (like Jimmy in James C. ('Jimmy') O'Dell, Jr.)/li - * limiddle names/li - * lilast name (including compound ones like van der Sar' and Ortega y Gasset), and/li - * lisuffix (like 'Jr.', 'III')/li - * /ul + * table + * tr + * thinput/th + * thLeading initial/th + * thFirst name/th + * thNick name/th + * thMiddle name/th + * thLast Name/th + * thSuffix/th + * /tr + * tr + * tdJ. Walter Weatherman/td + * tdJ./td + * tdWalter/td + * td/td + * td/td + * tdWeatherman/td + * td/td + * /tr + * tr + * tdde la Cruz, Ana M./td + * td/td + * tdAna/td + * td/td + * tdM./td + * tdde la Cruz/td + * td/td + * /tr + * tr + * tdJames C. ('Jimmy') O'Dell, Jr./td + * td/td + * tdJames/td + * tdJimmy/td + * tdC./td + * tdO'Dell/td + * tdJr./td + * /tr + * /table * + * h3Sample usage/h3 + * + * pHumanNameParser instances are immutable and can be reused for parsing multiple names:/p + * * pre - * Name name = new Name(S�rgio Vieira de Mello); - * HumanNameParser parser = new HumanNameParser(name); - * String firstName = parser.getFirst(); - * String nickname = parser.getNickname(); + * HumanNameParser parser = new HumanNameParser(); + * Name parsedName = parser.parse(S�rgio Vieira de Mello) + * String firstName = parsedName.getFirstName(); + * String nickname = parsedName.getNickName(); * // ... + * + * Name nextName = parser.parse(James C. ('Jimmy') O'Dell, Jr.) + * String firstName = nextName.getFirstName(); + * String nickname = nextName.getNickName(); * /pre * + * h3Further notes/h3 + * * pThe original code was written in a href=http://jasonpriem.com/human-name-parse;PHP/a - * and ported to a href=http://tupilabs.github.io/HumanNameParser.java/;Java/a./p - * - * pThis implementation is based on the Java implementation, with additions - * suggested in a href=https://issues.apache.org/jira/browse/SANDBOX-487;SANDBOX-487/a./p + * and ported to a href=http://tupilabs.github.io/HumanNameParser.java/;Java/a. This + * implementation is based on the Java implementation, with additions + * suggested in a href=https://issues.apache.org/jira/browse/SANDBOX-487;SANDBOX-487/a + * and a href=https://issues.apache.org/jira/browse/SANDBOX-498;SANDBOX-498/a./p * * pThis class is immutable./p */ public final class HumanNameParser { -/** - * Suffixes found. - */ private final ListString suffixes; -/** - * Prefixes found. - */ private final ListString prefixes; /** - * Creates a parser given a string name. + * Creates a new parser. */ public
[06/13] [text] Use a shared parser instance for tests
Use a shared parser instance for tests Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/bbba0a32 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/bbba0a32 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/bbba0a32 Branch: refs/heads/master Commit: bbba0a327b7ad8873d176254ec2a550757911bda Parents: 1f6c5da Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:30:00 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:30:00 2015 +0200 -- .../commons/text/names/HumanNameParserTest.java | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/bbba0a32/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java -- diff --git a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java index d059ed4..314a949 100644 --- a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java +++ b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java @@ -33,32 +33,33 @@ import org.junit.Test; */ public class HumanNameParserTest { -private CSVParser parser; +private CSVParser inputParser; +private HumanNameParser nameParser; @Before public void setUp() throws Exception { -parser = CSVParser.parse( +inputParser = CSVParser.parse( HumanNameParserTest.class.getResource(testNames.txt), Charset.forName(UTF-8), CSVFormat.DEFAULT.withDelimiter('|').withHeader()); +nameParser = new HumanNameParser(); } @After public void tearDown() throws Exception { -if (parser != null) { -parser.close(); +if (inputParser != null) { +inputParser.close(); } } @Test(expected = NullPointerException.class) public void shouldThrowNullPointerException_WhenNullIsParsed() throws Exception { -HumanNameParser parser = new HumanNameParser(); -parser.parse(null); +nameParser.parse(null); } @Test public void testInputs() { -for (CSVRecord record : parser) { +for (CSVRecord record : inputParser) { validateRecord(record); } } @@ -70,8 +71,7 @@ public class HumanNameParserTest { * @param record a CSVRecord representing one record in the input file. */ private void validateRecord(CSVRecord record) { -HumanNameParser parser = new HumanNameParser(); -Name result = parser.parse(record.get(Colums.Name)); +Name result = nameParser.parse(record.get(Colums.Name)); long recordNum = record.getRecordNumber(); assertThat(Wrong LeadingInit in record + recordNum,
[09/13] [text] Drop unused code from NameString and clean up NameStringTest
Drop unused code from NameString and clean up NameStringTest Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/ed985cd5 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/ed985cd5 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/ed985cd5 Branch: refs/heads/master Commit: ed985cd51220e956f516acecf1039defd0141d34 Parents: 9e34064 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:44:32 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:44:32 2015 +0200 -- .../commons/text/names/HumanNameParser.java | 5 +- .../apache/commons/text/names/NameString.java | 24 ++- .../commons/text/names/NameStringTest.java | 67 ++-- 3 files changed, 30 insertions(+), 66 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/ed985cd5/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index a29e375..b5c0aa3 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -100,6 +100,7 @@ public final class HumanNameParser { Objects.requireNonNull(name, Parameter 'name' must not be null.); NameString nameString = new NameString(name); +// TODO compile regexes only once when the parser is created String suffixes = StringUtils.join(this.suffixes, \\.*|) + \\.*; String prefixes = StringUtils.join(this.prefixes, |) + ; @@ -132,11 +133,11 @@ public final class HumanNameParser { // get the first name String first = nameString.chopWithRegex(firstRegex, 0); if (StringUtils.isBlank(first)) { -throw new NameParseException(Couldn't find a first name in '{ + nameString.getStr() + }'); +throw new NameParseException(Couldn't find a first name in '{ + nameString.getWrappedString() + }'); } // if anything's left, that's the middle name -String middle = nameString.getStr(); +String middle = nameString.getWrappedString(); return new Name(leadingInit, first, nickname, middle, last, suffix); } http://git-wip-us.apache.org/repos/asf/commons-text/blob/ed985cd5/src/main/java/org/apache/commons/text/names/NameString.java -- diff --git a/src/main/java/org/apache/commons/text/names/NameString.java b/src/main/java/org/apache/commons/text/names/NameString.java index 8f606f2..54e2753 100644 --- a/src/main/java/org/apache/commons/text/names/NameString.java +++ b/src/main/java/org/apache/commons/text/names/NameString.java @@ -37,30 +37,20 @@ final class NameString { * * @param str encapsulated string. */ -public NameString(String str) { +NameString(String str) { this.str = str; } /** - * Gets the encapsulated string. + * Gets the wrapped string. * - * @return encapsulated string + * @return wrapped string */ -public String getStr() { +String getWrappedString() { return str; } /** - * Sets the encapsulated string value. - * - * @param str string value - */ -public void setStr(String str) { -this.str = str; -this.norm(); -} - -/** * Uses a regex to chop off and return part of the namestring. * There are two parts: first, it returns the matched substring, * and then it removes that substring from the encapsulated @@ -70,7 +60,7 @@ final class NameString { * @param submatchIndex which of the parenthesized submatches to use * @return the part of the namestring that got chopped off */ -public String chopWithRegex(String regex, int submatchIndex) { +String chopWithRegex(String regex, int submatchIndex) { String chopped = ; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(this.str); @@ -106,7 +96,7 @@ final class NameString { * @param flipAroundChar the character(s) demarcating the two halves you want to flip. * @throws NameParseException if a regex fails or a condition is not expected */ -public void flip(String flipAroundChar) { +void flip(String flipAroundChar) { String[] parts = this.str.split(flipAroundChar); if (parts != null) { if (parts.length == 2) { @@ -125,7 +115,7 @@ final class NameString { * pStrips whitespace chars from ends, strips redundant whitespace, converts
[05/13] [text] Remove state from HumanNameParser, making it immutable
Remove state from HumanNameParser, making it immutable Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/1f6c5dae Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/1f6c5dae Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/1f6c5dae Branch: refs/heads/master Commit: 1f6c5daecded67a17c07371a564f74ef623b3f29 Parents: 685f9a8 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:28:37 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:28:37 2015 +0200 -- .../commons/text/names/HumanNameParser.java | 141 +++ .../org/apache/commons/text/names/Name.java | 32 + 2 files changed, 51 insertions(+), 122 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/1f6c5dae/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index df8e55c..c47abde 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -61,135 +61,32 @@ import org.apache.commons.lang3.StringUtils; * pThis implementation is based on the Java implementation, with additions * suggested in a href=https://issues.apache.org/jira/browse/SANDBOX-487;SANDBOX-487/a./p * - * pThis class is not thread-safe./p + * pThis class is immutable./p */ public class HumanNameParser { /** - * Leading init part. - */ -private String leadingInit; -/** - * First name. - */ -private String first; -/** - * Single nickname found in the name input. - */ -private String nickname; -/** - * Middle name. - */ -private String middle; -/** - * Last name. - */ -private String last; -/** - * Name suffix. - */ -private String suffix; -/** * Suffixes found. */ -private ListString suffixes; +private final ListString suffixes; /** * Prefixes found. */ -private ListString prefixes; +private final ListString prefixes; /** * Creates a parser given a string name. */ public HumanNameParser() { -this.leadingInit = ; -this.first = ; -this.nickname = ; -this.middle = ; -this.last = ; -this.suffix = ; - -this.suffixes = Arrays.asList(new String[]{ +// TODO make this configurable +this.suffixes = Arrays.asList( esq, esquire, jr, -sr, 2, ii, iii, iv}); -this.prefixes = Arrays -.asList(new String[] { +sr, 2, ii, iii, iv); +this.prefixes = Arrays.asList( bar, ben, bin, da, dal, de la, de, del, der, di, ibn, la, le, san, st, ste, van, van der, van den, vel, -von }); -} - -/** - * Gets the leading init part of the name. - * - * @return the leading init part of the name - */ -public String getLeadingInit() { -return leadingInit; -} - -/** - * Gets the first name. - * - * @return first name - */ -public String getFirst() { -return first; -} - -/** - * Gets the nickname. - * - * @return the nickname - */ -public String getNickname() { -return nickname; -} - -/** - * Gets the middle name. - * - * @return the middle name - */ -public String getMiddle() { -return middle; -} - -/** - * Gets the last name. - * - * @return the last name - */ -public String getLast() { -return last; -} - -/** - * Gets the suffix part of the name. - * - * @return the name suffix - */ -public String getSuffix() { -return suffix; -} - -/** - * Gets the name suffixes. - * - * @return the name suffixes - */ -public ListString getSuffixes() { -return suffixes; -} - -/** - * Gets the name prefixes. - * - * @return the name prefixes - */ -public ListString getPrefixes() { -return prefixes; +von ); } /** @@ -218,28 +115,28 @@ public class HumanNameParser { String firstRegex = (?i)^([^ ]+); // get nickname, if there is one -this.nickname = nameString.chopWithRegex(nicknamesRegex, 2); +String nickname = nameString.chopWithRegex(nicknamesRegex, 2); // get suffix, if there is one -this.suffix =
[07/13] [text] Fix typo
Fix typo Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/a942b4c0 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/a942b4c0 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/a942b4c0 Branch: refs/heads/master Commit: a942b4c02194a6f544f129e89e0f399d51c5c01a Parents: bbba0a3 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:31:01 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:31:01 2015 +0200 -- .../commons/text/names/HumanNameParserTest.java | 16 1 file changed, 8 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/a942b4c0/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java -- diff --git a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java index 314a949..f6c9ba6 100644 --- a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java +++ b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java @@ -71,29 +71,29 @@ public class HumanNameParserTest { * @param record a CSVRecord representing one record in the input file. */ private void validateRecord(CSVRecord record) { -Name result = nameParser.parse(record.get(Colums.Name)); +Name result = nameParser.parse(record.get(Columns.Name)); long recordNum = record.getRecordNumber(); assertThat(Wrong LeadingInit in record + recordNum, -result.getLeadingInitial(), equalTo(record.get(Colums.LeadingInit))); +result.getLeadingInitial(), equalTo(record.get(Columns.LeadingInit))); assertThat(Wrong FirstName in record + recordNum, -result.getFirstName(), equalTo(record.get(Colums.FirstName))); +result.getFirstName(), equalTo(record.get(Columns.FirstName))); assertThat(Wrong NickName in record + recordNum, -result.getNickName(), equalTo(record.get(Colums.NickName))); +result.getNickName(), equalTo(record.get(Columns.NickName))); assertThat(Wrong MiddleName in record + recordNum, -result.getMiddleName(), equalTo(record.get(Colums.MiddleName))); +result.getMiddleName(), equalTo(record.get(Columns.MiddleName))); assertThat(Wrong LastName in record + recordNum, -result.getLastName(), equalTo(record.get(Colums.LastName))); +result.getLastName(), equalTo(record.get(Columns.LastName))); assertThat(Wrong Suffix in record + recordNum, -result.getSuffix(), equalTo(record.get(Colums.Suffix))); +result.getSuffix(), equalTo(record.get(Columns.Suffix))); } -private enum Colums { +private enum Columns { Name,LeadingInit,FirstName,NickName,MiddleName,LastName,Suffix } }
[13/13] [text] Merge remote-tracking branch 'remotes/origin/SANDBOX-498' for issue SANDBOX-498
Merge remote-tracking branch 'remotes/origin/SANDBOX-498' for issue SANDBOX-498 Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/bf8bfb0a Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/bf8bfb0a Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/bf8bfb0a Branch: refs/heads/master Commit: bf8bfb0a46c0e6d7f9e3d3416bf2f147c9b81074 Parents: e8e85d9 c1372c1 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Mon Apr 20 14:58:27 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Mon Apr 20 14:58:27 2015 +1200 -- src/changes/changes.xml | 1 + .../commons/text/names/HumanNameParser.java | 279 +++ .../org/apache/commons/text/names/Name.java | 141 +- .../commons/text/names/NameParseException.java | 2 +- .../apache/commons/text/names/NameString.java | 122 .../commons/text/names/HumanNameParserTest.java | 43 +-- .../commons/text/names/NameStringTest.java | 77 + .../org/apache/commons/text/names/NameTest.java | 104 --- 8 files changed, 381 insertions(+), 388 deletions(-) --
[04/13] [text] Make HumanNameParser return a name object. Introduce a new wrapper object for strings to be parsed called NameString.
Make HumanNameParser return a name object. Introduce a new wrapper object for strings to be parsed called NameString. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/685f9a86 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/685f9a86 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/685f9a86 Branch: refs/heads/master Commit: 685f9a864d46cc526b14e3a7476465c49d991478 Parents: 9a0cc85 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:22:45 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:22:45 2015 +0200 -- .../commons/text/names/HumanNameParser.java | 36 ++--- .../org/apache/commons/text/names/Name.java | 141 ++- .../apache/commons/text/names/NameString.java | 134 ++ .../commons/text/names/HumanNameParserTest.java | 24 ++-- .../commons/text/names/NameStringTest.java | 104 ++ .../org/apache/commons/text/names/NameTest.java | 104 -- 6 files changed, 315 insertions(+), 228 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/685f9a86/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index fa2433a..df8e55c 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -195,14 +195,14 @@ public class HumanNameParser { /** * Consumes the string and creates the name parts. * - * @param nameStr the name to parse. Must not be null. + * @param name the name to parse. Must not be null. * @throws NameParseException if the parser fails to retrieve the name parts. - * @throws NullPointerException if nameStr is null. + * @throws NullPointerException if name is null. */ -public void parse(String nameStr) { -Objects.requireNonNull(nameStr, Parameter 'nameStr' must not be null.); +public Name parse(String name) { +Objects.requireNonNull(name, Parameter 'name' must not be null.); -Name name = new Name(nameStr); +NameString nameString = new NameString(name); String suffixes = StringUtils.join(this.suffixes, \\.*|) + \\.*; String prefixes = StringUtils.join(this.prefixes, |) + ; @@ -218,28 +218,30 @@ public class HumanNameParser { String firstRegex = (?i)^([^ ]+); // get nickname, if there is one -this.nickname = name.chopWithRegex(nicknamesRegex, 2); +this.nickname = nameString.chopWithRegex(nicknamesRegex, 2); // get suffix, if there is one -this.suffix = name.chopWithRegex(suffixRegex, 1); +this.suffix = nameString.chopWithRegex(suffixRegex, 1); -// flip the before-comma and after-comma parts of the name -name.flip(,); +// flip the before-comma and after-comma parts of the nameString +nameString.flip(,); -// get the last name -this.last = name.chopWithRegex(lastRegex, 0); +// get the last nameString +this.last = nameString.chopWithRegex(lastRegex, 0); // get the first initial, if there is one -this.leadingInit = name.chopWithRegex(leadingInitRegex, 1); +this.leadingInit = nameString.chopWithRegex(leadingInitRegex, 1); -// get the first name -this.first = name.chopWithRegex(firstRegex, 0); +// get the first nameString +this.first = nameString.chopWithRegex(firstRegex, 0); if (StringUtils.isBlank(this.first)) { -throw new NameParseException(Couldn't find a first name in '{ + name.getStr() + }'); +throw new NameParseException(Couldn't find a first name in '{ + nameString.getStr() + }'); } -// if anything's left, that's the middle name -this.middle = name.getStr(); +// if anything's left, that's the middle nameString +this.middle = nameString.getStr(); + +return new Name(leadingInit, first, nickname, middle, last, suffix); } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/685f9a86/src/main/java/org/apache/commons/text/names/Name.java -- diff --git a/src/main/java/org/apache/commons/text/names/Name.java b/src/main/java/org/apache/commons/text/names/Name.java index 0dd2560..3067ba5 100644 --- a/src/main/java/org/apache/commons/text/names/Name.java +++ b/src/main/java/org/apache/commons/text/names/Name.java @@ -16,119 +16,70 @@ */ package
[02/13] [text] Pass the name to parse as parameter to the parse method
Pass the name to parse as parameter to the parse method Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/df7e7a7b Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/df7e7a7b Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/df7e7a7b Branch: refs/heads/master Commit: df7e7a7b0aba73a1bf09c41dbd32e913252a8707 Parents: aa29350 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:02:55 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:02:55 2015 +0200 -- .../commons/text/names/HumanNameParser.java | 52 ++-- .../commons/text/names/HumanNameParserTest.java | 4 +- 2 files changed, 16 insertions(+), 40 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/df7e7a7b/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index 5088bba..bf8f9ed 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -65,10 +65,6 @@ import org.apache.commons.lang3.StringUtils; public class HumanNameParser { /** - * Name parsed. - */ -private Name name; -/** * Leading init part. */ private String leadingInit; @@ -103,21 +99,8 @@ public class HumanNameParser { /** * Creates a parser given a string name. - * - * @param name string name - */ -public HumanNameParser(String name) { -this(new Name(name)); -} - -/** - * Creates a parser given a {@code Name} object. - * - * @param name {@code Name} */ -public HumanNameParser(Name name) { -this.name = name; - +public HumanNameParser() { this.leadingInit = ; this.first = ; this.nickname = ; @@ -125,9 +108,9 @@ public class HumanNameParser { this.last = ; this.suffix = ; -this.suffixes = Arrays.asList(new String[] { +this.suffixes = Arrays.asList(new String[]{ esq, esquire, jr, -sr, 2, ii, iii, iv }); +sr, 2, ii, iii, iv}); this.prefixes = Arrays .asList(new String[] { bar, ben, bin, da, dal, @@ -137,15 +120,6 @@ public class HumanNameParser { } /** - * Gets the {@code Name} object. - * - * @return the {@code Name} object - */ -public Name getName() { -return name; -} - -/** * Gets the leading init part of the name. * * @return the leading init part of the name @@ -220,9 +194,11 @@ public class HumanNameParser { /** * Consumes the string and creates the name parts. * + * @param nameStr the name to parse. * @throws NameParseException if the parser fails to retrieve the name parts */ -public void parse() { +public void parse(String nameStr) { +Name name = new Name(nameStr); String suffixes = StringUtils.join(this.suffixes, \\.*|) + \\.*; String prefixes = StringUtils.join(this.prefixes, |) + ; @@ -238,28 +214,28 @@ public class HumanNameParser { String firstRegex = (?i)^([^ ]+); // get nickname, if there is one -this.nickname = this.name.chopWithRegex(nicknamesRegex, 2); +this.nickname = name.chopWithRegex(nicknamesRegex, 2); // get suffix, if there is one -this.suffix = this.name.chopWithRegex(suffixRegex, 1); +this.suffix = name.chopWithRegex(suffixRegex, 1); // flip the before-comma and after-comma parts of the name -this.name.flip(,); +name.flip(,); // get the last name -this.last = this.name.chopWithRegex(lastRegex, 0); +this.last = name.chopWithRegex(lastRegex, 0); // get the first initial, if there is one -this.leadingInit = this.name.chopWithRegex(leadingInitRegex, 1); +this.leadingInit = name.chopWithRegex(leadingInitRegex, 1); // get the first name -this.first = this.name.chopWithRegex(firstRegex, 0); +this.first = name.chopWithRegex(firstRegex, 0); if (StringUtils.isBlank(this.first)) { -throw new NameParseException(Couldn't find a first name in '{ + this.name.getStr() + }'); +throw new NameParseException(Couldn't find a first name in '{ + name.getStr() + }'); } // if anything's left, that's the middle name -this.middle = this.name.getStr(); +this.middle = name.getStr(); } }
[03/13] [text] Check for null inputs
Check for null inputs Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/9a0cc85a Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/9a0cc85a Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/9a0cc85a Branch: refs/heads/master Commit: 9a0cc85ad01dcf1f468736984cdd5dec0a7a3bf3 Parents: df7e7a7 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:06:09 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:06:09 2015 +0200 -- .../java/org/apache/commons/text/names/HumanNameParser.java | 8 ++-- .../org/apache/commons/text/names/HumanNameParserTest.java | 6 ++ 2 files changed, 12 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/9a0cc85a/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index bf8f9ed..fa2433a 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -19,6 +19,7 @@ package org.apache.commons.text.names; import java.util.Arrays; import java.util.List; +import java.util.Objects; import org.apache.commons.lang3.StringUtils; @@ -194,10 +195,13 @@ public class HumanNameParser { /** * Consumes the string and creates the name parts. * - * @param nameStr the name to parse. - * @throws NameParseException if the parser fails to retrieve the name parts + * @param nameStr the name to parse. Must not be null. + * @throws NameParseException if the parser fails to retrieve the name parts. + * @throws NullPointerException if nameStr is null. */ public void parse(String nameStr) { +Objects.requireNonNull(nameStr, Parameter 'nameStr' must not be null.); + Name name = new Name(nameStr); String suffixes = StringUtils.join(this.suffixes, \\.*|) + \\.*; String prefixes = StringUtils.join(this.prefixes, |) + ; http://git-wip-us.apache.org/repos/asf/commons-text/blob/9a0cc85a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java -- diff --git a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java index 478d19c..d43d2be 100644 --- a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java +++ b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java @@ -50,6 +50,12 @@ public class HumanNameParserTest { } } +@Test(expected = NullPointerException.class) +public void shouldThrowNullPointerException_WhenNullIsParsed() throws Exception { +HumanNameParser parser = new HumanNameParser(); +parser.parse(null); +} + @Test public void testInputs() { for (CSVRecord record : parser) {
[01/13] [text] Make parse method public
Repository: commons-text Updated Branches: refs/heads/master e8e85d9de - bf8bfb0a4 Make parse method public Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/aa293500 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/aa293500 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/aa293500 Branch: refs/heads/master Commit: aa293500080d6872b3ac653dcf74a50cf8223ae5 Parents: e8e85d9 Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 15:58:16 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 15:58:16 2015 +0200 -- src/main/java/org/apache/commons/text/names/HumanNameParser.java | 4 +--- .../java/org/apache/commons/text/names/HumanNameParserTest.java | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/aa293500/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index 843685a..5088bba 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -134,8 +134,6 @@ public class HumanNameParser { de la, de, del, der, di, ibn, la, le, san, st, ste, van, van der, van den, vel, von }); - -this.parse(); } /** @@ -224,7 +222,7 @@ public class HumanNameParser { * * @throws NameParseException if the parser fails to retrieve the name parts */ -private void parse() { +public void parse() { String suffixes = StringUtils.join(this.suffixes, \\.*|) + \\.*; String prefixes = StringUtils.join(this.prefixes, |) + ; http://git-wip-us.apache.org/repos/asf/commons-text/blob/aa293500/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java -- diff --git a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java index 90e1dfa..5ff7805 100644 --- a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java +++ b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java @@ -65,6 +65,7 @@ public class HumanNameParserTest { */ private void validateRecord(CSVRecord record) { HumanNameParser parser = new HumanNameParser(record.get(Colums.Name)); +parser.parse(); long recordNum = record.getRecordNumber(); assertThat(Wrong LeadingInit in record + recordNum,
[10/13] [text] Condition will always be true
Condition will always be true Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/b1c7e564 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/b1c7e564 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/b1c7e564 Branch: refs/heads/master Commit: b1c7e564251e7a404aa3d021c282349150fd4061 Parents: ed985cd Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:45:49 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:45:49 2015 +0200 -- .../org/apache/commons/text/names/NameString.java | 14 ++ 1 file changed, 6 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/b1c7e564/src/main/java/org/apache/commons/text/names/NameString.java -- diff --git a/src/main/java/org/apache/commons/text/names/NameString.java b/src/main/java/org/apache/commons/text/names/NameString.java index 54e2753..21898d3 100644 --- a/src/main/java/org/apache/commons/text/names/NameString.java +++ b/src/main/java/org/apache/commons/text/names/NameString.java @@ -98,14 +98,12 @@ final class NameString { */ void flip(String flipAroundChar) { String[] parts = this.str.split(flipAroundChar); -if (parts != null) { -if (parts.length == 2) { -this.str = String.format(%s %s, parts[1], parts[0]); -this.norm(); -} else if (parts.length 2) { -throw new NameParseException( -Can't flip around multiple ' + flipAroundChar + ' characters in namestring.); -} +if (parts.length == 2) { +this.str = String.format(%s %s, parts[1], parts[0]); +this.norm(); +} else if (parts.length 2) { +throw new NameParseException( +Can't flip around multiple ' + flipAroundChar + ' characters in namestring.); } }
[08/13] [text] Make classes in the name package final.
Make classes in the name package final. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/9e340643 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/9e340643 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/9e340643 Branch: refs/heads/master Commit: 9e340643cfebd7b4088fd9946b3e92fc9f8cd394 Parents: a942b4c Author: Benedikt Ritter brit...@apache.org Authored: Sun Apr 19 16:32:31 2015 +0200 Committer: Benedikt Ritter brit...@apache.org Committed: Sun Apr 19 16:32:31 2015 +0200 -- src/main/java/org/apache/commons/text/names/HumanNameParser.java | 2 +- .../java/org/apache/commons/text/names/NameParseException.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/9e340643/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index c47abde..a29e375 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -63,7 +63,7 @@ import org.apache.commons.lang3.StringUtils; * * pThis class is immutable./p */ -public class HumanNameParser { +public final class HumanNameParser { /** * Suffixes found. http://git-wip-us.apache.org/repos/asf/commons-text/blob/9e340643/src/main/java/org/apache/commons/text/names/NameParseException.java -- diff --git a/src/main/java/org/apache/commons/text/names/NameParseException.java b/src/main/java/org/apache/commons/text/names/NameParseException.java index b09c2d6..4fe5eda 100644 --- a/src/main/java/org/apache/commons/text/names/NameParseException.java +++ b/src/main/java/org/apache/commons/text/names/NameParseException.java @@ -19,7 +19,7 @@ package org.apache.commons.text.names; /** * Name parse exception. */ -public class NameParseException extends RuntimeException { +public final class NameParseException extends RuntimeException { /** * Serial UID.
[text] Renaming variables to simpler names
Repository: commons-text Updated Branches: refs/heads/SANDBOX-498-KINOW [created] c5785647e Renaming variables to simpler names Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/c5785647 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/c5785647 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/c5785647 Branch: refs/heads/SANDBOX-498-KINOW Commit: c5785647efbb802cdfc5fc74dc1ee4457ca525d0 Parents: c4e8a3e Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sun Apr 19 22:17:15 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 19 22:17:15 2015 +1200 -- .../commons/text/names/HumanNameParser.java | 26 ++-- 1 file changed, 13 insertions(+), 13 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/c5785647/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index 843685a..659ec95 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -75,7 +75,7 @@ public class HumanNameParser { /** * First name. */ -private String first; +private String firstName; /** * Single nickname found in the name input. */ @@ -83,11 +83,11 @@ public class HumanNameParser { /** * Middle name. */ -private String middle; +private String middleName; /** * Last name. */ -private String last; +private String lastName; /** * Name suffix. */ @@ -119,10 +119,10 @@ public class HumanNameParser { this.name = name; this.leadingInit = ; -this.first = ; +this.firstName = ; this.nickname = ; -this.middle = ; -this.last = ; +this.middleName = ; +this.lastName = ; this.suffix = ; this.suffixes = Arrays.asList(new String[] { @@ -162,7 +162,7 @@ public class HumanNameParser { * @return first name */ public String getFirst() { -return first; +return firstName; } /** @@ -180,7 +180,7 @@ public class HumanNameParser { * @return the middle name */ public String getMiddle() { -return middle; +return middleName; } /** @@ -189,7 +189,7 @@ public class HumanNameParser { * @return the last name */ public String getLast() { -return last; +return lastName; } /** @@ -249,19 +249,19 @@ public class HumanNameParser { this.name.flip(,); // get the last name -this.last = this.name.chopWithRegex(lastRegex, 0); +this.lastName = this.name.chopWithRegex(lastRegex, 0); // get the first initial, if there is one this.leadingInit = this.name.chopWithRegex(leadingInitRegex, 1); // get the first name -this.first = this.name.chopWithRegex(firstRegex, 0); -if (StringUtils.isBlank(this.first)) { +this.firstName = this.name.chopWithRegex(firstRegex, 0); +if (StringUtils.isBlank(this.firstName)) { throw new NameParseException(Couldn't find a first name in '{ + this.name.getStr() + }'); } // if anything's left, that's the middle name -this.middle = this.name.getStr(); +this.middleName = this.name.getStr(); } }
Git Push Summary
Repository: commons-text Updated Branches: refs/heads/SANDBOX-498-KINOW [deleted] c5785647e
[text] SANDBOX-498 Add parser options and initialise regular expressions once
Repository: commons-text Updated Branches: refs/heads/SANDBOX-498-OPTIONS [created] 331f80bfc SANDBOX-498 Add parser options and initialise regular expressions once Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/331f80bf Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/331f80bf Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/331f80bf Branch: refs/heads/SANDBOX-498-OPTIONS Commit: 331f80bfcf0380fcc35a6d18a327aef4a9e844e4 Parents: bf8bfb0 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Mon Apr 20 15:41:05 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Mon Apr 20 15:41:09 2015 +1200 -- .../commons/text/names/HumanNameParser.java | 73 .../commons/text/names/ParserOptions.java | 59 2 files changed, 102 insertions(+), 30 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/331f80bf/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index 5407d15..e7a3927 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -17,8 +17,6 @@ */ package org.apache.commons.text.names; -import java.util.Arrays; -import java.util.List; import java.util.Objects; import org.apache.commons.lang3.StringUtils; @@ -100,22 +98,51 @@ import org.apache.commons.lang3.StringUtils; */ public final class HumanNameParser { -private final ListString suffixes; -private final ListString prefixes; +/** + * The options used by the parser. + */ +private final ParserOptions options; + +/* + * Regular expressions used by the parser. + */ +// The regex use is a bit tricky. *Everything* matched by the regex will be replaced, +// but you can select a particular parenthesized submatch to be returned. +// Also, note that each regex requres that the preceding ones have been run, and matches chopped out. +// names that starts or end w/ an apostrophe break this +private final static String NICKNAMES_REGEX = (?i) ('|\\\|\\(\\\*'*)(.+?)('|\\\|\\\*'*\\)) ; +// note the lookahead, which isn't returned or replaced +private final static String LEADING_INIT_REGEX = (?i)(^(.\\.*)(?= \\p{L}{2})); +private final static String FIRST_NAME_REGEX = (?i)^([^ ]+); +private final String suffixRegex; +private final String lastRegex; + /** * Creates a new parser. */ public HumanNameParser() { -// TODO make this configurable -this.suffixes = Arrays.asList( -esq, esquire, jr, -sr, 2, ii, iii, iv); -this.prefixes = Arrays.asList( -bar, ben, bin, da, dal, -de la, de, del, der, di, ibn, la, le, -san, st, ste, van, van der, van den, vel, -von ); +this(ParserOptions.DEFAULT_OPTIONS); +} + +/** + * Creates a new parser by providing options. + */ +public HumanNameParser(ParserOptions options) { +this.options = options; +final String suffixes = StringUtils.join(options.getSuffixes(), \\.*|) + \\.*; +final String prefixes = StringUtils.join(options.getPrefixes(), |) + ; +suffixRegex = (?i),* *(( + suffixes + )$); +lastRegex = (?i)(?!^)\\b([^ ]+ y | + prefixes + )*[^ ]+$; +} + +/** + * Gets the parser options. + * + * @return parser options + */ +public ParserOptions getOptions() { +return options; } /** @@ -129,23 +156,9 @@ public final class HumanNameParser { Objects.requireNonNull(name, Parameter 'name' must not be null.); NameString nameString = new NameString(name); -// TODO compile regexes only once when the parser is created -String suffixes = StringUtils.join(this.suffixes, \\.*|) + \\.*; -String prefixes = StringUtils.join(this.prefixes, |) + ; - -// The regex use is a bit tricky. *Everything* matched by the regex will be replaced, -// but you can select a particular parenthesized submatch to be returned. -// Also, note that each regex requres that the preceding ones have been run, and matches chopped out. -// names that starts or end w/ an apostrophe break this -String nicknamesRegex = (?i) ('|\\\|\\(\\\*'*)(.+?)('|\\\|\\\*'*\\)) ; -String suffixRegex = (?i),* *(( + suffixes + )$); -String lastRegex =
[text] Fix Java8 javadoc warnings
Repository: commons-text Updated Branches: refs/heads/master bf8bfb0a4 - 0e7aad06a Fix Java8 javadoc warnings Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/0e7aad06 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/0e7aad06 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/0e7aad06 Branch: refs/heads/master Commit: 0e7aad06a4967bec1581b88cdf706bed32599d4c Parents: bf8bfb0 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Wed Apr 22 22:53:56 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Wed Apr 22 22:53:56 2015 +1200 -- src/main/java/org/apache/commons/text/names/HumanNameParser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/0e7aad06/src/main/java/org/apache/commons/text/names/HumanNameParser.java -- diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java index 5407d15..9d6c2fc 100644 --- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java +++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java @@ -33,7 +33,7 @@ import org.apache.commons.lang3.StringUtils; * a {@link Name} object representing the parse result. Note that passing null * to the {@link #parse(String)} method will result in an exception./p * - * table + * table summary=Examples * tr * thinput/th * thLeading initial/th @@ -124,6 +124,7 @@ public final class HumanNameParser { * @param name the name to parse. Must not be null. * @throws NameParseException if the parser fails to retrieve the name parts. * @throws NullPointerException if name is null. + * @return The name object */ public Name parse(String name) { Objects.requireNonNull(name, Parameter 'name' must not be null.);
[text] SANDBOX-499 Create Commons Text logo
Repository: commons-text Updated Branches: refs/heads/master 0e7aad06a - 69f252391 SANDBOX-499 Create Commons Text logo Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/69f25239 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/69f25239 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/69f25239 Branch: refs/heads/master Commit: 69f252391261931e1abeea941f8c77efb0f8e230 Parents: 0e7aad0 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Wed Apr 22 22:55:23 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Wed Apr 22 22:55:23 2015 +1200 -- src/changes/changes.xml| 1 + src/media/logo.xcf | Bin 0 - 17288 bytes src/site/resources/images/logo.png | Bin 0 - 10143 bytes 3 files changed, 1 insertion(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/69f25239/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0a77677..c9f97e0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-499 type=add dev=kinowCreate Commons Text logo/action action issue=SANDBOX-498 type=update dev=britterImprove HumanNameParser/action action issue=SANDBOX-497 type=fix dev=kinowIP clearance for the names package/action action issue=SANDBOX-496 type=add dev=kinowWrite user guide/action http://git-wip-us.apache.org/repos/asf/commons-text/blob/69f25239/src/media/logo.xcf -- diff --git a/src/media/logo.xcf b/src/media/logo.xcf new file mode 100644 index 000..8b4d188 Binary files /dev/null and b/src/media/logo.xcf differ http://git-wip-us.apache.org/repos/asf/commons-text/blob/69f25239/src/site/resources/images/logo.png -- diff --git a/src/site/resources/images/logo.png b/src/site/resources/images/logo.png new file mode 100644 index 000..48d4609 Binary files /dev/null and b/src/site/resources/images/logo.png differ
[text] TEXT-16: Make ParserOptions immutable
Repository: commons-text Updated Branches: refs/heads/SANDBOX-498-OPTIONS 331f80bfc - 4310744eb TEXT-16: Make ParserOptions immutable Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/4310744e Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/4310744e Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/4310744e Branch: refs/heads/SANDBOX-498-OPTIONS Commit: 4310744eb62e735a39ff84840cd4eb41ae6eb5a6 Parents: 331f80b Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sat May 2 23:46:06 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sat May 2 23:46:06 2015 +1200 -- .../commons/text/names/ParserOptions.java | 44 +--- .../commons/text/names/NameStringTest.java | 6 -- .../commons/text/names/ParserOptionsTest.java | 72 3 files changed, 105 insertions(+), 17 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/4310744e/src/main/java/org/apache/commons/text/names/ParserOptions.java -- diff --git a/src/main/java/org/apache/commons/text/names/ParserOptions.java b/src/main/java/org/apache/commons/text/names/ParserOptions.java index 6bca771..dcde9ae 100644 --- a/src/main/java/org/apache/commons/text/names/ParserOptions.java +++ b/src/main/java/org/apache/commons/text/names/ParserOptions.java @@ -17,43 +17,65 @@ package org.apache.commons.text.names; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Set; +import org.apache.commons.lang3.Validate; + /** * Options for the {@link HumanNameParser} parser. */ public final class ParserOptions { -public static final ParserOptions DEFAULT_OPTIONS = new ParserOptions(); +private static final SetString DEFAULT_PREFIXES = new HashSetString(Arrays.asList( +bar, ben, bin, da, dal, +de la, de, del, der, di, ibn, la, le, +san, st, ste, van, van der, van den, vel, +von)); + +private static final SetString DEFAULT_SUFFIXES = new HashSetString(Arrays.asList( +esq, esquire, jr, +sr, 2, ii, iii, iv)); private final SetString suffixes; private final SetString prefixes; +public static final ParserOptions DEFAULT_OPTIONS = new ParserOptions(); + +/** + * Creates options for the human names parser. + */ public ParserOptions() { -this.suffixes = new HashSetString(Arrays.asList( -esq, esquire, jr, -sr, 2, ii, iii, iv)); -this.prefixes = new HashSetString(Arrays.asList( -bar, ben, bin, da, dal, -de la, de, del, der, di, ibn, la, le, -san, st, ste, van, van der, van den, vel, -von)); +this(DEFAULT_PREFIXES, DEFAULT_SUFFIXES); +} + +/** + * Creates options for the human names parser. + * + * @param prefixes name prefixes, must not be null + * @param suffixes name suffixes, must not be null + */ +public ParserOptions(SetString prefixes, SetString suffixes) { +Validate.notNull(prefixes, Prefixes must not be null); +Validate.notNull(prefixes, Suffixes must not be null); +this.prefixes = prefixes; +this.suffixes = suffixes; } /** * @return the suffixes */ public SetString getSuffixes() { -return suffixes; +return Collections.unmodifiableSet(suffixes); } /** * @return the prefixes */ public SetString getPrefixes() { -return prefixes; +return Collections.unmodifiableSet(prefixes); } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/4310744e/src/test/java/org/apache/commons/text/names/NameStringTest.java -- diff --git a/src/test/java/org/apache/commons/text/names/NameStringTest.java b/src/test/java/org/apache/commons/text/names/NameStringTest.java index e087579..4431d4a 100644 --- a/src/test/java/org/apache/commons/text/names/NameStringTest.java +++ b/src/test/java/org/apache/commons/text/names/NameStringTest.java @@ -37,14 +37,11 @@ public class NameStringTest { @Test public void testChopWithRegexReturnsChoppedSubstring() { -NameString nameString = new NameString(Björn O'Malley); - assertThat(nameString.chopWithRegex((^([^ ]+))(.+), 1), equalTo(Björn)); } @Test public void testChopWithRegexChopsStartOffNameStr() { -NameString nameString = new NameString(Björn O'Malley); nameString.chopWithRegex((^[^ ]+), 0); assertThat(nameString.getWrappedString(),
[text] Add changes for SANDBOX-488
Repository: commons-text Updated Branches: refs/heads/master b0b9d358c - e9ce5a7ef Add changes for SANDBOX-488 Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e9ce5a7e Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e9ce5a7e Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e9ce5a7e Branch: refs/heads/master Commit: e9ce5a7efb0e6255e0d46a127f4234cd83adb5b2 Parents: b0b9d35 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Thu Apr 16 23:27:01 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Thu Apr 16 23:27:01 2015 +1200 -- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/e9ce5a7e/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index fce5c14..c4cbe05 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-488 type=fix dev=kinowWork on the string metric, distance, and similarity definitions for the project/action action issue=SANDBOX-487 type=add dev=kinowHuman name parser/action action issue=SANDBOX-492 type=fix dev=kinow due-to=Jonathan bakerCreate StringDistanceFrom class that contains a StringMetric and the left side string. This would have a method that accepts the right side string to test./action action issue=SANDBOX-490 type=add dev=kinowAdd Cosine Similarity and Cosine Distance/action
[text] Typo in main page
Repository: commons-text Updated Branches: refs/heads/master e9ce5a7ef - 441159fb2 Typo in main page Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/441159fb Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/441159fb Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/441159fb Branch: refs/heads/master Commit: 441159fb2d5259eeae4553c093409023144234c8 Parents: e9ce5a7 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Thu Apr 16 23:28:31 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Thu Apr 16 23:28:31 2015 +1200 -- src/site/xdoc/index.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/441159fb/src/site/xdoc/index.xml -- diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 4539848..c67cff3 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -25,7 +25,7 @@ limitations under the License. section name=Commons Text p -Apache Commons Text is a library focused on algorithms working on strins. +Apache Commons Text is a library focused on algorithms working on strings. /p /section
[text] SANDBOX-488 Use an interface for EditDistance, and leave separate classes as utility objects
Repository: commons-text Updated Branches: refs/heads/master 67ab6de8a - b0b9d358c SANDBOX-488 Use an interface for EditDistance, and leave separate classes as utility objects Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/b0b9d358 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/b0b9d358 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/b0b9d358 Branch: refs/heads/master Commit: b0b9d358cc44e8e52d0675abf49eaefac003a112 Parents: 67ab6de Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Wed Apr 15 21:52:30 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Wed Apr 15 21:52:30 2015 +1200 -- .../commons/text/similarity/CosineDistance.java | 4 +- .../text/similarity/CosineSimilarity.java | 2 +- .../commons/text/similarity/EditDistance.java | 48 .../text/similarity/EditDistanceFrom.java | 112 +++ .../commons/text/similarity/FuzzyScore.java | 23 ++-- .../text/similarity/HammingDistance.java| 4 +- .../text/similarity/JaroWrinklerDistance.java | 8 +- .../text/similarity/LevenshteinDistance.java| 4 +- .../commons/text/similarity/StringMetric.java | 47 .../text/similarity/StringMetricFrom.java | 111 -- .../commons/text/similarity/FuzzyScoreTest.java | 20 ++-- .../ParameterizedEditDistanceFromTest.java | 92 +++ .../ParameterizedStringMetricFromTest.java | 92 --- .../text/similarity/StringMetricFromTest.java | 14 +-- 14 files changed, 295 insertions(+), 286 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/b0b9d358/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java index f9fcf39..98ef49e 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -28,9 +28,9 @@ import org.apache.commons.text.similarity.internal.Tokenizer; * pIt utilizes the CosineSimilarity to compute the distance. Character sequences * are converted into vectors through a simple tokenizer that works with /p * - * @since 0.1 + * @since 1.0 */ -public class CosineDistance implements StringMetricDouble { +public class CosineDistance implements EditDistanceDouble { /** * Tokenizer used to convert the character sequence into a vector. */ http://git-wip-us.apache.org/repos/asf/commons-text/blob/b0b9d358/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java index 4b29a04..cf21186 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java @@ -29,7 +29,7 @@ import java.util.Set; * http://en.wikipedia.org/wiki/Cosine_similarity. * /p * - * @since 0.1 + * @since 1.0 */ public class CosineSimilarity { http://git-wip-us.apache.org/repos/asf/commons-text/blob/b0b9d358/src/main/java/org/apache/commons/text/similarity/EditDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/EditDistance.java b/src/main/java/org/apache/commons/text/similarity/EditDistance.java new file mode 100644 index 000..824522a --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/EditDistance.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +/** + * Interface for a
[text] SANDBOX-496 Write user guide
Repository: commons-text Updated Branches: refs/heads/master f2f24aa6f - d39dbb548 SANDBOX-496 Write user guide Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/d39dbb54 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/d39dbb54 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/d39dbb54 Branch: refs/heads/master Commit: d39dbb5485b49a2ba1b9cc93738d8a02caf65ecb Parents: f2f24aa Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Fri Apr 17 18:19:18 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Fri Apr 17 18:19:18 2015 +1200 -- src/changes/changes.xml | 1 + .../apache/commons/text/names/package-info.java | 3 +++ .../commons/text/similarity/CosineDistance.java | 1 + .../similarity/internal/RegexTokenizer.java | 2 +- .../commons/text/similarity/package-info.java | 20 src/site/site.xml | 1 - src/site/xdoc/index.xml | 12 ++-- src/site/xdoc/proposal.xml | 2 +- 8 files changed, 33 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/d39dbb54/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c4cbe05..2768608 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-496 type=add dev=kinowWrite user guide/action action issue=SANDBOX-488 type=fix dev=kinowWork on the string metric, distance, and similarity definitions for the project/action action issue=SANDBOX-487 type=add dev=kinowHuman name parser/action action issue=SANDBOX-492 type=fix dev=kinow due-to=Jonathan bakerCreate StringDistanceFrom class that contains a StringMetric and the left side string. This would have a method that accepts the right side string to test./action http://git-wip-us.apache.org/repos/asf/commons-text/blob/d39dbb54/src/main/java/org/apache/commons/text/names/package-info.java -- diff --git a/src/main/java/org/apache/commons/text/names/package-info.java b/src/main/java/org/apache/commons/text/names/package-info.java index 1423d24..868f6e1 100644 --- a/src/main/java/org/apache/commons/text/names/package-info.java +++ b/src/main/java/org/apache/commons/text/names/package-info.java @@ -17,6 +17,9 @@ /** * pA human names parser in Java./p * + * pThe parser can parse different name formats, producing parts of names such as + * first and last name, prefix, suffix and nickname./p + * * @since 1.0 */ package org.apache.commons.text.names; http://git-wip-us.apache.org/repos/asf/commons-text/blob/d39dbb54/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java index 98ef49e..d4eeae5 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -28,6 +28,7 @@ import org.apache.commons.text.similarity.internal.Tokenizer; * pIt utilizes the CosineSimilarity to compute the distance. Character sequences * are converted into vectors through a simple tokenizer that works with /p * + * @see org.apache.commons.text.similarity.internal.RegexTokenizer * @since 1.0 */ public class CosineDistance implements EditDistanceDouble { http://git-wip-us.apache.org/repos/asf/commons-text/blob/d39dbb54/src/main/java/org/apache/commons/text/similarity/internal/RegexTokenizer.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/internal/RegexTokenizer.java b/src/main/java/org/apache/commons/text/similarity/internal/RegexTokenizer.java index cf49536..743baa3 100644 --- a/src/main/java/org/apache/commons/text/similarity/internal/RegexTokenizer.java +++ b/src/main/java/org/apache/commons/text/similarity/internal/RegexTokenizer.java @@ -23,7 +23,7 @@ import java.util.regex.Pattern; /** * A simple word tokenizer that utilizes regex to find words. It applies a regex - * {@code}(\\w)+{@code} over the input text to extract words from a given character + * {@code}(\w)+{@code} over the input text to extract words from a given character * sequence. * * @since 0.1 http://git-wip-us.apache.org/repos/asf/commons-text/blob/d39dbb54/src/main
[text] Fix TODO tags in test
Repository: commons-text Updated Branches: refs/heads/master 441159fb2 - f2f24aa6f Fix TODO tags in test Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/f2f24aa6 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/f2f24aa6 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/f2f24aa6 Branch: refs/heads/master Commit: f2f24aa6f589401094f998cd27d677473d4ad4ac Parents: 441159f Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Fri Apr 17 18:15:33 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Fri Apr 17 18:15:33 2015 +1200 -- .../text/similarity/ParameterizedEditDistanceFromTest.java | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/f2f24aa6/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java -- diff --git a/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java b/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java index 5a4d6d1..51f3e23 100644 --- a/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java +++ b/src/test/java/org/apache/commons/text/similarity/ParameterizedEditDistanceFromTest.java @@ -20,6 +20,7 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertThat; import java.util.Arrays; +import java.util.Locale; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,8 +55,6 @@ public class ParameterizedEditDistanceFromTestR { public static IterableObject[] parameters() { return Arrays.asList( new Object[][] { -/* TODO: When SANDBOX-491 is ready, add a few FuzzyScore tests. */ - { new HammingDistance(), Sam I am., Ham I am., 1 }, { new HammingDistance(), Japtheth, Ham, Shem, Japtheth, HAM, Shem, 2 }, { new HammingDistance(), Hamming, Hamming, 0 }, @@ -64,11 +63,14 @@ public class ParameterizedEditDistanceFromTestR { { new JaroWrinklerDistance(), hippo, elephant, 0.44 }, { new JaroWrinklerDistance(), hippo, , 0.0 }, -/* TODO: When SANDBOX-491 is ready, add a few limited/threshold tests. */ { new LevenshteinDistance(), Apache, a patchy, 4 }, { new LevenshteinDistance(), go, no go, 3 }, { new LevenshteinDistance(), go, go, 0 }, +{ new LevenshteinDistance(4), Apache, a patchy, 4 }, +{ new LevenshteinDistance(4), go, no go, 3 }, +{ new LevenshteinDistance(0), go, go, 0 }, + { new EditDistanceBoolean() { public Boolean apply(CharSequence left, CharSequence right) {
[2/2] [text] Add changes to SANDBOX-490
Add changes to SANDBOX-490 Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/376c7c4d Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/376c7c4d Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/376c7c4d Branch: refs/heads/master Commit: 376c7c4d86d5c0e899da67d4ed81b7dc456fdd58 Parents: 548a791 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sun Apr 12 23:30:58 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 12 23:30:58 2015 +1200 -- src/changes/changes.xml | 1 + 1 file changed, 1 insertion(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/376c7c4d/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 553d55b..4ac588a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-490 type=add dev=kinowAdd Cosine Similarity and Cosine Distance/action action issue=SANDBOX-493 type=fix dev=kinow due-to=Jonathan BakerChange (R) StringMetric.compare(CS left, CS right) to apply so that it is consistent with BiFunction./action action issue=SANDBOX-491 type=fix dev=kinow due-to=Jonathan BakerAllow extra information (e.g. Levenshtein threshold) to be stored as (final) fields in the StringMetric instance./action action issue=SANDBOX-486 type=add dev=kinowPort Myers algorithm from [collections]/action
[text] [SANDBOX-492] Create StringDistanceFrom class that contains a StringMetric and the left side string. This would have a method that accepts the right side string to test.
Repository: commons-text Updated Branches: refs/heads/master a5ac07106 - 6280d46c5 [SANDBOX-492] Create StringDistanceFrom class that contains a StringMetric and the left side string. This would have a method that accepts the right side string to test. This fixes #3 from GitHub. Thanks to Jonathan Baker. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/6280d46c Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/6280d46c Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/6280d46c Branch: refs/heads/master Commit: 6280d46c5d5e87e0491573efa969fcf4a6397cd7 Parents: a5ac071 Author: j--baker j--ba...@users.noreply.github.com Authored: Wed Mar 4 15:20:18 2015 -0500 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Mon Apr 13 00:48:45 2015 +1200 -- src/changes/changes.xml | 1 + .../text/similarity/StringMetricFrom.java | 111 +++ .../ParameterizedStringMetricFromTest.java | 92 +++ .../text/similarity/StringMetricFromTest.java | 71 4 files changed, 275 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/6280d46c/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4ac588a..45ac073 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,7 @@ body release version=1.0 date=tba description=tba +action issue=SANDBOX-492 type=fix dev=kinow due-to=Jonathan bakerCreate StringDistanceFrom class that contains a StringMetric and the left side string. This would have a method that accepts the right side string to test./action action issue=SANDBOX-490 type=add dev=kinowAdd Cosine Similarity and Cosine Distance/action action issue=SANDBOX-493 type=fix dev=kinow due-to=Jonathan BakerChange (R) StringMetric.compare(CS left, CS right) to apply so that it is consistent with BiFunction./action action issue=SANDBOX-491 type=fix dev=kinow due-to=Jonathan BakerAllow extra information (e.g. Levenshtein threshold) to be stored as (final) fields in the StringMetric instance./action http://git-wip-us.apache.org/repos/asf/commons-text/blob/6280d46c/src/main/java/org/apache/commons/text/similarity/StringMetricFrom.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/StringMetricFrom.java b/src/main/java/org/apache/commons/text/similarity/StringMetricFrom.java new file mode 100644 index 000..3b2a871 --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/StringMetricFrom.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +/** + * p + * This stores a {@link StringMetric} implementation and a {@link CharSequence} left string. + * The {@link #apply(CharSequence right)} method accepts the right string and invokes the + * comparison function for the pair of strings. + * /p + * + * p + * The following is an example which finds the most similar string: + * /p + * pre + * StringMetriclt;Integergt; metric = new LevenshteinDistance(); + * String target = Apache; + * StringMetricFromlt;Integergt; metricFrom = + * new StringMetricFromlt;Integergt;(metric, target); + * String mostSimilar = null; + * Integer shortestDistance = null; + * + * for (String test : new String[] { Appaloosa, a patchy, apple }) { + * Integer distance = metricFrom.apply(test); + * if (shortestDistance == null || distance lt; shortestDistance) { + * shortestDistance = distance; + * mostSimilar = test; + * } + * } + * + * System.out.println(The string most similar to \ + target + \ + * + is \ + mostSimilar + \ because + * + its distance is only + shortestDistance + .); + * /pre + * + * @param R This is the type of similarity score used by the StringMetric function
[text] [SANDBOX-490] Add cosine similarity and cosine distance. Strings are converted into vectors using a simple regex tokenizer. Vectors are used to get the cosine similarity and, finally, the dista
Repository: commons-text Updated Branches: refs/heads/master 980791b69 - 3ccdabb1e [SANDBOX-490] Add cosine similarity and cosine distance. Strings are converted into vectors using a simple regex tokenizer. Vectors are used to get the cosine similarity and, finally, the distance is equal to 1.0 - the distance. New classes used by the cosine distance and the cosine similarity had to be created (including the tokenizers). These classes were put in a new internal package, annotated accordingly. Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/3ccdabb1 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/3ccdabb1 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/3ccdabb1 Branch: refs/heads/master Commit: 3ccdabb1e27bd41bf88e5b623136481d989b2b0e Parents: 980791b Author: Bruno P. Kinoshita ki...@apache.org Authored: Sat Feb 14 14:23:42 2015 -0200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 12 23:25:06 2015 +1200 -- pom.xml | 4 + .../commons/text/similarity/CosineDistance.java | 54 + .../text/similarity/CosineSimilarity.java | 101 + .../text/similarity/JaccardDistance.java| 21 ++ .../commons/text/similarity/JaccardIndex.java | 21 ++ .../text/similarity/internal/Counter.java | 61 ++ .../similarity/internal/RegexTokenizer.java | 52 + .../text/similarity/internal/Tokenizer.java | 35 .../text/similarity/internal/package-info.java | 23 +++ .../commons/text/checkstyle-suppressions.xml| 28 +++ .../org/apache/commons/text/checkstyle.xml | 206 +++ .../org/apache/commons/text/fb-excludes.xml | 19 ++ .../org/apache/commons/text/license-header.txt | 16 ++ .../text/similarity/CosineDistanceTest.java | 72 +++ 14 files changed, 713 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/3ccdabb1/pom.xml -- diff --git a/pom.xml b/pom.xml index 2f46e9a..6b2a50f 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,10 @@ version2.13/version configuration enableRulesSummaryfalse/enableRulesSummary + configLocation${basedir}/src/main/resources/org/apache/commons/text/checkstyle.xml/configLocation + headerLocation${basedir}/src/main/resources/org/apache/commons/text/license-header.txt/headerLocation + suppressionsLocation${basedir}/src/main/resources/org/apache/commons/text/checkstyle-suppressions.xml/suppressionsLocation + suppressionsFileExpression${basedir}/src/main/resources/org/apache/commons/text/checkstyle-suppressions.xml/suppressionsFileExpression /configuration reportSets reportSet http://git-wip-us.apache.org/repos/asf/commons-text/blob/3ccdabb1/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java new file mode 100644 index 000..69cfad7 --- /dev/null +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the License); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +import java.util.Map; + +import org.apache.commons.text.similarity.internal.Counter; +import org.apache.commons.text.similarity.internal.RegexTokenizer; +import org.apache.commons.text.similarity.internal.Tokenizer; + +/** + * Measures the cosine distance between two character sequences. + * + * pIt utilizes the CosineSimilarity to compute the distance. Character sequences + * are converted into vectors through a simple tokenizer that works with /p + * + * @since 0.1 + */ +public class CosineDistance implements StringMetricDouble { +/** + * Tokenizer used to convert
[1/2] [text] Code style, formatting and removing unused classes
Repository: commons-text Updated Branches: refs/heads/NEW-METRICS 81f679dea - e99b839ad Code style, formatting and removing unused classes Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e00d85b3 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e00d85b3 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e00d85b3 Branch: refs/heads/NEW-METRICS Commit: e00d85b38632dce4758f32b3e4af6afcecd66d3c Parents: 81f679d Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sun Apr 12 21:52:33 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 12 21:52:33 2015 +1200 -- .../commons/text/similarity/CosineDistance.java | 33 - .../text/similarity/CosineSimilarity.java | 19 +++ .../similarity/internal/CharacterTokenizer.java | 43 .../text/similarity/internal/Counter.java | 24 +++-- .../similarity/internal/RegexTokenizer.java | 52 .../similarity/internal/SimpleTokenizer.java| 50 --- .../similarity/internal/StringTokenizer.java| 36 -- .../text/similarity/internal/Tokenizer.java | 5 +- .../internal/WhiteSpaceTokenizer.java | 46 - .../text/similarity/internal/package-info.java | 6 ++- 10 files changed, 105 insertions(+), 209 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/e00d85b3/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java index 54970e4..6ed2d69 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -19,27 +19,34 @@ package org.apache.commons.text.similarity; import java.util.Map; import org.apache.commons.text.similarity.internal.Counter; -import org.apache.commons.text.similarity.internal.SimpleTokenizer; +import org.apache.commons.text.similarity.internal.RegexTokenizer; import org.apache.commons.text.similarity.internal.Tokenizer; /** - * p - * Calcules the cosine distance. - * /p + * Measures the cosine distance between two character sequences. + * + * pIt utilizes the CosineSimilarity to compute the distance. Character sequences + * are converted into vectors through a simple tokenizer that works with /p + * + * @since 0.1 */ public class CosineDistance implements StringMetricDouble { - -private final TokenizerString tokenizer = new SimpleTokenizer(); - +/** + * Tokenizer used to convert the character sequence into a vector. + */ +private final TokenizerCharSequence tokenizer = new RegexTokenizer(); +/** + * Cosine similarity. + */ private final CosineSimilarity cosineSimilarity = new CosineSimilarity(); - + @Override public Double compare(CharSequence left, CharSequence right) { -String[] leftTokens = tokenizer.tokenize(left); -String[] rightTokens = tokenizer.tokenize(right); - -MapString, Integer leftVector = Counter.of(leftTokens); -MapString, Integer rightVector = Counter.of(rightTokens); +CharSequence[] leftTokens = tokenizer.tokenize(left); +CharSequence[] rightTokens = tokenizer.tokenize(right); + +MapCharSequence, Integer leftVector = Counter.of(leftTokens); +MapCharSequence, Integer rightVector = Counter.of(rightTokens); double similarity = cosineSimilarity.cosineSimilarity(leftVector, rightVector); return 1.0 - similarity; } http://git-wip-us.apache.org/repos/asf/commons-text/blob/e00d85b3/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java index 992e5e9..096f2aa 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineSimilarity.java @@ -20,16 +20,13 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; - /** - * p * Measures the Cosine similarity of two vectors of an inner product space and * compares the angle between them. - * /p * * p - * For further explanation about the Cosine Similarity, take a look at its - * Wikipedia page at http://en.wikipedia.org/wiki/Cosine_similarity. + * For further explanation about the Cosine Similarity, refer to + *
[2/2] [text] Formatting, code style and comments
Formatting, code style and comments Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/e99b839a Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/e99b839a Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/e99b839a Branch: refs/heads/NEW-METRICS Commit: e99b839ad6fc023dd57519e07b8a2f36e2b58b39 Parents: e00d85b Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sun Apr 12 21:54:11 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 12 21:54:11 2015 +1200 -- .../text/similarity/CosineDistanceTest.java | 19 ++- 1 file changed, 18 insertions(+), 1 deletion(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/e99b839a/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java -- diff --git a/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java index ce33572..0d6879a 100644 --- a/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/CosineDistanceTest.java @@ -26,18 +26,29 @@ import org.junit.Test; /** * Unit tests for {@link org.apache.commons.text.similarity.CosineSimilarity}. + * + * @since 0.1 */ public class CosineDistanceTest { +/** + * Cosine distance under test. + */ private static CosineDistance cosineDistance; +/** + * Creates the cosine distance object used throughout the tests. + */ @BeforeClass public static void setUp() { cosineDistance = new CosineDistance(); } +/** + * Tests the cosine distance with several inputs. + */ @Test -public void testCosineSimilarity() { +public void testCosineDistance() { assertEquals(Double.valueOf(0.5d), roundValue(cosineDistance.compare(the house, da house))); assertEquals(Double.valueOf(0.0d), roundValue(cosineDistance.compare(AB, AB))); assertEquals(Double.valueOf(1.0d), roundValue(cosineDistance.compare(AB, BA))); @@ -48,6 +59,12 @@ public class CosineDistanceTest { // --- Utility methods +/** + * Rounds up a value. + * + * @param value a value + * @return rounded up value + */ private Double roundValue(Double value) { return (Double) new BigDecimal(value).setScale(2, RoundingMode.HALF_UP).doubleValue(); }
[1/2] [text] Remove unused and empty Jaccard files and update distance method name
Repository: commons-text Updated Branches: refs/heads/master 3ccdabb1e - 376c7c4d8 Remove unused and empty Jaccard files and update distance method name Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/548a7918 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/548a7918 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/548a7918 Branch: refs/heads/master Commit: 548a7918ef57e2591c3d6aaa9bb3e42e17fa6cbe Parents: 3ccdabb Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Sun Apr 12 23:30:02 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Sun Apr 12 23:30:02 2015 +1200 -- .../commons/text/similarity/CosineDistance.java | 2 +- .../text/similarity/JaccardDistance.java| 21 .../commons/text/similarity/JaccardIndex.java | 21 .../text/similarity/CosineDistanceTest.java | 8 4 files changed, 5 insertions(+), 47 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/548a7918/src/main/java/org/apache/commons/text/similarity/CosineDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java index 69cfad7..f9fcf39 100644 --- a/src/main/java/org/apache/commons/text/similarity/CosineDistance.java +++ b/src/main/java/org/apache/commons/text/similarity/CosineDistance.java @@ -41,7 +41,7 @@ public class CosineDistance implements StringMetricDouble { private final CosineSimilarity cosineSimilarity = new CosineSimilarity(); @Override -public Double compare(CharSequence left, CharSequence right) { +public Double apply(CharSequence left, CharSequence right) { CharSequence[] leftTokens = tokenizer.tokenize(left); CharSequence[] rightTokens = tokenizer.tokenize(right); http://git-wip-us.apache.org/repos/asf/commons-text/blob/548a7918/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java b/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java deleted file mode 100644 index 7237244..000 --- a/src/main/java/org/apache/commons/text/similarity/JaccardDistance.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the License); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.text.similarity; - -public class JaccardDistance { - -} http://git-wip-us.apache.org/repos/asf/commons-text/blob/548a7918/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java -- diff --git a/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java b/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java deleted file mode 100644 index ceaa468..000 --- a/src/main/java/org/apache/commons/text/similarity/JaccardIndex.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the License); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.text.similarity; - -public class JaccardIndex { - -}
[text] Fix checkstyle errors
Repository: commons-text Updated Branches: refs/heads/master 376c7c4d8 - a5ac07106 Fix checkstyle errors Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/a5ac0710 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/a5ac0710 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/a5ac0710 Branch: refs/heads/master Commit: a5ac07106f25c0e359bb5782cf8eb16ce15aa0b8 Parents: 376c7c4 Author: Bruno P. Kinoshita brunodepau...@yahoo.com.br Authored: Mon Apr 13 00:17:25 2015 +1200 Committer: Bruno P. Kinoshita brunodepau...@yahoo.com.br Committed: Mon Apr 13 00:17:25 2015 +1200 -- .../commons/text/diff/CommandVisitor.java | 1 + .../apache/commons/text/diff/DeleteCommand.java | 1 + .../apache/commons/text/diff/EditCommand.java | 1 + .../apache/commons/text/diff/EditScript.java| 1 + .../apache/commons/text/diff/InsertCommand.java | 1 + .../apache/commons/text/diff/KeepCommand.java | 1 + .../commons/text/diff/ReplacementsFinder.java | 10 + .../commons/text/diff/ReplacementsHandler.java | 1 + .../commons/text/diff/StringsComparator.java| 32 +++--- .../commons/text/similarity/FuzzyScore.java | 8 .../text/similarity/JaroWrinklerDistance.java | 17 +--- .../text/similarity/LevenshteinDistance.java| 44 +--- 12 files changed, 85 insertions(+), 33 deletions(-) -- http://git-wip-us.apache.org/repos/asf/commons-text/blob/a5ac0710/src/main/java/org/apache/commons/text/diff/CommandVisitor.java -- diff --git a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java index d73dde8..7e5f40f 100644 --- a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java +++ b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java @@ -117,6 +117,7 @@ package org.apache.commons.text.diff; * } * /pre * + * @param T object type * @since 1.0 */ public interface CommandVisitorT { http://git-wip-us.apache.org/repos/asf/commons-text/blob/a5ac0710/src/main/java/org/apache/commons/text/diff/DeleteCommand.java -- diff --git a/src/main/java/org/apache/commons/text/diff/DeleteCommand.java b/src/main/java/org/apache/commons/text/diff/DeleteCommand.java index 7494002..8173718 100644 --- a/src/main/java/org/apache/commons/text/diff/DeleteCommand.java +++ b/src/main/java/org/apache/commons/text/diff/DeleteCommand.java @@ -29,6 +29,7 @@ package org.apache.commons.text.diff; * @see StringsComparator * @see EditScript * + * @param T object type * @since 1.0 */ public class DeleteCommandT extends EditCommandT { http://git-wip-us.apache.org/repos/asf/commons-text/blob/a5ac0710/src/main/java/org/apache/commons/text/diff/EditCommand.java -- diff --git a/src/main/java/org/apache/commons/text/diff/EditCommand.java b/src/main/java/org/apache/commons/text/diff/EditCommand.java index 972cebb..7920206 100644 --- a/src/main/java/org/apache/commons/text/diff/EditCommand.java +++ b/src/main/java/org/apache/commons/text/diff/EditCommand.java @@ -48,6 +48,7 @@ package org.apache.commons.text.diff; * @see StringsComparator * @see EditScript * + * @param T object type * @since 1.0 */ public abstract class EditCommandT { http://git-wip-us.apache.org/repos/asf/commons-text/blob/a5ac0710/src/main/java/org/apache/commons/text/diff/EditScript.java -- diff --git a/src/main/java/org/apache/commons/text/diff/EditScript.java b/src/main/java/org/apache/commons/text/diff/EditScript.java index 641d60b..8891044 100644 --- a/src/main/java/org/apache/commons/text/diff/EditScript.java +++ b/src/main/java/org/apache/commons/text/diff/EditScript.java @@ -40,6 +40,7 @@ import java.util.List; * @see CommandVisitor * @see ReplacementsHandler * + * @param T object type * @since 1.0 */ public class EditScriptT { http://git-wip-us.apache.org/repos/asf/commons-text/blob/a5ac0710/src/main/java/org/apache/commons/text/diff/InsertCommand.java -- diff --git a/src/main/java/org/apache/commons/text/diff/InsertCommand.java b/src/main/java/org/apache/commons/text/diff/InsertCommand.java index 9a365d0..f0337dc 100644 --- a/src/main/java/org/apache/commons/text/diff/InsertCommand.java +++ b/src/main/java/org/apache/commons/text/diff/InsertCommand.java @@ -29,6 +29,7 @@ package org.apache.commons.text.diff; * @see StringsComparator * @see EditScript * + * @param T object type * @since 1.0 */ public class
Git Push Summary
Repository: commons-text Updated Branches: refs/heads/NEW-METRICS [deleted] e99b839ad