diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDArray.java index 2a59d190f4d26a62fdd872fd78df11f4f1dfc7c3..0844e41cb57fcd9aa13dd3a933915f37aa9a25e4 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDArray.java @@ -19,7 +19,7 @@ package ch.systemsx.cisd.base.mdarray; import java.util.Arrays; /** - * A multi-dimensional array of type <code>T</code>. + * A multi-dimensional array of generic type <code>T</code>. * * @author Bernd Rinn */ @@ -27,32 +27,60 @@ public class MDArray<T> extends MDAbstractArray<T> { private final T[] flattenedArray; - + + /** + * Creates an empty {@link MDArray} with the given <var>componentClass</var> and + * <var>dimensions</var>. Convenience method if <var>dimensions</var> are available as {@code + * long[]}. + */ public MDArray(Class<T> componentClass, long[] dimensions) { this(createArray(componentClass, getLength(dimensions)), toInt(dimensions), false); } + /** + * Creates a {@link MDArray} from the given {@code flattenedArray} and {@code dimensions}. It is + * checked that the arguments are compatible. Convenience method if <var>dimensions</var> are + * available as {@code long[]}. + */ public MDArray(T[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDArray} from the given <var>flattenedArray</var> and <var>dimensions</var>. + * If <var>checkDimensions/var>} is {@code true}, it is checked that the arguments are + * compatible. Convenience method if <var>dimensions</var> are available as {@code long[]}. + */ public MDArray(T[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDArray} with the given <var>componentClass</var> and + * <var>dimensions</var>. + */ public MDArray(Class<T> componentClass, int[] dimensions) { this(createArray(componentClass, getLength(dimensions)), dimensions, false); } + /** + * Creates a {@link MDArray} from the given {@code flattenedArray} and {@code dimensions}. It is + * checked that the arguments are compatible. + */ public MDArray(T[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDArray} from the given <var>flattenedArray</var> and <var>dimensions</var>. + * If <var>checkDimensions/var>} is {@code true}, it is checked that the arguments are + * compatible. + */ public MDArray(T[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -73,8 +101,7 @@ public class MDArray<T> extends MDAbstractArray<T> @SuppressWarnings("unchecked") private static <V> V[] createArray(Class<V> componentClass, final int vectorLength) { - final V[] value = - (V[]) java.lang.reflect.Array.newInstance(componentClass, vectorLength); + final V[] value = (V[]) java.lang.reflect.Array.newInstance(componentClass, vectorLength); return value; } @@ -194,11 +221,11 @@ public class MDArray<T> extends MDAbstractArray<T> { return (Class<T>) flattenedArray.getClass().getComponentType(); } - + // // Object // - + @Override public int hashCode() { @@ -235,7 +262,7 @@ public class MDArray<T> extends MDAbstractArray<T> } return true; } - + @SuppressWarnings("unchecked") private MDArray<T> toMDArray(Object obj) { diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDByteArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDByteArray.java index ba820ba5bc434201c23aa475618353cb2f26954a..0da289594d9f7a0c5af355417ab6ffd6e167d5b7 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDByteArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDByteArray.java @@ -27,31 +27,58 @@ public final class MDByteArray extends MDAbstractArray<Byte> { private final byte[] flattenedArray; + /** + * Creates an empty {@link MDByteArray} with the <var>dimensions</var>. Convenience method if + * <var>dimensions</var> are available as {@code long[]}. + */ public MDByteArray(long[] dimensions) { this(new byte[getLength(dimensions)], toInt(dimensions), false); } + /** + * Creates a {@link MDByteArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. Convenience method if <var>dimensions</var> + * are available as {@code long[]}. + */ public MDByteArray(byte[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDByteArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. Convenience method if <var>dimensions</var> are available as + * {@code long[]}. + */ public MDByteArray(byte[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDByteArray} with the <var>dimensions</var>. + */ public MDByteArray(int[] dimensions) { this(new byte[getLength(dimensions)], dimensions, false); } + /** + * Creates a {@link MDByteArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. + */ public MDByteArray(byte[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDByteArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. + */ public MDByteArray(byte[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -69,11 +96,22 @@ public final class MDByteArray extends MDAbstractArray<Byte> this.flattenedArray = flattenedArray; } + /** + * Creates a {@link MDByteArray} from the given <var>matrix</var> of rank 2. Note that the + * values in <var>matrix</var> will be copied and thus the created {@link MDDoubleArray} will be + * independent from <var>matrix</var> after construction. + */ public MDByteArray(byte[][] matrix) { this(matrix, getDimensions(matrix)); } - + + /** + * Creates a {@link MDByteArray} from the given <var>matrix</var> of rank 2 and the + * <var>dimension</var> which need to be less or equal the dimensions of <var>matrix</var>. Note + * that the values in <var>matrix</var> will be copied and thus the created + * {@link MDDoubleArray} will be independent from <var>matrix</var> after construction. + */ public MDByteArray(byte[][] matrix, int[] dimensions) { super(dimensions); @@ -95,8 +133,9 @@ public final class MDByteArray extends MDAbstractArray<Byte> private static int[] getDimensions(byte[][] matrix) { assert matrix != null; - - return new int[] { matrix.length, matrix.length == 0 ? 0 : matrix[0].length }; + + return new int[] + { matrix.length, matrix.length == 0 ? 0 : matrix[0].length }; } @Override @@ -223,7 +262,7 @@ public final class MDByteArray extends MDAbstractArray<Byte> } return result; } - + // // Object // diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDDoubleArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDDoubleArray.java index 182ede3aa07231b0ccc6264d2a699ad94619d5a0..a5281543c661b96b8e9e29ecf91b11200865c7b2 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDDoubleArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDDoubleArray.java @@ -27,31 +27,58 @@ public final class MDDoubleArray extends MDAbstractArray<Double> { private final double[] flattenedArray; + /** + * Creates an empty {@link MDDoubleArray} with the <var>dimensions</var>. Convenience method if + * <var>dimensions</var> are available as {@code long[]}. + */ public MDDoubleArray(long[] dimensions) { this(new double[getLength(dimensions)], toInt(dimensions), false); } + /** + * Creates a {@link MDDoubleArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. Convenience method if <var>dimensions</var> + * are available as {@code long[]}. + */ public MDDoubleArray(double[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDDoubleArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. Convenience method if <var>dimensions</var> are available as + * {@code long[]}. + */ public MDDoubleArray(double[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDDoubleArray} with the <var>dimensions</var>. + */ public MDDoubleArray(int[] dimensions) { this(new double[getLength(dimensions)], dimensions, false); } + /** + * Creates a {@link MDDoubleArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. + */ public MDDoubleArray(double[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDDoubleArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. + */ public MDDoubleArray(double[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -69,11 +96,22 @@ public final class MDDoubleArray extends MDAbstractArray<Double> this.flattenedArray = flattenedArray; } + /** + * Creates a {@link MDDoubleArray} from the given <var>matrix</var> of rank 2. Note that the + * values in <var>matrix</var> will be copied and thus the created {@link MDDoubleArray} will be + * independent from <var>matrix</var> after construction. + */ public MDDoubleArray(double[][] matrix) { this(matrix, getDimensions(matrix)); } - + + /** + * Creates a {@link MDDoubleArray} from the given <var>matrix</var> of rank 2 and the + * <var>dimension</var> which need to be less or equal the dimensions of <var>matrix</var>. Note + * that the values in <var>matrix</var> will be copied and thus the created + * {@link MDDoubleArray} will be independent from <var>matrix</var> after construction. + */ public MDDoubleArray(double[][] matrix, int[] dimensions) { super(dimensions); @@ -95,8 +133,9 @@ public final class MDDoubleArray extends MDAbstractArray<Double> private static int[] getDimensions(double[][] matrix) { assert matrix != null; - - return new int[] { matrix.length, matrix.length == 0 ? 0 : matrix[0].length }; + + return new int[] + { matrix.length, matrix.length == 0 ? 0 : matrix[0].length }; } @Override @@ -133,7 +172,7 @@ public final class MDDoubleArray extends MDAbstractArray<Double> { return flattenedArray[computeIndex(indices)]; } - + /** * Returns the value of a one-dimensional array at the position defined by <var>index</var>. * <p> @@ -223,11 +262,11 @@ public final class MDDoubleArray extends MDAbstractArray<Double> } return result; } - + // // Object // - + @Override public int hashCode() { diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDFloatArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDFloatArray.java index ea6b86d34fe7101504686ed32af27b94b9b6c30d..e5eb557e42792e14a4822752cc11923e83b43a9b 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDFloatArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDFloatArray.java @@ -27,31 +27,58 @@ public final class MDFloatArray extends MDAbstractArray<Float> { private final float[] flattenedArray; + /** + * Creates an empty {@link MDDoubleArray} with the <var>dimensions</var>. Convenience method if + * <var>dimensions</var> are available as {@code long[]}. + */ public MDFloatArray(long[] dimensions) { this(new float[getLength(dimensions)], toInt(dimensions), false); } + /** + * Creates a {@link MDDoubleArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. Convenience method if <var>dimensions</var> + * are available as {@code long[]}. + */ public MDFloatArray(float[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDDoubleArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. Convenience method if <var>dimensions</var> are available as + * {@code long[]}. + */ public MDFloatArray(float[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDDoubleArray} with the <var>dimensions</var>. + */ public MDFloatArray(int[] dimensions) { this(new float[getLength(dimensions)], dimensions, false); } + /** + * Creates a {@link MDDoubleArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. + */ public MDFloatArray(float[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDDoubleArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. + */ public MDFloatArray(float[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -69,11 +96,22 @@ public final class MDFloatArray extends MDAbstractArray<Float> this.flattenedArray = flattenedArray; } + /** + * Creates a {@link MDFloatArray} from the given <var>matrix</var> of rank 2. Note that the + * values in <var>matrix</var> will be copied and thus the created {@link MDDoubleArray} will be + * independent from <var>matrix</var> after construction. + */ public MDFloatArray(float[][] matrix) { this(matrix, getDimensions(matrix)); } + /** + * Creates a {@link MDFloatArray} from the given <var>matrix</var> of rank 2 and the + * <var>dimension</var> which need to be less or equal the dimensions of <var>matrix</var>. Note + * that the values in <var>matrix</var> will be copied and thus the created + * {@link MDDoubleArray} will be independent from <var>matrix</var> after construction. + */ public MDFloatArray(float[][] matrix, int[] dimensions) { super(dimensions); diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDIntArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDIntArray.java index c9bbfc0a6cdea0425340dc123e090af87dc4b845..9caf649431f769e037f49e5d609fb66866e77cf7 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDIntArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDIntArray.java @@ -27,31 +27,58 @@ public final class MDIntArray extends MDAbstractArray<Integer> { private final int[] flattenedArray; + /** + * Creates an empty {@link MDIntArray} with the <var>dimensions</var>. Convenience method if + * <var>dimensions</var> are available as {@code long[]}. + */ public MDIntArray(long[] dimensions) { this(new int[getLength(dimensions)], toInt(dimensions), false); } + /** + * Creates a {@link MDIntArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. Convenience method if <var>dimensions</var> + * are available as {@code long[]}. + */ public MDIntArray(int[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDIntArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. Convenience method if <var>dimensions</var> are available as + * {@code long[]}. + */ public MDIntArray(int[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDIntArray} with the <var>dimensions</var>. + */ public MDIntArray(int[] dimensions) { this(new int[getLength(dimensions)], dimensions, false); } + /** + * Creates a {@link MDIntArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. + */ public MDIntArray(int[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDIntArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. + */ public MDIntArray(int[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -69,11 +96,22 @@ public final class MDIntArray extends MDAbstractArray<Integer> this.flattenedArray = flattenedArray; } + /** + * Creates a {@link MDIntArray} from the given <var>matrix</var> of rank 2. Note that the + * values in <var>matrix</var> will be copied and thus the created {@link MDDoubleArray} will be + * independent from <var>matrix</var> after construction. + */ public MDIntArray(int[][] matrix) { this(matrix, getDimensions(matrix)); } + /** + * Creates a {@link MDIntArray} from the given <var>matrix</var> of rank 2 and the + * <var>dimension</var> which need to be less or equal the dimensions of <var>matrix</var>. Note + * that the values in <var>matrix</var> will be copied and thus the created + * {@link MDDoubleArray} will be independent from <var>matrix</var> after construction. + */ public MDIntArray(int[][] matrix, int[] dimensions) { super(dimensions); diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDLongArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDLongArray.java index e4e3d76bd7841b62fecd25e911c60046c5573722..53c06f30ba608923cbf43bacf085da175ab7e450 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDLongArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDLongArray.java @@ -27,31 +27,58 @@ public final class MDLongArray extends MDAbstractArray<Long> { private final long[] flattenedArray; + /** + * Creates an empty {@link MDLongArray} with the <var>dimensions</var>. Convenience method if + * <var>dimensions</var> are available as {@code long[]}. + */ public MDLongArray(long[] dimensions) { this(new long[getLength(dimensions)], toInt(dimensions), false); } + /** + * Creates a {@link MDLongArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. Convenience method if <var>dimensions</var> + * are available as {@code long[]}. + */ public MDLongArray(long[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDLongArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. Convenience method if <var>dimensions</var> are available as + * {@code long[]}. + */ public MDLongArray(long[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDLongArray} with the <var>dimensions</var>. + */ public MDLongArray(int[] dimensions) { this(new long[getLength(dimensions)], dimensions, false); } + /** + * Creates a {@link MDLongArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. + */ public MDLongArray(long[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDLongArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. + */ public MDLongArray(long[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -69,11 +96,22 @@ public final class MDLongArray extends MDAbstractArray<Long> this.flattenedArray = flattenedArray; } + /** + * Creates a {@link MDLongArray} from the given <var>matrix</var> of rank 2. Note that the + * values in <var>matrix</var> will be copied and thus the created {@link MDDoubleArray} will be + * independent from <var>matrix</var> after construction. + */ public MDLongArray(long[][] matrix) { this(matrix, getDimensions(matrix)); } + /** + * Creates a {@link MDLongArray} from the given <var>matrix</var> of rank 2 and the + * <var>dimension</var> which need to be less or equal the dimensions of <var>matrix</var>. Note + * that the values in <var>matrix</var> will be copied and thus the created + * {@link MDDoubleArray} will be independent from <var>matrix</var> after construction. + */ public MDLongArray(long[][] matrix, int[] dimensions) { super(dimensions); diff --git a/base/source/java/ch/systemsx/cisd/base/mdarray/MDShortArray.java b/base/source/java/ch/systemsx/cisd/base/mdarray/MDShortArray.java index 9fe36e5e2cd0b3e69568323e18cc27d959b8507f..ecd50df0812ae3fa2fddc571c5c98c8f79f984ad 100644 --- a/base/source/java/ch/systemsx/cisd/base/mdarray/MDShortArray.java +++ b/base/source/java/ch/systemsx/cisd/base/mdarray/MDShortArray.java @@ -27,31 +27,58 @@ public final class MDShortArray extends MDAbstractArray<Short> { private final short[] flattenedArray; + /** + * Creates an empty {@link MDShortArray} with the <var>dimensions</var>. Convenience method if + * <var>dimensions</var> are available as {@code long[]}. + */ public MDShortArray(long[] dimensions) { this(new short[getLength(dimensions)], toInt(dimensions), false); } + /** + * Creates a {@link MDShortArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. Convenience method if <var>dimensions</var> + * are available as {@code long[]}. + */ public MDShortArray(short[] flattenedArray, long[] dimensions) { this(flattenedArray, toInt(dimensions), true); } + /** + * Creates a {@link MDShortArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. Convenience method if <var>dimensions</var> are available as + * {@code long[]}. + */ public MDShortArray(short[] flattenedArray, long[] dimensions, boolean checkdimensions) { this(flattenedArray, toInt(dimensions), checkdimensions); } + /** + * Creates an empty {@link MDShortArray} with the <var>dimensions</var>. + */ public MDShortArray(int[] dimensions) { this(new short[getLength(dimensions)], dimensions, false); } + /** + * Creates a {@link MDShortArray} from the given {@code flattenedArray} and {@code dimensions}. + * It is checked that the arguments are compatible. + */ public MDShortArray(short[] flattenedArray, int[] dimensions) { this(flattenedArray, dimensions, true); } + /** + * Creates a {@link MDShortArray} from the given <var>flattenedArray</var> and + * <var>dimensions</var>. If <var>checkDimensions/var>} is {@code true}, it is checked that the + * arguments are compatible. + */ public MDShortArray(short[] flattenedArray, int[] dimensions, boolean checkdimensions) { super(dimensions); @@ -69,11 +96,22 @@ public final class MDShortArray extends MDAbstractArray<Short> this.flattenedArray = flattenedArray; } + /** + * Creates a {@link MDShortArray} from the given <var>matrix</var> of rank 2. Note that the + * values in <var>matrix</var> will be copied and thus the created {@link MDDoubleArray} will be + * independent from <var>matrix</var> after construction. + */ public MDShortArray(short[][] matrix) { this(matrix, getDimensions(matrix)); } + /** + * Creates a {@link MDShortArray} from the given <var>matrix</var> of rank 2 and the + * <var>dimension</var> which need to be less or equal the dimensions of <var>matrix</var>. Note + * that the values in <var>matrix</var> will be copied and thus the created + * {@link MDDoubleArray} will be independent from <var>matrix</var> after construction. + */ public MDShortArray(short[][] matrix, int[] dimensions) { super(dimensions);