Class Matrix<E>
java.lang.Object
ch.nolix.base.container.base.AbstractContainer<E>
ch.nolix.base.container.arraylist.AbstractExtendedContainer<E>
ch.nolix.base.container.matrix.Matrix<E>
- Type Parameters:
E- is the type of the elements of aMatrix.
- All Implemented Interfaces:
Filterable<E>, Groupable<E>, IContainer<E>, IFilteringContainerViewProvider<E>, IIntervallContainerViewProvider<E>, IMappingContainerViewProvider<E>, Mappable<E>, AggregationRequestable<E>, ArrayMappable<E>, CountRequestable<E>, IndexRequestable<E>, IterableWithCopyableIterator<E>, SingleSearchable<E>, StoringRequestable<E>, StringMappable, IMatrix<E>, Clearable, EmptinessRequestable, MaterializationRequestable, Iterable<E>
A
Matrix is a AbstractContainer that stores its elements in
rows and columns. A Matrix is clearable.- Author:
- Silvan Wyss
-
Method Summary
Modifier and TypeMethodDescriptionAdds a new column to the currentMatrixwith the given elements.Adds a new column to the currentMatrixwith the given elements.Adds a new row to the currentMatrixwith the given elements.Adds a new row to the currentMatrixwith the given elements.voidclear()Removes all elements of the currentMatrix.static <T> Matrix<T> static <T> Matrix<T> fromMatrix(IMatrix<T> matrix) getColumn(int oneBasedColumnIndex) intThe time complexity of this implementation is O(1).intgetColumnIndexOf(int index) getCopy()The time complexity of this implementation is O(m * n) if: -This matrix contains m rows.intgetCount()The time complexity of this implementation is O(1).intgetIndexOf(int rowIndex, int columnIndex) getRow(int oneBasedRowIndex) intThe time complexity of this implementation is O(1).intgetRowIndexOf(int index) getRows()getStoredAtOneBasedIndex(int oneBasedIndex) getStoredAtOneBasedRowIndexAndColumnIndex(int oneBasedRowIndex, int oneBasedColumnIndex) The time complexity of this implementation is O(1).booleaniterator()The time complexity of this implementation is O(1).voidSets the given element to the currentMatrixat the given index.voidsetAtOneBasedRowIndexAndColumnIndex(int oneBasedRowIndex, int oneBasedColumnIndex, E element) Sets the given element to the currentMatrixto the row with the given row index and the column with the given column index.The time complexity of this implementation is O(n) if the currentMatrixcontains n elements.<O> Matrix<O> The time complexity of this implementation is O(n) if: -This matrix contains n elements.The time complexity of this implementation is O(n) if the currentMatrixcontains n elements.toString()The time complexity of this implementation is O(n) if: -The currentMatrixcontains n elements.Methods inherited from class AbstractExtendedContainer
getViewFromOneBasedStartIndexToOneBasedEndIndex, getViewOf, getViewOfStoredSelected, toOrderedListMethods inherited from class AbstractContainer
contains, containsAllOf, containsAllOf, containsAny, containsAnyOf, containsAnyOf, containsAsManyAs, containsEqualing, containsExactlyEqualingInSameOrder, containsExactlyInSameOrder, containsLessThan, containsMoreThan, containsNone, containsNoneOf, containsNoneOf, containsOnce, containsOne, containsOne, containsOneEqualing, containsOnly, getAverage, getAverageOrZero, getCount, getCountOf, getMax, getMaxOrZero, getMedian, getMedianOrZero, getMin, getMinOrZero, getOneBasedIndexOfFirst, getOneBasedIndexOfFirstEqualElement, getOneBasedIndexOfFirstOccurrenceOf, getOptionalStoredFirst, getOptionalStoredFirst, getStandardDeviation, getStoredByMax, getStoredByMin, getStoredFirst, getStoredFirst, getStoredFirstOfType, getStoredInGroups, getStoredLast, getStoredOfType, getStoredOne, getStoredOne, getStoredOthers, getStoredSelected, getSum, getSumOfInts, getVariance, getViewFromOneBasedStartIndex, getViewToOneBasedEndIndex, getViewWithoutFirst, getViewWithoutFirst, getViewWithoutLast, getViewWithoutLast, isEmpty, to, toArray, toByteArray, toCharArray, toConcatenatedString, toDoubleArray, toIntArray, toLongArray, toMultiples, toNumbers, toReversedList, toStringArray, toStrings, toStringWithSeparator, toStringWithSeparator, toWithOneBasedIndexMethods inherited from interface AggregationRequestable
getAverage, getAverageOrZero, getMax, getMaxOrZero, getMedian, getMedianOrZero, getMin, getMinOrZero, getStandardDeviation, getSum, getSumOfInts, getVarianceMethods inherited from interface ArrayMappable
toArray, toByteArray, toCharArray, toDoubleArray, toIntArray, toLongArray, toStringArrayMethods inherited from interface CountRequestable
getCount, getCountOfMethods inherited from interface EmptinessRequestable
containsAny, isEmptyMethods inherited from interface Filterable
getStoredOfType, getStoredOthers, getStoredSelectedMethods inherited from interface Groupable
getStoredInGroupsMethods inherited from interface IContainer
toOrderedList, toReversedListMethods inherited from interface IFilteringContainerViewProvider
getViewOfStoredSelectedMethods inherited from interface IIntervallContainerViewProvider
getViewFromOneBasedStartIndex, getViewFromOneBasedStartIndexToOneBasedEndIndex, getViewToOneBasedEndIndex, getViewWithoutFirst, getViewWithoutFirst, getViewWithoutLast, getViewWithoutLastMethods inherited from interface IMappingContainerViewProvider
getViewOfMethods inherited from interface IndexRequestable
getOneBasedIndexOfFirst, getOneBasedIndexOfFirstEqualElement, getOneBasedIndexOfFirstOccurrenceOfMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface Mappable
to, toMultiples, toNumbers, toStrings, toWithOneBasedIndexMethods inherited from interface MaterializationRequestable
isViewMethods inherited from interface SingleSearchable
getOptionalStoredFirst, getOptionalStoredFirst, getStoredByMax, getStoredByMin, getStoredFirst, getStoredFirst, getStoredFirstOfType, getStoredLast, getStoredOne, getStoredOneMethods inherited from interface StoringRequestable
contains, containsAllOf, containsAllOf, containsAny, containsAnyOf, containsAnyOf, containsAsManyAs, containsEqualing, containsExactlyEqualingInSameOrder, containsExactlyInSameOrder, containsLessThan, containsMoreThan, containsNone, containsNoneOf, containsNoneOf, containsOnce, containsOne, containsOne, containsOneEqualing, containsOnlyMethods inherited from interface StringMappable
toConcatenatedString, toStringWithSeparator, toStringWithSeparator
-
Method Details
-
createEmpty
-
fromMatrix
-
addColumn
Adds a new column to the currentMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMatrixcontains m elements. -n elements are given.- Parameters:
elements-- Returns:
- the current
Matrix. - Throws:
RuntimeException- if the given elements is null.RuntimeException- if one of the given elements is null.UnequalArgumentException- if the currentMatrixis not empty or not as many elements are given as the number of rows of the currentMatrix.
-
addColumn
Adds a new column to the currentMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMatrixcontains m elements. -n elements are given.- Parameters:
elements-- Returns:
- the current
Matrix. - Throws:
RuntimeException- if the given elements is null.RuntimeException- if one of the given elements is null.UnequalArgumentException- if the currentMatrixis not empty and if not as many elements are given as the number of rows of the currentMatrix.
-
addRow
Adds a new row to the currentMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMatrixcontains m rows. -n elements are given.- Parameters:
elements-- Returns:
- the current
Matrix. - Throws:
RuntimeException- if the given elements is null.RuntimeException- if one of the given elements is null.UnequalArgumentException- the currentMatrixis not empty and if not as many elements are given as the number of columns of the currentMatrix.
-
addRow
Adds a new row to the currentMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMatrixcontains m rows. -n elements are given.- Parameters:
elements-- Returns:
- the current
Matrix. - Throws:
RuntimeException- if the given elements is null.RuntimeException- if one of the given elements is null.UnequalArgumentException- the currentMatrixis not empty and if not as many elements are given as the number of columns of the currentMatrix.
-
clear
-
getColumn
- Parameters:
oneBasedColumnIndex-- Returns:
- the column of the current
Matrixat the given oneBasedColumnIndex. - Throws:
RuntimeException- if the given oneBasedColumnIndex is not positive or bigger than the number of the columns of the currentMatrix.
-
getColumnCount
public int getColumnCount()The time complexity of this implementation is O(1).- Specified by:
getColumnCountin interfaceIMatrix<E>- Returns:
- the number of columns of the current
Matrix.
-
getColumnIndexOf
public int getColumnIndexOf(int index) - Parameters:
index-- Returns:
- the index of the column of the element of the current
Matrixat the given index. - Throws:
RuntimeException- if the given index is not positive.RuntimeException- if the given index is bigger than the number of elements of the currentMatrix.
-
getColumns
- Specified by:
getColumnsin interfaceIMatrix<E>- Returns:
- the columns of the current
Matrix.
-
getCopy
-
getCount
public int getCount()The time complexity of this implementation is O(1).- Specified by:
getCountin interfaceCountRequestable<E>- Returns:
- the number of elements of the current
Matrix.
-
getIndexOf
public int getIndexOf(int rowIndex, int columnIndex) - Parameters:
rowIndex-columnIndex-- Returns:
- the index of the element of the current
Matrixat the given row index and column index. - Throws:
RuntimeException- if the given row index is not positive.RuntimeException- if the given row index is bigger than the number of rows of the currentMatrix.RuntimeException- if the given column index is not positive.RuntimeException- if the given column index is bigger than the number of columns of the currentMatrix.
-
getStoredAtOneBasedIndex
- Specified by:
getStoredAtOneBasedIndexin interfaceSingleSearchable<E>- Parameters:
oneBasedIndex-- Returns:
- the element of the current
Matrixat the given index . - Throws:
RuntimeException- if the given index is not positive.RuntimeException- if the given index is bigger than the number of elements of the currentMatrix.
-
getStoredAtOneBasedRowIndexAndColumnIndex
The time complexity of this implementation is O(1).- Specified by:
getStoredAtOneBasedRowIndexAndColumnIndexin interfaceIMatrix<E>- Parameters:
oneBasedRowIndex-oneBasedColumnIndex-- Returns:
- the element of the current
Matrixat the given row index and column index. - Throws:
RuntimeException- if the given row index is not positive.RuntimeException- if the given row index is bigger than the number of rows of the currentMatrix.RuntimeException- if the given column index is not positive.RuntimeException- if the given column index is bigger than the number of columns of the currentMatrix.
-
getRow
- Parameters:
oneBasedRowIndex-- Returns:
- the row of the current
Matrixat the given oneBasedRowIndex. - Throws:
RuntimeException- if the given oneBasedRowIndex is not positive or bigger than the number of rows of the currentMatrix.
-
getRowIndexOf
public int getRowIndexOf(int index) - Parameters:
index-- Returns:
- the index of the row of the element of the current
Matrixat the given index. - Throws:
RuntimeException- if the given index is not positive.RuntimeException- if the given index is bigger than the number of elements of the currentMatrix.
-
getRows
-
getRowCount
public int getRowCount()The time complexity of this implementation is O(1).- Specified by:
getRowCountin interfaceIMatrix<E>- Returns:
- the number of rows of the current
Matrix.
-
isMaterialized
public boolean isMaterialized()- Specified by:
isMaterializedin interfaceMaterializationRequestable- Returns:
- true if the current
MaterializationRequestableis materialized, false otherwise.
-
iterator
The time complexity of this implementation is O(1). -
setAt
Sets the given element to the currentMatrixat the given index. The complexity of this implementation is O(1).- Parameters:
index-element-- Throws:
RuntimeException- if the given index is not positive.RuntimeException- if the given index is bigger than the number of elements of the currentMatrix.RuntimeException- if the given element is null.
-
setAtOneBasedRowIndexAndColumnIndex
public void setAtOneBasedRowIndexAndColumnIndex(int oneBasedRowIndex, int oneBasedColumnIndex, E element) Sets the given element to the currentMatrixto the row with the given row index and the column with the given column index. The time complexity of this implementation is O(1).- Specified by:
setAtOneBasedRowIndexAndColumnIndexin interfaceIMatrix<E>- Parameters:
oneBasedRowIndex-oneBasedColumnIndex-element-- Throws:
RuntimeException- if the given row index is not positive.RuntimeException- if the given row index is bigger than the number of rows of the currentMatrix.RuntimeException- if the given column index is not positive.RuntimeException- if the given column index is bigger than the number of columns of the currentMatrix.RuntimeException- if the given element is null.
-
toMatrix
The time complexity of this implementation is O(n) if: -This matrix contains n elements. -The given transformer has a complexity of O(1).- Type Parameters:
O- is the type of the elements the given transformer returns.- Parameters:
transformer-- Returns:
- a new matrix with the elements the given transformer transforms of
the elements of the current
Matrix.
-
toLeftRotatedMatrix
-
toRightRotatedMatrix
-
toString
-