Class MutableMatrix<E>
java.lang.Object
ch.nolix.base.datastructure.extendediterable.AbstractExtendedIterable<E>
ch.nolix.base.datastructure.matrix.MutableMatrix<E>
- Type Parameters:
E- the type of the elements of aMutableMatrix.
- All Implemented Interfaces:
IterableWithCopyableIterator<E>, ExtendedIterable<E>, IterableFilterProvider<E>, IterableFilterViewProvider<E>, IterableGroupProvider<E>, IterableIntervalViewProvider<E>, IterableMappedProvider<E>, IterableMappedViewProvider<E>, IterableOrderProvider<E>, IterableArrayProvider<E>, IterableByExtremumProvider<E>, IterableByIndexProvider<E>, IterableFirstProvider<E>, IterableLastProvider<E>, IterableStringProvider, IterableContainAnyRequestable, IterableContainEqualRequestable<E>, IterableContainMatchingRequestable<E>, IterableContainMultipleRequestable, IterableContainObjectRequestable, IterableOneBasedIndexRequestable<E>, IMatrix<E>, AggregationRequestable<E>, BaseCountRequestable, CountRequestable<E>, SingleProvider<E>, Clearable, EmptinessRequestable, MaterializationRequestable, Iterable<E>
A
MutableMatrix is a AbstractExtendedIterable that stores its
elements in rows and columns. A MutableMatrix is clearable.- Author:
- Silvan Wyss
-
Method Summary
Modifier and TypeMethodDescriptionAdds a new column to the currentMutableMatrixwith the given elements.Adds a new column to the currentMutableMatrixwith the given elements.Adds a new row to the currentMutableMatrixwith the given elements.Adds a new row to the currentMutableMatrixwith the given elements.voidclear()Removes all elements of the currentMutableMatrix.static <T> MutableMatrix<T> static <T> MutableMatrix<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 currentMutableMatrixat the given index.voidsetAtOneBasedRowIndexAndColumnIndex(int oneBasedRowIndex, int oneBasedColumnIndex, E element) Sets the given element to the currentMutableMatrixto 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 currentMutableMatrixcontains n elements.<O> MutableMatrix<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 currentMutableMatrixcontains n elements.toString()The time complexity of this implementation is O(n) if: -The currentMutableMatrixcontains n elements.Methods inherited from class AbstractExtendedIterable
contains, containsAll, containsAll, containsAny, containsAny, containsAny, containsEqual, containsExactlyAllEqualInSameOrder, containsExactlyInSameOrder, containsMatching, containsMatchingOnly, containsNoEqual, containsNoMatching, containsNone, containsNone, containsNonNull, containsOnce, containsOne, containsOneEqual, containsOneMatching, containsOneNoneNull, containsOnly, getAverage, getAverageOrZero, getCount, getCountOf, getMax, getMaxOrZero, getMedian, getMedianOrZero, getMin, getMinOrZero, getOneBasedIndexOfFirst, getOneBasedIndexOfFirstEqualElement, getOneBasedIndexOfFirstOccurrenceOf, getOptionalStoredFirst, getOptionalStoredFirst, getStandardDeviation, getStoredByMax, getStoredByMin, getStoredFirst, getStoredFirst, getStoredFirstNonNull, getStoredFirstOfType, getStoredInGroups, getStoredLast, getStoredOfType, getStoredOthers, getStoredSelected, getStoredSingle, getStoredSingle, getSum, getSumOfInts, getVariance, getViewFromOneBasedStartIndex, getViewFromOneBasedStartIndexToOneBasedEndIndex, getViewOf, getViewOfStoredSelected, getViewToOneBasedEndIndex, getViewWithoutFirst, getViewWithoutFirst, getViewWithoutLast, getViewWithoutLast, isEmpty, to, toArray, toByteArray, toCharArray, toConcatenatedString, toDoubleArray, toIntArray, toLongArray, toMultiples, toNumbers, toOrdered, toReversed, toStringArray, toStrings, toStringWithDelimiter, toStringWithDelimiter, toWithOneBasedIndexMethods inherited from interface AggregationRequestable
getAverage, getAverageOrZero, getMax, getMaxOrZero, getMedian, getMedianOrZero, getMin, getMinOrZero, getStandardDeviation, getSum, getSumOfInts, getVarianceMethods inherited from interface CountRequestable
getCount, getCountOfMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface IterableArrayProvider
toArray, toByteArray, toCharArray, toDoubleArray, toIntArray, toLongArray, toStringArrayMethods inherited from interface IterableByExtremumProvider
getStoredByMax, getStoredByMinMethods inherited from interface IterableContainAnyRequestable
containsAny, containsNonNull, containsOne, containsOneNoneNull, isEmptyMethods inherited from interface IterableContainEqualRequestable
containsEqual, containsNoEqual, containsOneEqualMethods inherited from interface IterableContainMatchingRequestable
containsMatching, containsMatchingOnly, containsNoMatching, containsOneMatchingMethods inherited from interface IterableContainMultipleRequestable
containsAll, containsAll, containsAny, containsAny, containsExactlyAllEqualInSameOrder, containsExactlyInSameOrder, containsNone, containsNoneMethods inherited from interface IterableContainObjectRequestable
contains, containsOnce, containsOnlyMethods inherited from interface IterableFilterProvider
getStoredOfType, getStoredOthers, getStoredSelectedMethods inherited from interface IterableFilterViewProvider
getViewOfStoredSelectedMethods inherited from interface IterableFirstProvider
getOptionalStoredFirst, getOptionalStoredFirst, getStoredFirst, getStoredFirst, getStoredFirstNonNull, getStoredFirstOfTypeMethods inherited from interface IterableGroupProvider
getStoredInGroupsMethods inherited from interface IterableIntervalViewProvider
getViewFromOneBasedStartIndex, getViewFromOneBasedStartIndexToOneBasedEndIndex, getViewToOneBasedEndIndex, getViewWithoutFirst, getViewWithoutFirst, getViewWithoutLast, getViewWithoutLastMethods inherited from interface IterableLastProvider
getStoredLastMethods inherited from interface IterableMappedProvider
to, toMultiples, toNumbers, toStrings, toWithOneBasedIndexMethods inherited from interface IterableMappedViewProvider
getViewOfMethods inherited from interface IterableOneBasedIndexRequestable
getOneBasedIndexOfFirst, getOneBasedIndexOfFirstEqualElement, getOneBasedIndexOfFirstOccurrenceOfMethods inherited from interface IterableOrderProvider
toOrdered, toReversedMethods inherited from interface IterableStringProvider
toConcatenatedString, toStringWithDelimiter, toStringWithDelimiterMethods inherited from interface MaterializationRequestable
isViewMethods inherited from interface SingleProvider
getStoredSingle, getStoredSingle
-
Method Details
-
createEmpty
- Type Parameters:
T- the type of the elements of the createdMutableMatrix.- Returns:
- a new empty
MutableMatrix
-
fromMatrix
- Type Parameters:
T- the type of the elements of the given matrix- Parameters:
matrix-- Returns:
- a new
MutableMatrixwith the size and elements of the given matrix.
-
addColumn
Adds a new column to the currentMutableMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMutableMatrixcontains m elements. -n elements are given.- Parameters:
elements-- Returns:
- the current
MutableMatrix - Throws:
RuntimeException- if the given elements is nullRuntimeException- if one of the given elements is nullUnequalArgumentException- if the currentMutableMatrixis not empty or not as many elements are given as the number of rows of the currentMutableMatrix.
-
addColumn
Adds a new column to the currentMutableMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMutableMatrixcontains m elements. -n elements are given.- Parameters:
elements-- Returns:
- the current
MutableMatrix - Throws:
RuntimeException- if the given elements is nullRuntimeException- if one of the given elements is nullUnequalArgumentException- if the currentMutableMatrixis not empty and if not as many elements are given as the number of rows of the currentMutableMatrix.
-
addRow
Adds a new row to the currentMutableMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMutableMatrixcontains m rows. -n elements are given.- Parameters:
elements-- Returns:
- the current
MutableMatrix - Throws:
RuntimeException- if the given elements is nullRuntimeException- if one of the given elements is nullUnequalArgumentException- the currentMutableMatrixis not empty and if not as many elements are given as the number of columns of the currentMutableMatrix.
-
addRow
Adds a new row to the currentMutableMatrixwith the given elements. The complexity of this implementation is O(m + n) if: -The currentMutableMatrixcontains m rows. -n elements are given.- Parameters:
elements-- Returns:
- the current
MutableMatrix - Throws:
RuntimeException- if the given elements is nullRuntimeException- if one of the given elements is nullUnequalArgumentException- the currentMutableMatrixis not empty and if not as many elements are given as the number of columns of the currentMutableMatrix.
-
clear
public void clear()Removes all elements of the currentMutableMatrix. The complexity of this implementation is O(1). -
getColumn
- Parameters:
oneBasedColumnIndex-- Returns:
- the column of the current
MutableMatrixat the given oneBasedColumnIndex - Throws:
RuntimeException- if the given oneBasedColumnIndex is not positive or bigger than the number of the columns of the currentMutableMatrix.
-
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
MutableMatrix.
-
getColumnIndexOf
public int getColumnIndexOf(int index) - Parameters:
index-- Returns:
- the index of the column of the element of the current
MutableMatrixat the given index - Throws:
RuntimeException- if the given index is not positiveRuntimeException- if the given index is bigger than the number of elements of the currentMutableMatrix.
-
getColumns
- Specified by:
getColumnsin interfaceIMatrix<E>- Returns:
- the columns of the current
MutableMatrix.
-
getCopy
The time complexity of this implementation is O(m * n) if: -This matrix contains m rows. -This matrix contains n columns.- Returns:
- a new
MutableMatrixwith the elements of the currentMutableMatrix.
-
getCount
public int getCount()The time complexity of this implementation is O(1).- Specified by:
getCountin interfaceBaseCountRequestable- Returns:
- the number of elements of the current
MutableMatrix.
-
getIndexOf
public int getIndexOf(int rowIndex, int columnIndex) - Parameters:
rowIndex-columnIndex-- Returns:
- the index of the element of the current
MutableMatrixat the given row index and column index - Throws:
RuntimeException- if the given row index is not positiveRuntimeException- if the given row index is bigger than the number of rows of the currentMutableMatrixRuntimeException- if the given column index is not positiveRuntimeException- if the given column index is bigger than the number of columns of the currentMutableMatrix.
-
getStoredAtOneBasedIndex
- Specified by:
getStoredAtOneBasedIndexin interfaceIterableByIndexProvider<E>- Parameters:
oneBasedIndex-- Returns:
- the element of the current
MutableMatrixat the given index - Throws:
RuntimeException- if the given index is not positiveRuntimeException- if the given index is bigger than the number of elements of the currentMutableMatrix.
-
getStoredAtOneBasedRowIndexAndColumnIndex
The time complexity of this implementation is O(1).- Specified by:
getStoredAtOneBasedRowIndexAndColumnIndexin interfaceIMatrix<E>- Parameters:
oneBasedRowIndex-oneBasedColumnIndex-- Returns:
- the element of the current
MutableMatrixat the given row index and column index - Throws:
RuntimeException- if the given row index is not positiveRuntimeException- if the given row index is bigger than the number of rows of the currentMutableMatrixRuntimeException- if the given column index is not positiveRuntimeException- if the given column index is bigger than the number of columns of the currentMutableMatrix.
-
getRow
- Parameters:
oneBasedRowIndex-- Returns:
- the row of the current
MutableMatrixat the given oneBasedRowIndex - Throws:
RuntimeException- if the given oneBasedRowIndex is not positive or bigger than the number of rows of the currentMutableMatrix.
-
getRowIndexOf
public int getRowIndexOf(int index) - Parameters:
index-- Returns:
- the index of the row of the element of the current
MutableMatrixat the given index - Throws:
RuntimeException- if the given index is not positiveRuntimeException- if the given index is bigger than the number of elements of the currentMutableMatrix.
-
getRows
- Specified by:
getRowsin interfaceIMatrix<E>- Returns:
- the rows of the current
MutableMatrix.
-
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
MutableMatrix.
-
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).- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceIterableWithCopyableIterator<E>- Returns:
- a new iterator for the current
MutableMatrix.
-
setAt
Sets the given element to the currentMutableMatrixat the given index. The complexity of this implementation is O(1).- Parameters:
index-element-- Throws:
RuntimeException- if the given index is not positiveRuntimeException- if the given index is bigger than the number of elements of the currentMutableMatrixRuntimeException- if the given element is null
-
setAtOneBasedRowIndexAndColumnIndex
public void setAtOneBasedRowIndexAndColumnIndex(int oneBasedRowIndex, int oneBasedColumnIndex, E element) Sets the given element to the currentMutableMatrixto 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 positiveRuntimeException- if the given row index is bigger than the number of rows of the currentMutableMatrixRuntimeException- if the given column index is not positiveRuntimeException- if the given column index is bigger than the number of columns of the currentMutableMatrixRuntimeException- 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- 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
MutableMatrix.
-
toLeftRotatedMatrix
The time complexity of this implementation is O(n) if the currentMutableMatrixcontains n elements.- Returns:
- a new left rotated
MutableMatrixof the currentMutableMatrix.
-
toRightRotatedMatrix
The time complexity of this implementation is O(n) if the currentMutableMatrixcontains n elements.- Returns:
- a new right rotated
MutableMatrixof the currentMutableMatrix.
-
toString
The time complexity of this implementation is O(n) if: -The currentMutableMatrixcontains n elements. -The toString method of the elements of the currentMutableMatrixhas a complexity of O(1).- Overrides:
toStringin classObject- Returns:
- a
Stringrepresentation of the currentMutableMatrix.
-