ArrayFieldVector implements FieldVector<T>, Serializable { public T walkInOptimizedOrder(final FieldVectorPreservingVisitor<T> visitor) { return walkInDefaultOrder(visitor); } ArrayFieldVector(final Field<T> field);  ArrayFieldVector(Field<T> field, int size);  ArrayFieldVector(int size, T preset);  ArrayFieldVector(T[] d);  ArrayFieldVector(Field<T> field, T[] d);  ArrayFieldVector(T[] d, boolean copyArray);  ArrayFieldVector(Field<T> field, T[] d, boolean copyArray);  ArrayFieldVector(T[] d, int pos, int size);  ArrayFieldVector(Field<T> field, T[] d, int pos, int size);  ArrayFieldVector(FieldVector<T> v);  ArrayFieldVector(ArrayFieldVector<T> v);  ArrayFieldVector(ArrayFieldVector<T> v, boolean deep); @Deprecated  ArrayFieldVector(ArrayFieldVector<T> v1, ArrayFieldVector<T> v2);  ArrayFieldVector(FieldVector<T> v1, FieldVector<T> v2); @Deprecated  ArrayFieldVector(ArrayFieldVector<T> v1, T[] v2);  ArrayFieldVector(FieldVector<T> v1, T[] v2); @Deprecated  ArrayFieldVector(T[] v1, ArrayFieldVector<T> v2);  ArrayFieldVector(T[] v1, FieldVector<T> v2);  ArrayFieldVector(T[] v1, T[] v2);  ArrayFieldVector(Field<T> field, T[] v1, T[] v2); Field<T> getField(); FieldVector<T> copy(); FieldVector<T> add(FieldVector<T> v); ArrayFieldVector<T> add(ArrayFieldVector<T> v); FieldVector<T> subtract(FieldVector<T> v); ArrayFieldVector<T> subtract(ArrayFieldVector<T> v); FieldVector<T> mapAdd(T d); FieldVector<T> mapAddToSelf(T d); FieldVector<T> mapSubtract(T d); FieldVector<T> mapSubtractToSelf(T d); FieldVector<T> mapMultiply(T d); FieldVector<T> mapMultiplyToSelf(T d); FieldVector<T> mapDivide(T d); FieldVector<T> mapDivideToSelf(T d); FieldVector<T> mapInv(); FieldVector<T> mapInvToSelf(); FieldVector<T> ebeMultiply(FieldVector<T> v); ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v); FieldVector<T> ebeDivide(FieldVector<T> v); ArrayFieldVector<T> ebeDivide(ArrayFieldVector<T> v); T[] getData(); T[] getDataRef(); T dotProduct(FieldVector<T> v); T dotProduct(ArrayFieldVector<T> v); FieldVector<T> projection(FieldVector<T> v); ArrayFieldVector<T> projection(ArrayFieldVector<T> v); FieldMatrix<T> outerProduct(FieldVector<T> v); FieldMatrix<T> outerProduct(ArrayFieldVector<T> v); T getEntry(int index); int getDimension(); FieldVector<T> append(FieldVector<T> v); ArrayFieldVector<T> append(ArrayFieldVector<T> v); FieldVector<T> append(T in); FieldVector<T> getSubVector(int index, int n); void setEntry(int index, T value); void setSubVector(int index, FieldVector<T> v); void set(int index, ArrayFieldVector<T> v); void set(T value); T[] toArray(); T walkInDefaultOrder(final FieldVectorPreservingVisitor<T> visitor); T walkInDefaultOrder(final FieldVectorPreservingVisitor<T> visitor,
                                final int start, final int end); T walkInOptimizedOrder(final FieldVectorPreservingVisitor<T> visitor); T walkInOptimizedOrder(final FieldVectorPreservingVisitor<T> visitor,
                                  final int start, final int end); T walkInDefaultOrder(final FieldVectorChangingVisitor<T> visitor); T walkInDefaultOrder(final FieldVectorChangingVisitor<T> visitor,
                                final int start, final int end); T walkInOptimizedOrder(final FieldVectorChangingVisitor<T> visitor); T walkInOptimizedOrder(final FieldVectorChangingVisitor<T> visitor,
                                  final int start, final int end); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testWalkInOptimizedOrderPreservingVisitor1() { final Fraction[] data = new Fraction[] { Fraction.ZERO, Fraction.ONE, Fraction.ZERO, Fraction.ZERO, Fraction.TWO, Fraction.ZERO, Fraction.ZERO, Fraction.ZERO, new Fraction(3) }; final ArrayFieldVector<Fraction> v = new ArrayFieldVector<Fraction>(data); final FieldVectorPreservingVisitor<Fraction> visitor; visitor = new FieldVectorPreservingVisitor<Fraction>() { private final boolean[] visited = new boolean[data.length]; public void visit(final int actualIndex, final Fraction actualValue) { visited[actualIndex] = true; Assert.assertEquals(Integer.toString(actualIndex), data[actualIndex], actualValue); } public void start(final int actualSize, final int actualStart, final int actualEnd) { Assert.assertEquals(data.length, actualSize); Assert.assertEquals(0, actualStart); Assert.assertEquals(data.length - 1, actualEnd); Arrays.fill(visited, false); } public Fraction end() { for (int i = 0; i < data.length; i++) { Assert.assertTrue("entry " + i + "has not been visited", visited[i]); } return Fraction.ZERO; } }; v.walkInOptimizedOrder(visitor); }
@Test public void testWalkInOptimizedOrderPreservingVisitor2() { final ArrayFieldVector<Fraction> v = create(5); final FieldVectorPreservingVisitor<Fraction> visitor; visitor = new FieldVectorPreservingVisitor<Fraction>() { public void visit(int index, Fraction value) { } public void start(int dimension, int start, int end) { } public Fraction end() { return Fraction.ZERO; } }; try { v.walkInOptimizedOrder(visitor, -1, 4); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 5, 4); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 0, -1); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 0, 5); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 4, 0); Assert.fail(); } catch (NumberIsTooSmallException e) { } }
@Test public void testWalkInOptimizedOrderPreservingVisitor3() { final Fraction[] data = new Fraction[] { Fraction.ZERO, Fraction.ONE, Fraction.ZERO, Fraction.ZERO, Fraction.TWO, Fraction.ZERO, Fraction.ZERO, Fraction.ZERO, new Fraction(3) }; final ArrayFieldVector<Fraction> v = new ArrayFieldVector<Fraction>(data); final int expectedStart = 2; final int expectedEnd = 7; final FieldVectorPreservingVisitor<Fraction> visitor; visitor = new FieldVectorPreservingVisitor<Fraction>() { private final boolean[] visited = new boolean[data.length]; public void visit(final int actualIndex, final Fraction actualValue) { Assert.assertEquals(Integer.toString(actualIndex), data[actualIndex], actualValue); visited[actualIndex] = true; } public void start(final int actualSize, final int actualStart, final int actualEnd) { Assert.assertEquals(data.length, actualSize); Assert.assertEquals(expectedStart, actualStart); Assert.assertEquals(expectedEnd, actualEnd); Arrays.fill(visited, true); } public Fraction end() { for (int i = expectedStart; i <= expectedEnd; i++) { Assert.assertTrue("entry " + i + "has not been visited", visited[i]); } return Fraction.ZERO; } }; v.walkInOptimizedOrder(visitor, expectedStart, expectedEnd); }
@Test public void testWalkInOptimizedOrderChangingVisitor2() { final ArrayFieldVector<Fraction> v = create(5); final FieldVectorChangingVisitor<Fraction> visitor; visitor = new FieldVectorChangingVisitor<Fraction>() { public Fraction visit(int index, Fraction value) { return Fraction.ZERO; } public void start(int dimension, int start, int end) { } public Fraction end() { return Fraction.ZERO; } }; try { v.walkInOptimizedOrder(visitor, -1, 4); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 5, 4); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 0, -1); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 0, 5); Assert.fail(); } catch (OutOfRangeException e) { } try { v.walkInOptimizedOrder(visitor, 4, 0); Assert.fail(); } catch (NumberIsTooSmallException e) { } }