MAHOUT-2033 Fixed Map-Reduce Refactor
Project: http://git-wip-us.apache.org/repos/asf/mahout/repo Commit: http://git-wip-us.apache.org/repos/asf/mahout/commit/49ad8cb4 Tree: http://git-wip-us.apache.org/repos/asf/mahout/tree/49ad8cb4 Diff: http://git-wip-us.apache.org/repos/asf/mahout/diff/49ad8cb4 Branch: refs/heads/branch-0.14.0 Commit: 49ad8cb457079301a87b02e71ba1273c62585bed Parents: 410ed16 Author: Trevor a.k.a @rawkintrevo <[email protected]> Authored: Fri Jun 29 11:10:13 2018 -0500 Committer: Trevor a.k.a @rawkintrevo <[email protected]> Committed: Fri Jun 29 11:10:13 2018 -0500 ---------------------------------------------------------------------- community/mahout-mr/integration/pom.xml | 143 +- community/mahout-mr/mr-examples/pom.xml | 30 +- community/mahout-mr/mr/pom.xml | 6 +- community/mahout-mr/pom.xml | 1 + core/pom.xml | 75 +- .../math/buffer/ValueTypeBufferConsumer.java.t | 42 + .../math/function/KeyTypeObjectProcedure.java.t | 50 + .../math/function/KeyTypeProcedure.java.t | 46 + .../function/KeyTypeValueTypeProcedure.java.t | 49 + .../function/ObjectValueTypeProcedure.java.t | 49 + .../math/function/ValueTypeComparator.java.t | 81 + .../math/list/AbstractValueTypeList.java.t | 851 +++++++ .../mahout/math/list/ValueTypeArrayList.java.t | 659 +++++ .../math/map/AbstractKeyTypeObjectMap.java.t | 467 ++++ .../math/map/AbstractKeyTypeValueTypeMap.java.t | 509 ++++ .../math/map/AbstractObjectValueTypeMap.java.t | 516 ++++ .../math/map/OpenKeyTypeObjectHashMap.java.t | 548 +++++ .../math/map/OpenKeyTypeValueTypeHashMap.java.t | 632 +++++ .../math/map/OpenObjectValueTypeHashMap.java.t | 567 +++++ .../mahout/math/set/AbstractKeyTypeSet.java.t | 181 ++ .../mahout/math/set/OpenKeyTypeHashSet.java.t | 423 ++++ .../org/apache/mahout/common/RandomUtils.java | 100 - .../org/apache/mahout/common/RandomWrapper.java | 105 - .../org/apache/mahout/math/AbstractMatrix.java | 834 ------- .../org/apache/mahout/math/AbstractVector.java | 684 ------ .../java/org/apache/mahout/math/Algebra.java | 73 - .../java/org/apache/mahout/math/Arrays.java | 662 ----- .../org/apache/mahout/math/BinarySearch.java | 403 --- .../mahout/math/CardinalityException.java | 30 - .../java/org/apache/mahout/math/Centroid.java | 89 - .../mahout/math/CholeskyDecomposition.java | 227 -- .../org/apache/mahout/math/ConstantVector.java | 177 -- .../apache/mahout/math/DelegatingVector.java | 336 --- .../org/apache/mahout/math/DenseMatrix.java | 193 -- .../mahout/math/DenseSymmetricMatrix.java | 62 - .../org/apache/mahout/math/DenseVector.java | 442 ---- .../org/apache/mahout/math/DiagonalMatrix.java | 378 --- .../org/apache/mahout/math/FileBasedMatrix.java | 185 -- .../math/FileBasedSparseBinaryMatrix.java | 535 ---- .../mahout/math/FunctionalMatrixView.java | 99 - .../org/apache/mahout/math/IndexException.java | 30 - .../apache/mahout/math/LengthCachingVector.java | 35 - .../java/org/apache/mahout/math/Matrices.java | 167 -- .../java/org/apache/mahout/math/Matrix.java | 413 ---- .../org/apache/mahout/math/MatrixSlice.java | 36 - .../org/apache/mahout/math/MatrixTimesOps.java | 35 - .../apache/mahout/math/MatrixVectorView.java | 292 --- .../java/org/apache/mahout/math/MatrixView.java | 160 -- .../java/org/apache/mahout/math/MurmurHash.java | 158 -- .../org/apache/mahout/math/MurmurHash3.java | 84 - .../org/apache/mahout/math/NamedVector.java | 328 --- .../apache/mahout/math/OldQRDecomposition.java | 234 -- .../mahout/math/OrderedIntDoubleMapping.java | 265 -- .../mahout/math/OrthonormalityVerifier.java | 46 - .../apache/mahout/math/PermutedVectorView.java | 250 -- .../apache/mahout/math/PersistentObject.java | 58 - .../org/apache/mahout/math/PivotedMatrix.java | 288 --- .../main/java/org/apache/mahout/math/QR.java | 27 - .../org/apache/mahout/math/QRDecomposition.java | 181 -- .../mahout/math/RandomAccessSparseVector.java | 303 --- .../apache/mahout/math/RandomTrinaryMatrix.java | 146 -- .../math/SequentialAccessSparseVector.java | 379 --- .../mahout/math/SingularValueDecomposition.java | 669 ----- .../java/org/apache/mahout/math/Sorting.java | 2299 ------------------ .../apache/mahout/math/SparseColumnMatrix.java | 220 -- .../org/apache/mahout/math/SparseMatrix.java | 246 -- .../org/apache/mahout/math/SparseRowMatrix.java | 289 --- .../java/org/apache/mahout/math/Swapper.java | 35 - .../mahout/math/TransposedMatrixView.java | 147 -- .../org/apache/mahout/math/UpperTriangular.java | 160 -- .../java/org/apache/mahout/math/Vector.java | 434 ---- .../mahout/math/VectorBinaryAggregate.java | 483 ---- .../apache/mahout/math/VectorBinaryAssign.java | 667 ----- .../org/apache/mahout/math/VectorIterable.java | 56 - .../java/org/apache/mahout/math/VectorView.java | 238 -- .../org/apache/mahout/math/WeightedVector.java | 87 - .../mahout/math/WeightedVectorComparator.java | 54 - .../org/apache/mahout/math/flavor/BackEnum.java | 26 - .../apache/mahout/math/flavor/MatrixFlavor.java | 82 - .../math/flavor/TraversingStructureEnum.java | 48 - .../math/function/DoubleDoubleFunction.java | 98 - .../mahout/math/function/DoubleFunction.java | 48 - .../mahout/math/function/FloatFunction.java | 36 - .../apache/mahout/math/function/Functions.java | 1730 ------------- .../mahout/math/function/IntFunction.java | 41 - .../math/function/IntIntDoubleFunction.java | 43 - .../mahout/math/function/IntIntFunction.java | 25 - .../org/apache/mahout/math/function/Mult.java | 71 - .../math/function/ObjectObjectProcedure.java | 40 - .../mahout/math/function/ObjectProcedure.java | 47 - .../apache/mahout/math/function/PlusMult.java | 123 - .../math/function/SquareRootFunction.java | 26 - .../mahout/math/function/TimesFunction.java | 77 - .../mahout/math/function/VectorFunction.java | 27 - .../mahout/math/function/package-info.java | 4 - .../apache/mahout/math/jet/math/Arithmetic.java | 328 --- .../apache/mahout/math/jet/math/Constants.java | 49 - .../apache/mahout/math/jet/math/Polynomial.java | 98 - .../mahout/math/jet/math/package-info.java | 5 - .../random/AbstractContinousDistribution.java | 51 - .../random/AbstractDiscreteDistribution.java | 27 - .../math/jet/random/AbstractDistribution.java | 87 - .../mahout/math/jet/random/Exponential.java | 81 - .../apache/mahout/math/jet/random/Gamma.java | 302 --- .../math/jet/random/NegativeBinomial.java | 106 - .../apache/mahout/math/jet/random/Normal.java | 110 - .../apache/mahout/math/jet/random/Poisson.java | 296 --- .../apache/mahout/math/jet/random/Uniform.java | 164 -- .../math/jet/random/engine/MersenneTwister.java | 275 --- .../math/jet/random/engine/RandomEngine.java | 169 -- .../math/jet/random/engine/package-info.java | 7 - .../math/jet/random/sampling/RandomSampler.java | 503 ---- .../org/apache/mahout/math/jet/stat/Gamma.java | 681 ------ .../mahout/math/jet/stat/Probability.java | 203 -- .../mahout/math/jet/stat/package-info.java | 5 - .../apache/mahout/math/list/AbstractList.java | 247 -- .../mahout/math/list/AbstractObjectList.java | 80 - .../mahout/math/list/ObjectArrayList.java | 419 ---- .../mahout/math/list/SimpleLongArrayList.java | 104 - .../apache/mahout/math/list/package-info.java | 144 -- .../apache/mahout/math/map/HashFunctions.java | 115 - .../org/apache/mahout/math/map/OpenHashMap.java | 654 ----- .../org/apache/mahout/math/map/PrimeFinder.java | 145 -- .../mahout/math/map/QuickOpenIntIntHashMap.java | 215 -- .../apache/mahout/math/map/package-info.java | 250 -- .../org/apache/mahout/math/package-info.java | 4 - .../org/apache/mahout/math/set/AbstractSet.java | 188 -- .../org/apache/mahout/math/set/HashUtils.java | 56 - .../org/apache/mahout/math/set/OpenHashSet.java | 548 ----- .../math/solver/ConjugateGradientSolver.java | 213 -- .../mahout/math/solver/EigenDecomposition.java | 892 ------- .../mahout/math/solver/JacobiConditioner.java | 47 - .../org/apache/mahout/math/solver/LSMR.java | 565 ----- .../mahout/math/solver/Preconditioner.java | 36 - .../apache/mahout/math/stats/LogLikelihood.java | 220 -- .../math/stats/OnlineExponentialAverage.java | 62 - .../mahout/math/stats/OnlineSummarizer.java | 93 - .../math/list/ValueTypeArrayListTest.java.t | 237 ++ .../map/OpenKeyTypeObjectHashMapTest.java.t | 431 ++++ .../map/OpenKeyTypeValueTypeHashMapTest.java.t | 379 +++ .../map/OpenObjectValueTypeHashMapTest.java.t | 423 ++++ .../math/set/OpenKeyTypeHashSetTest.java.t | 179 ++ .../apache/mahout/common/RandomUtilsTest.java | 1 - .../apache/mahout/math/AbstractVectorTest.java | 51 +- .../org/apache/mahout/math/CentroidTest.java | 144 +- .../mahout/math/CholeskyDecompositionTest.java | 304 +-- .../apache/mahout/math/DenseSymmetricTest.java | 38 +- .../apache/mahout/math/DiagonalMatrixTest.java | 1 - .../apache/mahout/math/FileBasedMatrixTest.java | 47 +- .../math/FileBasedSparseBinaryMatrixTest.java | 1 - .../org/apache/mahout/math/MahoutTestCase.java | 6 +- .../org/apache/mahout/math/MatricesTest.java | 1 - .../java/org/apache/mahout/math/MatrixTest.java | 2 - .../mahout/math/MatrixVectorViewTest.java | 1 - .../org/apache/mahout/math/MurmurHash3Test.java | 1 - .../org/apache/mahout/math/MurmurHashTest.java | 2 +- .../mahout/math/OldQRDecompositionTest.java | 374 +-- .../mahout/math/PermutedVectorViewTest.java | 2 - .../apache/mahout/math/PivotedMatrixTest.java | 1 - .../org/apache/mahout/math/TestDenseVector.java | 1 - .../org/apache/mahout/math/TestMatrixView.java | 1 - .../math/TestOrderedIntDoubleMapping.java | 1 - .../math/TestRandomAccessSparseVector.java | 1 - .../math/TestSequentialAccessSparseVector.java | 1 - .../apache/mahout/math/TestSparseMatrix.java | 1 - .../apache/mahout/math/TestSparseRowMatrix.java | 1 - .../org/apache/mahout/math/TestVectorView.java | 1 - .../apache/mahout/math/UpperTriangularTest.java | 1 - .../math/VectorBinaryAggregateCostTest.java | 660 ++--- .../mahout/math/VectorBinaryAssignCostTest.java | 488 ++-- .../java/org/apache/mahout/math/VectorTest.java | 1 - .../apache/mahout/math/WeightedVectorTest.java | 2 +- .../mahout/math/jet/random/ExponentialTest.java | 1 - .../mahout/math/jet/random/GammaTest.java | 1 - .../math/jet/random/NegativeBinomialTest.java | 1 - .../mahout/math/jet/random/NormalTest.java | 1 - .../jet/random/engine/MersenneTwisterTest.java | 1 - .../mahout/math/list/ObjectArrayListTest.java | 1 - .../mahout/math/random/EmpiricalTest.java | 156 +- .../mahout/math/random/IndianBuffetTest.java | 86 +- .../mahout/math/random/MultiNormalTest.java | 162 +- .../mahout/math/random/MultinomialTest.java | 538 ++-- .../apache/mahout/math/random/NormalTest.java | 124 +- .../mahout/math/random/PoissonSamplerTest.java | 112 +- .../org/apache/mahout/math/MatrixWritable.java | 5 +- 185 files changed, 9148 insertions(+), 28801 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/community/mahout-mr/integration/pom.xml ---------------------------------------------------------------------- diff --git a/community/mahout-mr/integration/pom.xml b/community/mahout-mr/integration/pom.xml index 8dbe599..b985d52 100644 --- a/community/mahout-mr/integration/pom.xml +++ b/community/mahout-mr/integration/pom.xml @@ -23,13 +23,13 @@ <parent> <groupId>org.apache.mahout</groupId> - <artifactId>mahout</artifactId> - <version>0.13.1-SNAPSHOT</version> - <relativePath>../mr/pom.xml</relativePath> + <artifactId>mahout-mr</artifactId> + <version>0.14.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> </parent> <artifactId>mahout-integration</artifactId> - <name>Mahout Integration</name> + <name>-- Mahout Classic Integration</name> <description>Optional components of Mahout which generally support interaction with third party systems, formats, APIs, etc.</description> @@ -41,7 +41,7 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> <configuration> - <appendedResourcesDirectory>../community/mahout-mr/src/appended-resources</appendedResourcesDirectory> + <appendedResourcesDirectory>../mr/src/appended-resources</appendedResourcesDirectory> <resourceBundles> <resourceBundle>org.apache:apache-jar-resource-bundle:1.4</resourceBundle> </resourceBundles> @@ -66,54 +66,82 @@ <dependencies> <!-- own modules --> + <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>mahout-hdfs</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>mahout-mr</artifactId> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>mahout-hdfs</artifactId> - <type>test-jar</type> - <scope>test</scope> + <groupId>org.apache.mahout</groupId> + <artifactId>core_2.11</artifactId> + <version>${project.version}</version> </dependency> + <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>mahout-mr</artifactId> - <type>test-jar</type> + <groupId>org.apache.mahout</groupId> + <artifactId>core_${scala.compat.version}</artifactId> + <version>${project.version}</version> + <classifier>tests</classifier> <scope>test</scope> </dependency> + + <!--<dependency>--> + <!--<groupId>${project.groupId}</groupId>--> + <!--<artifactId>mahout-hdfs</artifactId>--> + <!--<version>${project.version}</version>--> + <!--</dependency>--> + <dependency> <groupId>${project.groupId}</groupId> - <artifactId>mahout-math</artifactId> + <artifactId>mr</artifactId> + <version>${project.version}</version> </dependency> + + <!--<dependency>--> + <!--<groupId>${project.groupId}</groupId>--> + <!--<artifactId>mahout-hdfs</artifactId>--> + <!--<type>test-jar</type>--> + <!--<scope>test</scope>--> + <!--<version>${project.version}</version>--> + <!--</dependency>--> + <dependency> <groupId>${project.groupId}</groupId> - <artifactId>mahout-math</artifactId> + <artifactId>mr</artifactId> <type>test-jar</type> <scope>test</scope> + <version>${project.version}</version> </dependency> + <!--<dependency>--> + <!--<groupId>${project.groupId}</groupId>--> + <!--<artifactId>mahout-math</artifactId>--> + + <!--</dependency>--> + + <!--<dependency>--> + <!--<groupId>${project.groupId}</groupId>--> + <!--<artifactId>mahout-math</artifactId>--> + <!--<type>test-jar</type>--> + <!--<scope>test</scope>--> + <!--</dependency>--> + <!-- 3rd party --> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <optional>true</optional> + <version>1.4</version> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <optional>true</optional> + <version>1.6</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> + <version>2.4</version> </dependency> <dependency> @@ -121,22 +149,22 @@ <artifactId>guava</artifactId> </dependency> - <dependency> - <groupId>org.apache.solr</groupId> - <artifactId>solr-commons-csv</artifactId> - <version>3.5.0</version> - </dependency> + <!--<dependency>--> + <!--<groupId>org.apache.solr</groupId>--> + <!--<artifactId>solr-commons-csv</artifactId>--> + <!--<version>3.5.0</version>--> + <!--</dependency>--> - <dependency> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-benchmark</artifactId> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-analyzers-common</artifactId> - <optional>true</optional> - </dependency> + <!--<dependency>--> + <!--<groupId>org.apache.lucene</groupId>--> + <!--<artifactId>lucene-benchmark</artifactId>--> + <!--<optional>true</optional>--> + <!--</dependency>--> + <!--<dependency>--> + <!--<groupId>org.apache.lucene</groupId>--> + <!--<artifactId>lucene-analyzers-common</artifactId>--> + <!--<optional>true</optional>--> + <!--</dependency>--> <dependency> <groupId>org.mongodb</groupId> @@ -155,6 +183,7 @@ <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> + <version>1.0.0</version> </dependency> <dependency> @@ -164,16 +193,16 @@ <optional>true</optional> </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> + <!--<dependency>--> + <!--<groupId>org.slf4j</groupId>--> + <!--<artifactId>slf4j-api</artifactId>--> + <!--</dependency>--> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-jcl</artifactId> - <scope>test</scope> - </dependency> + <!--<dependency>--> + <!--<groupId>org.slf4j</groupId>--> + <!--<artifactId>slf4j-jcl</artifactId>--> + <!--<scope>test</scope>--> + <!--</dependency>--> <dependency> <groupId>junit</groupId> @@ -181,17 +210,19 @@ <scope>test</scope> </dependency> - <dependency> - <groupId>com.carrotsearch.randomizedtesting</groupId> - <artifactId>randomizedtesting-runner</artifactId> - <scope>test</scope> - </dependency> + <!--<dependency>--> + <!--<groupId>com.carrotsearch.randomizedtesting</groupId>--> + <!--<artifactId>randomizedtesting-runner</artifactId>--> + <!--<scope>test</scope>--> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> - </dependency> + <!--</dependency>--> + + <!--<dependency>--> + <!--<groupId>org.easymock</groupId>--> + <!--<artifactId>easymock</artifactId>--> + <!--<scope>test</scope>--> + <!--<version>3.2</version>--> + <!--</dependency>--> </dependencies> http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/community/mahout-mr/mr-examples/pom.xml ---------------------------------------------------------------------- diff --git a/community/mahout-mr/mr-examples/pom.xml b/community/mahout-mr/mr-examples/pom.xml index 7627f23..9737438 100644 --- a/community/mahout-mr/mr-examples/pom.xml +++ b/community/mahout-mr/mr-examples/pom.xml @@ -80,7 +80,7 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-remote-resources-plugin</artifactId> <configuration> - <appendedResourcesDirectory>../mr/src/main/appended-resources</appendedResourcesDirectory> + <appendedResourcesDirectory>../mr/src/appended-resources</appendedResourcesDirectory> <resourceBundles> <resourceBundle>org.apache:apache-jar-resource-bundle:1.4</resourceBundle> </resourceBundles> @@ -105,9 +105,31 @@ <dependencies> - - - + <dependency> + <groupId>org.apache.mahout</groupId> + <artifactId>mr</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>mr</artifactId> + <type>test-jar</type> + <scope>test</scope> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.mahout</groupId> + <artifactId>mahout-integration</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> </dependencies> <profiles> http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/community/mahout-mr/mr/pom.xml ---------------------------------------------------------------------- diff --git a/community/mahout-mr/mr/pom.xml b/community/mahout-mr/mr/pom.xml index 0f28588..65d74c8 100644 --- a/community/mahout-mr/mr/pom.xml +++ b/community/mahout-mr/mr/pom.xml @@ -67,7 +67,7 @@ <phase>package</phase> <configuration> <tasks> - <copy file="target/mahout-mr-${version}.jar" tofile="../../lib/mahout-mr-${version}.jar" /> + <copy file="target/mr-${version}.jar" tofile="../../../lib/mahout-mr-${version}.jar" /> </tasks> </configuration> <goals> @@ -84,7 +84,7 @@ <configuration> <filesets> <fileset> - <directory>../../lib/</directory> + <directory>../../../lib/</directory> <includes> <include>mahout-mr_*.jar</include> </includes> @@ -155,7 +155,7 @@ <configuration> <filesets> <fileset> - <directory>../../lib</directory> + <directory>../../../lib</directory> <includes> <include>mahout-mr*.jar</include> </includes> http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/community/mahout-mr/pom.xml ---------------------------------------------------------------------- diff --git a/community/mahout-mr/pom.xml b/community/mahout-mr/pom.xml index 5e8fc82..380aa15 100644 --- a/community/mahout-mr/pom.xml +++ b/community/mahout-mr/pom.xml @@ -36,6 +36,7 @@ <modules> <module>mr</module> + <module>integration</module> <module>mr-examples</module> </modules> http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index a91c31c..4910610 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -69,19 +69,13 @@ <version>7.0.12</version> </dependency> - <!-- TODO dump the "jet" random engine... --> - <!-- TODO dump org.apache.mahout.common/* --> - <!-- TODO dump org.apache.mahout.math.list.* --> - <!-- ToDO dump org.apachche.mahout.common.* --> - <!-- TODO lots of references commented out referencing OpenIntHashSet, change them to java.util.HashSet--> - <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-math3</artifactId> </dependency> <!-- TODO this is declared at top, fix this reimport --> - <!-- TODO fix all tests to stop using `com.carrotsearch.randomizedtesting.annotations` and `org.apache.lucene.util` --> + <!-- TODO fix all tests to stop using `com.carrotsearch.randomizedtesting.annotations` and `org.apache.lucene.util` and easymock --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -89,6 +83,7 @@ <scope>test</scope> </dependency> + <!-- Todo Factor this out--> <dependency> <groupId>com.carrotsearch.randomizedtesting</groupId> @@ -104,6 +99,12 @@ <scope>test</scope> </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + <version>3.2</version> + <scope>test</scope> + </dependency> <!-- TODO ONE Logging framework... --> <dependency> @@ -121,6 +122,66 @@ <build> <plugins> + + <!-- Build templates into code for various old-school Vector fns --> + <plugin> + <groupId>org.apache.mahout</groupId> + <artifactId>mahout-collection-codegen-plugin</artifactId> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>generate</goal> + </goals> + <configuration> + <!--<mainExcludes>--> + <!--<mainExclude>**/AbstractBooleanList.java</mainExclude>--> + <!--<mainExclude>**/BooleanArrayList.java</mainExclude>--> + <!--<mainExclude>**/BooleanBufferConsumer.java</mainExclude>--> + <!--</mainExcludes>--> + <!--<testExcludes>--> + <!--<testExclude>**/BooleanArrayListTest.java</testExclude>--> + <!--</testExcludes>--> + <outputDirectory>${project.build.directory}/generated-sources/mahout</outputDirectory> + <testOutputDirectory>${project.build.directory}/generated-test-sources/mahout</testOutputDirectory> + </configuration> + </execution> + </executions> + </plugin> + + <!-- add generated sources into build --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-sources/mahout</source> + </sources> + </configuration> + </execution> + <execution> + <id>add-test-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-test-sources/mahout</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <!-- End Generate Source --> + <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/buffer/ValueTypeBufferConsumer.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/buffer/ValueTypeBufferConsumer.java.t b/core/src/main/java-templates/org/apache/mahout/math/buffer/ValueTypeBufferConsumer.java.t new file mode 100644 index 0000000..3077dfd --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/buffer/ValueTypeBufferConsumer.java.t @@ -0,0 +1,42 @@ +/** + * 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. + */ +/* +Copyright 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ +package org.apache.mahout.math.buffer; + +import org.apache.mahout.math.list.${valueTypeCap}ArrayList; +/** + * Object that can accept a primitive array list of + * ${valueType} items. + **/ +public interface ${valueTypeCap}BufferConsumer { + + /** + * Adds all elements of the specified list to the receiver. + * + * @param list the list of which all elements shall be added. + */ + void addAllOf(${valueTypeCap}ArrayList list); +} http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeObjectProcedure.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeObjectProcedure.java.t b/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeObjectProcedure.java.t new file mode 100644 index 0000000..4ecf714 --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeObjectProcedure.java.t @@ -0,0 +1,50 @@ +/** + * 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.mahout.math.function; + +/* +Copyright 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ + +/** + * Interface that represents a procedure object: a procedure that takes two arguments and does not return a value. + * +*/ +public interface ${keyTypeCap}ObjectProcedure<T> { + + /** + * Applies a procedure to two arguments. Optionally can return a boolean flag to inform the object calling the + * procedure. + * + * <p>Example: forEach() methods often use procedure objects. To signal to a forEach() method whether iteration should + * continue normally or terminate (because for example a matching element has been found), a procedure can return + * <tt>false</tt> to indicate termination and <tt>true</tt> to indicate continuation. + * + * @param first first argument passed to the procedure. + * @param second second argument passed to the procedure. + * @return a flag to inform the object calling the procedure. + */ + boolean apply(${keyType} first, T second); +} http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeProcedure.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeProcedure.java.t b/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeProcedure.java.t new file mode 100644 index 0000000..c198353 --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeProcedure.java.t @@ -0,0 +1,46 @@ +/** + * 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.mahout.math.function; + +/* +Copyright 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ + +/** + * Interface that represents a procedure object: a procedure that takes a single argument and does not return a value. + * + */ +public interface ${keyTypeCap}Procedure { + + /** + * Applies a procedure to an argument. Optionally can return a boolean flag to inform the object calling the + * procedure. + * + * <p>Example: forEach() methods often use procedure objects. To signal to a forEach() method whether iteration should + * continue normally or terminate (because for example a matching element has been found), a procedure can return + * <tt>false</tt> to indicate termination and <tt>true</tt> to indicate continuation. + * + * @param element element passed to the procedure. + * @return a flag to inform the object calling the procedure. + */ + boolean apply(${keyType} element); +} http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeValueTypeProcedure.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeValueTypeProcedure.java.t b/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeValueTypeProcedure.java.t new file mode 100644 index 0000000..cf7ac22 --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/function/KeyTypeValueTypeProcedure.java.t @@ -0,0 +1,49 @@ +/** + * 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.mahout.math.function; + +/* +Copyright 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ + +/** + * Interface that represents a procedure object: a procedure that takes two arguments and does not return a value. + * + */ +public interface ${keyTypeCap}${valueTypeCap}Procedure { + + /** + * Applies a procedure to two arguments. Optionally can return a boolean flag to inform the object calling the + * procedure. + * + * <p>Example: forEach() methods often use procedure objects. To signal to a forEach() method whether iteration should + * continue normally or terminate (because for example a matching element has been found), a procedure can return + * <tt>false</tt> to indicate termination and <tt>true</tt> to indicate continuation. + * + * @param first first argument passed to the procedure. + * @param second second argument passed to the procedure. + * @return a flag to inform the object calling the procedure. + */ + boolean apply(${keyType} first, ${valueType} second); +} http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/function/ObjectValueTypeProcedure.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/function/ObjectValueTypeProcedure.java.t b/core/src/main/java-templates/org/apache/mahout/math/function/ObjectValueTypeProcedure.java.t new file mode 100644 index 0000000..e3576a8 --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/function/ObjectValueTypeProcedure.java.t @@ -0,0 +1,49 @@ +/** + * 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.mahout.math.function; + +/* +Copyright 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ + +/** + * Interface that represents a procedure object: a procedure that takes two arguments and does not return a value. + * + */ +public interface Object${valueTypeCap}Procedure<T> { + + /** + * Applies a procedure to two arguments. Optionally can return a boolean flag to inform the object calling the + * procedure. + * + * <p>Example: forEach() methods often use procedure objects. To signal to a forEach() method whether iteration should + * continue normally or terminate (because for example a matching element has been found), a procedure can return + * <tt>false</tt> to indicate termination and <tt>true</tt> to indicate continuation. + * + * @param first first argument passed to the procedure. + * @param second second argument passed to the procedure. + * @return a flag to inform the object calling the procedure. + */ + boolean apply(T first, ${valueType} second); +} http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/function/ValueTypeComparator.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/function/ValueTypeComparator.java.t b/core/src/main/java-templates/org/apache/mahout/math/function/ValueTypeComparator.java.t new file mode 100644 index 0000000..9f27905 --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/function/ValueTypeComparator.java.t @@ -0,0 +1,81 @@ +/** + * 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.mahout.math.function; + +/* +Copyright 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ + +/** + * A comparison function which imposes a <i>total ordering</i> on some collection of elements. Comparators can be + * passed to a sort method (such as <tt>org.apache.mahout.math.Sorting.quickSort</tt>) to allow precise control over + * the sort order.<p> + * + * Note: It is generally a good idea for comparators to implement <tt>java.io.Serializable</tt>, as they may be used as + * ordering methods in serializable data structures. In order for the data structure to serialize successfully, the + * comparator (if provided) must implement <tt>Serializable</tt>.<p> + * + * @see java.util.Comparator + * @see org.apache.mahout.math.Sorting + */ +public interface ${valueTypeCap}Comparator { + + /** + * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first + * argument is less than, equal to, or greater than the second.<p> + * + * The implementor must ensure that <tt>sgn(compare(x, y)) == -sgn(compare(y, x))</tt> for all <tt>x</tt> and + * <tt>y</tt>. (This implies that <tt>compare(x, y)</tt> must throw an exception if and only if <tt>compare(y, + * x)</tt> throws an exception.)<p> + * + * The implementor must also ensure that the relation is transitive: <tt>((compare(x, y)>0) && (compare(y, + * z)>0))</tt> implies <tt>compare(x, z)>0</tt>.<p> + * + * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> implies that <tt>sgn(compare(x, + * z))==sgn(compare(y, z))</tt> for all <tt>z</tt>.<p> + * + * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater + * than the second. + */ + int compare(${valueType} o1, ${valueType} o2); + + /** + * Indicates whether some other object is "equal to" this Comparator. This method must obey the general + * contract of <tt>Object.equals(Object)</tt>. Additionally, this method can return <tt>true</tt> <i>only</i> if the + * specified Object is also a comparator and it imposes the same ordering as this comparator. Thus, + * <code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2))</tt> for + * every element <tt>o1</tt> and <tt>o2</tt>.<p> + * + * Note that it is <i>always</i> safe <i>not</i> to override <tt>Object.equals(Object)</tt>. However, overriding this + * method may, in some cases, improve performance by allowing programs to determine that two distinct Comparators + * impose the same order. + * + * @param obj the reference object with which to compare. + * @return <code>true</code> only if the specified object is also a comparator and it imposes the same ordering as + * this comparator. + * @see Object#hashCode() + */ + boolean equals(Object obj); +} http://git-wip-us.apache.org/repos/asf/mahout/blob/49ad8cb4/core/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t ---------------------------------------------------------------------- diff --git a/core/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t b/core/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t new file mode 100644 index 0000000..343472a --- /dev/null +++ b/core/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t @@ -0,0 +1,851 @@ +/** + * 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. + */ + + /* +Copyright � 1999 CERN - European Organization for Nuclear Research. +Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose +is hereby granted without fee, provided that the above copyright notice appear in all copies and +that both that copyright notice and this permission notice appear in supporting documentation. +CERN makes no representations about the suitability of this software for any purpose. +It is provided "as is" without expressed or implied warranty. +*/ +package org.apache.mahout.math.list; +//CHECKSTYLE:OFF +import org.apache.mahout.math.Sorting; +import org.apache.mahout.math.buffer.${valueTypeCap}BufferConsumer; +import org.apache.mahout.math.function.${valueTypeCap}Comparator; +import org.apache.mahout.math.function.${valueTypeCap}Procedure; +//CHECKSTYLE:ON + +import java.util.ArrayList; +import java.util.List; + +/** + Abstract base class for resizable lists holding <code>${valueType}</code> elements; abstract. +*/ +public abstract class Abstract${valueTypeCap}List extends AbstractList implements ${valueTypeCap}BufferConsumer { + + /** + * The size of the list. This is a READ_ONLY variable for all methods but setSizeRaw(int newSize) !!! If you violate + * this principle in subclasses, you should exactly know what you are doing. + */ + protected int size; + + /** + * Appends the specified element to the end of this list. + * + * @param element element to be appended to this list. + */ + public void add(${valueType} element) { + beforeInsert(size, element); + } + + /** + * Appends all elements of the specified list to the receiver. + * + * @param other the list of which all elements shall be appended. + */ + public void addAllOf(Abstract${valueTypeCap}List other) { + addAllOfFromTo(other, 0, other.size() - 1); + } + + /** + * Appends the part of the specified list between <code>from</code> (inclusive) and <code>to</code> (inclusive) to the + * receiver. + * + * @param other the list to be added to the receiver. + * @param from the index of the first element to be appended (inclusive). + * @param to the index of the last element to be appended (inclusive). + * @throws IndexOutOfBoundsException index is out of range (<tt>other.size()>0 && (from<0 || from>to || + * to>=other.size())</tt>). + */ + public void addAllOfFromTo(Abstract${valueTypeCap}List other, int from, int to) { + beforeInsertAllOfFromTo(size, other, from, to); + } + + /** + * Appends the specified list to the end of this list. + * @param other the list to be appended. + **/ + @Override + public void addAllOf(${valueTypeCap}ArrayList other) { + addAllOfFromTo(other, 0, other.size() - 1); + } + + /** + * Inserts the specified element before the specified position into the receiver. Shifts the element currently at that + * position (if any) and any subsequent elements to the right. + * + * @param index index before which the specified element is to be inserted (must be in [0,size]). + * @param element element to be inserted. + * @throws IndexOutOfBoundsException index is out of range (<tt>index < 0 || index > size()</tt>). + */ + public void beforeInsert(int index, ${valueType} element) { + beforeInsertDummies(index, 1); + set(index, element); + } + + /** + * Inserts the part of the specified list between <code>otherFrom</code> (inclusive) and <code>otherTo</code> + * (inclusive) before the specified position into the receiver. Shifts the element currently at that position (if any) + * and any subsequent elements to the right. + * + * @param index index before which to insert first element from the specified list (must be in [0,size]).. + * @param other list of which a part is to be inserted into the receiver. + * @param from the index of the first element to be inserted (inclusive). + * @param to the index of the last element to be inserted (inclusive). + * @throws IndexOutOfBoundsException index is out of range (<tt>other.size()>0 && (from<0 || from>to || + * to>=other.size())</tt>). + * @throws IndexOutOfBoundsException index is out of range (<tt>index < 0 || index > size()</tt>). + */ + public void beforeInsertAllOfFromTo(int index, Abstract${valueTypeCap}List other, int from, int to) { + int length = to - from + 1; + this.beforeInsertDummies(index, length); + this.replaceFromToWithFrom(index, index + length - 1, other, from); + } + + /** + * Inserts <tt>length</tt> dummy elements before the specified position into the receiver. Shifts the element + * currently at that position (if any) and any subsequent elements to the right. <b>This method must set the new size + * to be <tt>size()+length</tt>. + * + * @param index index before which to insert dummy elements (must be in [0,size]).. + * @param length number of dummy elements to be inserted. + * @throws IndexOutOfBoundsException if <tt>index < 0 || index > size()</tt>. + */ + @Override + protected void beforeInsertDummies(int index, int length) { + if (index > size || index < 0) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); + } + if (length > 0) { + ensureCapacity(size + length); + setSizeRaw(size + length); + replaceFromToWithFrom(index + length, size - 1, this, index); + } + } + + /** + * Searches the receiver for the specified value using the binary search algorithm. The receiver must + * <strong>must</strong> be sorted (as by the sort method) prior to making this call. If it is not sorted, the + * results are undefined: in particular, the call may enter an infinite loop. If the receiver contains multiple + * elements equal to the specified object, there is no guarantee which instance will be found. + * + * @param key the value to be searched for. + * @return index of the search key, if it is contained in the receiver; otherwise, <tt>(-(<i>insertion point</i>) - + * 1)</tt>. The <i>insertion point</i> is defined as the the point at which the value would be inserted into + * the receiver: the index of the first element greater than the key, or <tt>receiver.size()</tt>, if all + * elements in the receiver are less than the specified key. Note that this guarantees that the return value + * will be >= 0 if and only if the key is found. + * @see java.util.Arrays + */ + public int binarySearch(${valueType} key) { + return this.binarySearchFromTo(key, 0, size - 1); + } + + /** + * Searches the receiver for the specified value using the binary search algorithm. The receiver must + * <strong>must</strong> be sorted (as by the sort method) prior to making this call. If it is not sorted, the + * results are undefined: in particular, the call may enter an infinite loop. If the receiver contains multiple + * elements equal to the specified object, there is no guarantee which instance will be found. + * + * @param key the value to be searched for. + * @param from the leftmost search position, inclusive. + * @param to the rightmost search position, inclusive. + * @return index of the search key, if it is contained in the receiver; otherwise, <tt>(-(<i>insertion point</i>) - + * 1)</tt>. The <i>insertion point</i> is defined as the the point at which the value would be inserted into + * the receiver: the index of the first element greater than the key, or <tt>receiver.size()</tt>, if all + * elements in the receiver are less than the specified key. Note that this guarantees that the return value + * will be >= 0 if and only if the key is found. + * @see java.util.Arrays + */ + public int binarySearchFromTo(${valueType} key, int from, int to) { + int low = from; + int high = to; + while (low <= high) { + int mid = (low + high) / 2; + ${valueType} midVal = get(mid); + + if (midVal < key) { + low = mid + 1; + } else if (midVal > key) { + high = mid - 1; + } else { + return mid; + } // key found + } + return -(low + 1); // key not found. + } + + /** + * Returns a deep copy of the receiver. + * + * @return a deep copy of the receiver. + */ + @Override + public Object clone() { + return partFromTo(0, size - 1); + } + + /** + * Returns true if the receiver contains the specified element. + * + * @param elem element whose presence in the receiver is to be tested. + */ + public boolean contains(${valueType} elem) { + return indexOfFromTo(elem, 0, size - 1) >= 0; + } + + /** + * Deletes the first element from the receiver that is identical to the specified element. Does nothing, if no such + * matching element is contained. + * + * @param element the element to be deleted. + */ + public void delete(${valueType} element) { + int index = indexOfFromTo(element, 0, size - 1); + if (index >= 0) { + remove(index); + } + } + + /** + * Returns the elements currently stored, possibly including invalid elements between size and capacity. + * + * <b>WARNING:</b> For efficiency reasons and to keep memory usage low, this method may decide <b>not to copy the + * array</b>. So if subsequently you modify the returned array directly via the [] operator, be sure you know what + * you're doing. + * + * @return the elements currently stored. + */ + public ${valueType}[] elements() { + ${valueType}[] myElements = new ${valueType}[size]; + for (int i = size; --i >= 0;) { + myElements[i] = getQuick(i); + } + return myElements; + } + + /** + * Sets the receiver's elements to be the specified array. The size and capacity of the list is the length of the + * array. <b>WARNING:</b> For efficiency reasons and to keep memory usage low, this method may decide <b>not to copy + * the array</b>. So if subsequently you modify the returned array directly via the [] operator, be sure you know what + * you're doing. + * + * @param elements the new elements to be stored. + * @return the receiver itself. + */ + public Abstract${valueTypeCap}List elements(${valueType}[] elements) { + clear(); + addAllOfFromTo(new ${valueTypeCap}ArrayList(elements), 0, elements.length - 1); + return this; + } + + /** + * Ensures that the receiver can hold at least the specified number of elements without needing to allocate new + * internal memory. If necessary, allocates new internal memory and increases the capacity of the receiver. + * + * @param minCapacity the desired minimum capacity. + */ + public abstract void ensureCapacity(int minCapacity); + + /** + * Compares the specified Object with the receiver. Returns true if and only if the specified Object is also an + * ArrayList of the same type, both Lists have the same size, and all corresponding pairs of elements in the two Lists + * are identical. In other words, two Lists are defined to be equal if they contain the same elements in the same + * order. + * + * @param otherObj the Object to be compared for equality with the receiver. + * @return true if the specified Object is equal to the receiver. + */ + public boolean equals(Object otherObj) { //delta + if (otherObj == null) { + return false; + } + if (!(otherObj instanceof Abstract${valueTypeCap}List)) { + return false; + } + if (this == otherObj) { + return true; + } + Abstract${valueTypeCap}List other = (Abstract${valueTypeCap}List) otherObj; + if (size() != other.size()) { + return false; + } + + for (int i = size(); --i >= 0;) { + if (getQuick(i) != other.getQuick(i)) { + return false; + } + } + return true; + } + + /** + * Sets the specified range of elements in the specified array to the specified value. + * + * @param from the index of the first element (inclusive) to be filled with the specified value. + * @param to the index of the last element (inclusive) to be filled with the specified value. + * @param val the value to be stored in the specified elements of the receiver. + */ + public void fillFromToWith(int from, int to, ${valueType} val) { + checkRangeFromTo(from, to, this.size); + for (int i = from; i <= to;) { + setQuick(i++, val); + } + } + + /** + * Applies a procedure to each element of the receiver, if any. Starts at index 0, moving rightwards. + * + * @param procedure the procedure to be applied. Stops iteration if the procedure returns <tt>false</tt>, otherwise + * continues. + * @return <tt>false</tt> if the procedure stopped before all elements where iterated over, <tt>true</tt> otherwise. + */ + public boolean forEach(${valueTypeCap}Procedure procedure) { + for (int i = 0; i < size;) { + if (!procedure.apply(get(i++))) { + return false; + } + } + return true; + } + + /** + * Returns the element at the specified position in the receiver. + * + * @param index index of element to return. + * @throws IndexOutOfBoundsException index is out of range (index < 0 || index >= size()). + */ + public ${valueType} get(int index) { + if (index >= size || index < 0) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); + } + return getQuick(index); + } + + /** + * Returns the element at the specified position in the receiver; <b>WARNING:</b> Does not check preconditions. + * Provided with invalid parameters this method may return invalid elements without throwing any exception! <b>You + * should only use this method when you are absolutely sure that the index is within bounds.</b> Precondition + * (unchecked): <tt>index >= 0 && index < size()</tt>. + * + * This method is normally only used internally in large loops where bounds are explicitly checked before the loop and + * need no be rechecked within the loop. However, when desperately, you can give this method <tt>public</tt> + * visibility in subclasses. + * + * @param index index of element to return. + */ + protected abstract ${valueType} getQuick(int index); + + /** + * Returns the index of the first occurrence of the specified element. Returns <code>-1</code> if the receiver does + * not contain this element. + * + * @param element the element to be searched for. + * @return the index of the first occurrence of the element in the receiver; returns <code>-1</code> if the element is + * not found. + */ + public int indexOf(${valueType} element) { //delta + return indexOfFromTo(element, 0, size - 1); + } + + /** + * Returns the index of the first occurrence of the specified element. Returns <code>-1</code> if the receiver does + * not contain this element. Searches between <code>from</code>, inclusive and <code>to</code>, inclusive. Tests for + * identity. + * + * @param element element to search for. + * @param from the leftmost search position, inclusive. + * @param to the rightmost search position, inclusive. + * @return the index of the first occurrence of the element in the receiver; returns <code>-1</code> if the element is + * not found. + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + public int indexOfFromTo(${valueType} element, int from, int to) { + checkRangeFromTo(from, to, size); + + for (int i = from; i <= to; i++) { + if (element == getQuick(i)) { + return i; + } //found + } + return -1; //not found + } + + /** + * Returns the index of the last occurrence of the specified element. Returns <code>-1</code> if the receiver does not + * contain this element. + * + * @param element the element to be searched for. + * @return the index of the last occurrence of the element in the receiver; returns <code>-1</code> if the element is + * not found. + */ + public int lastIndexOf(${valueType} element) { + return lastIndexOfFromTo(element, 0, size - 1); + } + + /** + * Returns the index of the last occurrence of the specified element. Returns <code>-1</code> if the receiver does not + * contain this element. Searches beginning at <code>to</code>, inclusive until <code>from</code>, inclusive. Tests + * for identity. + * + * @param element element to search for. + * @param from the leftmost search position, inclusive. + * @param to the rightmost search position, inclusive. + * @return the index of the last occurrence of the element in the receiver; returns <code>-1</code> if the element is + * not found. + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + public int lastIndexOfFromTo(${valueType} element, int from, int to) { + checkRangeFromTo(from, to, size()); + + for (int i = to; i >= from; i--) { + if (element == getQuick(i)) { + return i; + } //found + } + return -1; //not found + } + + /** + * Sorts the specified range of the receiver into ascending order. + * + * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low + * sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) + * performance, and can approach linear performance on nearly sorted lists. + * + * <p><b>You should never call this method unless you are sure that this particular sorting algorithm is the right one + * for your data set.</b> It is generally better to call <tt>sort()</tt> or <tt>sortFromTo(...)</tt> instead, because + * those methods automatically choose the best sorting algorithm. + * + * @param from the index of the first element (inclusive) to be sorted. + * @param to the index of the last element (inclusive) to be sorted. + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + @Override + public void mergeSortFromTo(int from, int to) { + int mySize = size(); + checkRangeFromTo(from, to, mySize); + + ${valueType}[] myElements = elements(); + Sorting.mergeSort(myElements, from, to + 1); + elements(myElements); + setSizeRaw(mySize); + } + + /** + * Sorts the receiver according to the order induced by the specified comparator. All elements in the range must be + * <i>mutually comparable</i> by the specified comparator (that is, <tt>c.compare(e1, e2)</tt> must not throw a + * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in the range).<p> + * + * This sort is guaranteed to be <i>stable</i>: equal elements will not be reordered as a result of the sort.<p> + * + * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low + * sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) + * performance, and can approach linear performance on nearly sorted lists. + * + * @param from the index of the first element (inclusive) to be sorted. + * @param to the index of the last element (inclusive) to be sorted. + * @param c the comparator to determine the order of the receiver. + * @throws ClassCastException if the array contains elements that are not <i>mutually comparable</i> using + * the specified comparator. + * @throws IllegalArgumentException if <tt>fromIndex > toIndex</tt> + * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or <tt>toIndex > a.length</tt> + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + public void mergeSortFromTo(int from, int to, ${valueTypeCap}Comparator c) { + int mySize = size(); + checkRangeFromTo(from, to, mySize); + + ${valueType}[] myElements = elements(); + Sorting.mergeSort(myElements, from, to + 1, c); + elements(myElements); + setSizeRaw(mySize); + } + + /** + * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>to</code>, + * inclusive. + * + * @param from the index of the first element (inclusive). + * @param to the index of the last element (inclusive). + * @return a new list + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + public Abstract${valueTypeCap}List partFromTo(int from, int to) { + checkRangeFromTo(from, to, size); + + int length = to - from + 1; + ${valueTypeCap}ArrayList part = new ${valueTypeCap}ArrayList(length); + part.addAllOfFromTo(this, from, to); + return part; + } + + /** + * Sorts the specified range of the receiver into ascending numerical order. The sorting algorithm is a tuned + * quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice + * and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data + * sets that cause other quicksorts to degrade to quadratic performance. + * + * <p><b>You should never call this method unless you are sure that this particular sorting algorithm is the right one + * for your data set.</b> It is generally better to call <tt>sort()</tt> or <tt>sortFromTo(...)</tt> instead, because + * those methods automatically choose the best sorting algorithm. + * + * @param from the index of the first element (inclusive) to be sorted. + * @param to the index of the last element (inclusive) to be sorted. + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + @Override + public void quickSortFromTo(int from, int to) { + int mySize = size(); + checkRangeFromTo(from, to, mySize); + + ${valueType}[] myElements = elements(); + java.util.Arrays.sort(myElements, from, to + 1); + elements(myElements); + setSizeRaw(mySize); + } + + /** + * Sorts the receiver according to the order induced by the specified comparator. All elements in the range must be + * <i>mutually comparable</i> by the specified comparator (that is, <tt>c.compare(e1, e2)</tt> must not throw a + * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in the range).<p> + * + * The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a + * Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers + * n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance. + * + * @param from the index of the first element (inclusive) to be sorted. + * @param to the index of the last element (inclusive) to be sorted. + * @param c the comparator to determine the order of the receiver. + * @throws ClassCastException if the array contains elements that are not <i>mutually comparable</i> using + * the specified comparator. + * @throws IllegalArgumentException if <tt>fromIndex > toIndex</tt> + * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or <tt>toIndex > a.length</tt> + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + public void quickSortFromTo(int from, int to, ${valueTypeCap}Comparator c) { + int mySize = size(); + checkRangeFromTo(from, to, mySize); + + ${valueType}[] myElements = elements(); + Sorting.quickSort(myElements, from, to + 1, c); + elements(myElements); + setSizeRaw(mySize); + } + + /** + * Removes from the receiver all elements that are contained in the specified list. Tests for identity. + * + * @param other the other list. + * @return <code>true</code> if the receiver changed as a result of the call. + */ + public boolean removeAll(Abstract${valueTypeCap}List other) { + if (other.isEmpty()) { + return false; + } //nothing to do + int limit = other.size() - 1; + int j = 0; + + for (int i = 0; i < size; i++) { + if (other.indexOfFromTo(getQuick(i), 0, limit) < 0) { + setQuick(j++, getQuick(i)); + } + } + + boolean modified = (j != size); + setSize(j); + return modified; + } + + /** + * Removes from the receiver all elements whose index is between <code>from</code>, inclusive and <code>to</code>, + * inclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by + * <tt>(to - from + 1)</tt> elements. + * + * @param from index of first element to be removed. + * @param to index of last element to be removed. + * @throws IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || from>to || + * to>=size())</tt>). + */ + @Override + public void removeFromTo(int from, int to) { + checkRangeFromTo(from, to, size); + int numMoved = size - to - 1; + if (numMoved > 0) { + replaceFromToWithFrom(from, from - 1 + numMoved, this, to + 1); + //fillFromToWith(from+numMoved, size-1, 0.0f); //delta + } + int width = to - from + 1; + if (width > 0) { + setSizeRaw(size - width); + } + } + + /** + * Replaces a number of elements in the receiver with the same number of elements of another list. Replaces elements + * in the receiver, between <code>from</code> (inclusive) and <code>to</code> (inclusive), with elements of + * <code>other</code>, starting from <code>otherFrom</code> (inclusive). + * + * @param from the position of the first element to be replaced in the receiver + * @param to the position of the last element to be replaced in the receiver + * @param other list holding elements to be copied into the receiver. + * @param otherFrom position of first element within other list to be copied. + */ + public void replaceFromToWithFrom(int from, int to, Abstract${valueTypeCap}List other, int otherFrom) { + int length = to - from + 1; + if (length > 0) { + checkRangeFromTo(from, to, size()); + checkRangeFromTo(otherFrom, otherFrom + length - 1, other.size()); + + // unambiguous copy (it may hold other==this) + if (from <= otherFrom) { + while (--length >= 0) { + setQuick(from++, other.getQuick(otherFrom++)); + } + } else { + int otherTo = otherFrom + length - 1; + while (--length >= 0) { + setQuick(to--, other.getQuick(otherTo--)); + } + } + } + } + + /** + * Replaces the part between <code>from</code> (inclusive) and <code>to</code> (inclusive) with the other list's part + * between <code>otherFrom</code> and <code>otherTo</code>. Powerful (and tricky) method! Both parts need not be of + * the same size (part A can both be smaller or larger than part B). Parts may overlap. Receiver and other list may + * (but most not) be identical. If <code>from > to</code>, then inserts other part before <code>from</code>. + * + * @param from the first element of the receiver (inclusive) + * @param to the last element of the receiver (inclusive) + * @param other the other list (may be identical with receiver) + * @param otherFrom the first element of the other list (inclusive) + * @param otherTo the last element of the other list (inclusive) + * + * <p><b>Examples:</b><pre> + * a=[0, 1, 2, 3, 4, 5, 6, 7] + * b=[50, 60, 70, 80, 90] + * a.R(...)=a.replaceFromToWithFromTo(...) + * + * a.R(3,5,b,0,4)-->[0, 1, 2, 50, 60, 70, 80, 90, + * 6, 7] + * a.R(1,6,b,0,4)-->[0, 50, 60, 70, 80, 90, 7] + * a.R(0,6,b,0,4)-->[50, 60, 70, 80, 90, 7] + * a.R(3,5,b,1,2)-->[0, 1, 2, 60, 70, 6, 7] + * a.R(1,6,b,1,2)-->[0, 60, 70, 7] + * a.R(0,6,b,1,2)-->[60, 70, 7] + * a.R(5,3,b,0,4)-->[0, 1, 2, 3, 4, 50, 60, 70, + * 80, 90, 5, 6, 7] + * a.R(5,0,b,0,4)-->[0, 1, 2, 3, 4, 50, 60, 70, + * 80, 90, 5, 6, 7] + * a.R(5,3,b,1,2)-->[0, 1, 2, 3, 4, 60, 70, 5, 6, + * 7] + * a.R(5,0,b,1,2)-->[0, 1, 2, 3, 4, 60, 70, 5, 6, + * 7] + * + * Extreme cases: + * a.R(5,3,b,0,0)-->[0, 1, 2, 3, 4, 50, 5, 6, 7] + * a.R(5,3,b,4,4)-->[0, 1, 2, 3, 4, 90, 5, 6, 7] + * a.R(3,5,a,0,1)-->[0, 1, 2, 0, 1, 6, 7] + * a.R(3,5,a,3,5)-->[0, 1, 2, 3, 4, 5, 6, 7] + * a.R(3,5,a,4,4)-->[0, 1, 2, 4, 6, 7] + * a.R(5,3,a,0,4)-->[0, 1, 2, 3, 4, 0, 1, 2, 3, 4, + * 5, 6, 7] + * a.R(0,-1,b,0,4)-->[50, 60, 70, 80, 90, 0, 1, 2, + * 3, 4, 5, 6, 7] + * a.R(0,-1,a,0,4)-->[0, 1, 2, 3, 4, 0, 1, 2, 3, + * 4, 5, 6, 7] + * a.R(8,0,a,0,4)-->[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, + * 2, 3, 4] + * </pre> + */ + public void replaceFromToWithFromTo(int from, int to, Abstract${valueTypeCap}List other, int otherFrom, int otherTo) { + if (otherFrom > otherTo) { + throw new IndexOutOfBoundsException("otherFrom: " + otherFrom + ", otherTo: " + otherTo); + } + + if (this == other && to - from != otherTo - otherFrom) { // avoid stumbling over my own feet + replaceFromToWithFromTo(from, to, partFromTo(otherFrom, otherTo), 0, otherTo - otherFrom); + return; + } + + int length = otherTo - otherFrom + 1; + int diff = length; + int theLast = from - 1; + + if (to >= from) { + diff -= (to - from + 1); + theLast = to; + } + + if (diff > 0) { + beforeInsertDummies(theLast + 1, diff); + } else { + if (diff < 0) { + removeFromTo(theLast + diff, theLast - 1); + } + } + + if (length > 0) { + replaceFromToWithFrom(from, from + length - 1, other, otherFrom); + } + } + + /** + * Retains (keeps) only the elements in the receiver that are contained in the specified other list. In other words, + * removes from the receiver all of its elements that are not contained in the specified other list. + * + * @param other the other list to test against. + * @return <code>true</code> if the receiver changed as a result of the call. + */ + public boolean retainAll(Abstract${valueTypeCap}List other) { + if (other.isEmpty()) { + if (size == 0) { + return false; + } + setSize(0); + return true; + } + + int limit = other.size() - 1; + int j = 0; + for (int i = 0; i < size; i++) { + if (other.indexOfFromTo(getQuick(i), 0, limit) >= 0) { + setQuick(j++, getQuick(i)); + } + } + + boolean modified = (j != size); + setSize(j); + return modified; + } + + /** Reverses the elements of the receiver. Last becomes first, second last becomes second first, and so on. */ + @Override + public void reverse() { + int limit = size() / 2; + int j = size() - 1; + + for (int i = 0; i < limit;) { //swap + ${valueType} tmp = getQuick(i); + setQuick(i++, getQuick(j)); + setQuick(j--, tmp); + } + } + + /** + * Replaces the element at the specified position in the receiver with the specified element. + * + * @param index index of element to replace. + * @param element element to be stored at the specified position. + * @throws IndexOutOfBoundsException if <tt>index < 0 || index >= size()</tt>. + */ + public void set(int index, ${valueType} element) { + if (index >= size || index < 0) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); + } + setQuick(index, element); + } + + /** + * Replaces the element at the specified position in the receiver with the specified element; <b>WARNING:</b> Does not + * check preconditions. Provided with invalid parameters this method may access invalid indexes without throwing any + * exception! <b>You should only use this method when you are absolutely sure that the index is within bounds.</b> + * Precondition (unchecked): <tt>index >= 0 && index < size()</tt>. + * + * This method is normally only used internally in large loops where bounds are explicitly checked before the loop and + * need no be rechecked within the loop. However, when desperately, you can give this method <tt>public</tt> + * visibility in subclasses. + * + * @param index index of element to replace. + * @param element element to be stored at the specified position. + */ + protected abstract void setQuick(int index, ${valueType} element); + + /** + * Sets the size of the receiver without modifying it otherwise. This method should not release or allocate new memory + * but simply set some instance variable like <tt>size</tt>. + * + * If your subclass overrides and delegates size changing methods to some other object, you must make sure that those + * overriding methods not only update the size of the delegate but also of this class. For example: public + * DatabaseList extends Abstract${valueTypeCap}List { ... public void removeFromTo(int from,int to) { + * myDatabase.removeFromTo(from,to); this.setSizeRaw(size-(to-from+1)); } } + */ + protected void setSizeRaw(int newSize) { + size = newSize; + } + + /** Returns the number of elements contained in the receiver. */ + @Override + public int size() { + return size; + } + + /** + * Returns a list which is a concatenation of <code>times</code> times the receiver. + * + * @param times the number of times the receiver shall be copied. + */ + public Abstract${valueTypeCap}List times(int times) { + Abstract${valueTypeCap}List newList = new ${valueTypeCap}ArrayList(times * size()); + for (int i = times; --i >= 0;) { + newList.addAllOfFromTo(this, 0, size() - 1); + } + return newList; + } + + /** Returns a <code>ArrayList</code> containing all the elements in the receiver. */ + public List<${valueObjectType}> toList() { + int mySize = size(); + List<${valueObjectType}> list = new ArrayList<${valueObjectType}>(mySize); + for (int i = 0; i < mySize; i++) { + list.add(get(i)); + } + return list; + } + + public ${valueType}[] toArray(${valueType}[] values) { + int mySize = size(); + ${valueType}[] myElements; + if (values.length >= mySize) { + myElements = values; + } else { + myElements = new ${valueType}[mySize]; + } + for (int i = size; --i >= 0;) { + myElements[i] = getQuick(i); + } + return myElements; + } + + /** Returns a string representation of the receiver, containing the String representation of each element. */ + public String toString() { + return org.apache.mahout.math.Arrays.toString(partFromTo(0, size() - 1).elements()); + } +}
