Class MDAbstractArray<T>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  MDAbstractArray.ArrayEntry
      A class to represent an entry (index and value) of a MDArray, used for iteration.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void adaptCapacityHyperRows()  
      abstract int capacity()
      Returns the capacity of elements in the array.
      protected int computeHyperRowLength​(int[] dimensions)  
      int computeIndex​(int... indices)
      Computes the linear index for the multi-dimensional indices provided.
      int computeIndex​(int indexX, int indexY)
      Computes the linear index for the two-dimensional (indexX, indexY) provided.
      int computeIndex​(int indexX, int indexY, int indexZ)
      Computes the linear index for the three-dimensional (indexX, indexY, indexZ) provided.
      int[] computeReverseIndex​(int linearIndex)
      Computes the multi-dimensional index from the linearIndex.
      int decNumberOfHyperRows​(int count)
      Decrease the number of hyper-rows by count.
      int[] dimensions()
      Returns a copy of the dimensions of the multi-dimensional array.
      abstract java.lang.Object getAsFlatArray()
      Returns the array in flattened form.
      abstract T getAsObject​(int linearIndex)
      Return an object which has the same value as the element of the array specified by linearIndex.
      abstract T getAsObject​(int... indices)
      Return an object which has the same value as the element of the array specified by indices.
      abstract java.lang.Object getCopyAsFlatArray()
      Returns a copy of the array in flattened form.
      static int getLength​(int[] dimensions)
      Returns the one-dimensional length of the multi-dimensional array defined by dimensions.
      static int getLength​(int[] dimensions, int capacityHyperRows)
      Returns the one-dimensional length of the multi-dimensional array defined by dimensions.
      static int getLength​(long[] dimensions)
      Returns the one-dimensional length of the multi-dimensional array defined by dimensions.
      static int getLength​(long[] dimensions, long capacityHyperRows)
      Returns the one-dimensional length of the multi-dimensional array defined by dimensions.
      int incNumberOfHyperRows​(int count)
      Increase the number of hyper-rows by count.
      java.util.Iterator<MDAbstractArray.ArrayEntry> iterator()  
      long[] longDimensions()
      Returns a copy of the dimensions of the multi-dimensional array as long[].
      int numberOfHyperRows()
      Returns the current number of hyper rows of of this array.
      int rank()
      Returns the rank of the array.
      abstract void setToObject​(T value, int linearIndex)
      Sets the element of the array specified by linearIndex to the particular value.
      abstract void setToObject​(T value, int... indices)
      Sets the element of the array specified by indices to the particular value.
      int size()
      Returns the number of elements in the array.
      int size​(int dim)
      Returns the extent of the array along its dim-th axis.
      static int[] toInt​(long[] dimensions)
      Converts the dimensions from long[] to int[].
      static long[] toLong​(int[] dimensions)
      Converts the dimensions from int[] to long[].
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • dimensions

        protected final int[] dimensions
      • hyperRowLength

        protected int hyperRowLength
      • capacityHyperRows

        protected int capacityHyperRows
      • size

        protected int size
    • Constructor Detail

      • MDAbstractArray

        protected MDAbstractArray​(int[] dimensions,
                                  int arrayLength,
                                  int capacityHyperRows)
    • Method Detail

      • computeHyperRowLength

        protected int computeHyperRowLength​(int[] dimensions)
      • rank

        public int rank()
        Returns the rank of the array.
      • size

        public int size​(int dim)
        Returns the extent of the array along its dim-th axis.
      • dimensions

        public int[] dimensions()
        Returns a copy of the dimensions of the multi-dimensional array.
      • longDimensions

        public long[] longDimensions()
        Returns a copy of the dimensions of the multi-dimensional array as long[].
      • size

        public int size()
        Returns the number of elements in the array.
      • numberOfHyperRows

        public int numberOfHyperRows()
        Returns the current number of hyper rows of of this array.
      • getAsObject

        public abstract T getAsObject​(int linearIndex)
        Return an object which has the same value as the element of the array specified by linearIndex.
        Parameters:
        linearIndex - The index in the linear array returned by getAsFlatArray().
        Returns:
        The value at the specified index.
      • getAsObject

        public abstract T getAsObject​(int... indices)
        Return an object which has the same value as the element of the array specified by indices.
      • setToObject

        public abstract void setToObject​(T value,
                                         int... indices)
        Sets the element of the array specified by indices to the particular value.
      • setToObject

        public abstract void setToObject​(T value,
                                         int linearIndex)
        Sets the element of the array specified by linearIndex to the particular value.
        Parameters:
        value - The new value to set.
        linearIndex - The index in the linear array returned by getAsFlatArray().
      • getAsFlatArray

        public abstract java.lang.Object getAsFlatArray()
        Returns the array in flattened form. Changes to the returned object will change the multi-dimensional array directly.
      • getCopyAsFlatArray

        public abstract java.lang.Object getCopyAsFlatArray()
        Returns a copy of the array in flattened form. Changes to the returned object will not change the multi-dimensional array directly.
      • adaptCapacityHyperRows

        protected abstract void adaptCapacityHyperRows()
      • capacity

        public abstract int capacity()
        Returns the capacity of elements in the array.
      • incNumberOfHyperRows

        public int incNumberOfHyperRows​(int count)
        Increase the number of hyper-rows by count. Doubles the capacity if needed.
        Returns:
        The new number of rows.
      • decNumberOfHyperRows

        public int decNumberOfHyperRows​(int count)
        Decrease the number of hyper-rows by count.
        Returns:
        The new number of rows.
      • computeIndex

        public int computeIndex​(int... indices)
        Computes the linear index for the multi-dimensional indices provided.
      • computeReverseIndex

        public int[] computeReverseIndex​(int linearIndex)
        Computes the multi-dimensional index from the linearIndex.
      • computeIndex

        public int computeIndex​(int indexX,
                                int indexY)
        Computes the linear index for the two-dimensional (indexX, indexY) provided.
      • computeIndex

        public int computeIndex​(int indexX,
                                int indexY,
                                int indexZ)
        Computes the linear index for the three-dimensional (indexX, indexY, indexZ) provided.
      • toInt

        public static int[] toInt​(long[] dimensions)
        Converts the dimensions from long[] to int[].
      • toLong

        public static long[] toLong​(int[] dimensions)
        Converts the dimensions from int[] to long[].
      • getLength

        public static int getLength​(int[] dimensions)
        Returns the one-dimensional length of the multi-dimensional array defined by dimensions.
        Throws:
        java.lang.IllegalArgumentException - If dimensions overflow the int type.
      • getLength

        public static int getLength​(int[] dimensions,
                                    int capacityHyperRows)
        Returns the one-dimensional length of the multi-dimensional array defined by dimensions. If capacityHyperRows > dimensions[0], then it will replace dimensions[0] by capacityHyperRows
        Throws:
        java.lang.IllegalArgumentException - If dimensions overflow the int type.
      • getLength

        public static int getLength​(long[] dimensions)
        Returns the one-dimensional length of the multi-dimensional array defined by dimensions.
        Throws:
        java.lang.IllegalArgumentException - If dimensions overflow the int type.
      • getLength

        public static int getLength​(long[] dimensions,
                                    long capacityHyperRows)
        Returns the one-dimensional length of the multi-dimensional array defined by dimensions. If capacityHyperRows > dimensions[0], then it will replace dimensions[0] by capacityHyperRows
        Throws:
        java.lang.IllegalArgumentException - If dimensions overflow the int type.
      • iterator

        public java.util.Iterator<MDAbstractArray.ArrayEntry> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object