Class VectorExtensions
java.lang.Object
com.github.martincooper.datatable.VectorExtensions
VectorExtensions class.
Helper methods for add, insert, update and remove with bounds checking.
Created by Martin Cooper on 16/07/2017.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> io.vavr.control.Try<io.vavr.collection.Vector<T>>addItem(io.vavr.collection.Vector<T> vector, T item) Adds - Appends a new item to the end of the vector.static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>>insertItem(io.vavr.collection.Vector<T> vector, Integer index, T item) Inserts a new item into the vector, with additional bounds check.static booleanoutOfBounds(io.vavr.collection.Vector vector, Integer index) Checks if the specified parameters are out of bounds.static booleanoutOfBounds(Integer itemCount, Integer index) Checks if the specified parameters are out of bounds.static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>>removeItem(io.vavr.collection.Vector<T> vector, Integer index) Removes an item from the vector, with additional bounds check.static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>>replaceItem(io.vavr.collection.Vector<T> vector, Integer index, T item) Replaces - Updates an item in the vector, with additional bounds check.
-
Constructor Details
-
VectorExtensions
public VectorExtensions()
-
-
Method Details
-
addItem
public static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>> addItem(io.vavr.collection.Vector<T> vector, T item) Adds - Appends a new item to the end of the vector.- Type Parameters:
T- The vector type.- Parameters:
vector- The vector to add the item to.item- The item to add.- Returns:
- Returns the new vector with the item added.
-
insertItem
public static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>> insertItem(io.vavr.collection.Vector<T> vector, Integer index, T item) Inserts a new item into the vector, with additional bounds check.- Type Parameters:
T- The vector type.- Parameters:
vector- The vector to insert the item into.index- The index to insert the item at.item- The item to insert.- Returns:
- Returns the new vector with the item inserted.
-
removeItem
public static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>> removeItem(io.vavr.collection.Vector<T> vector, Integer index) Removes an item from the vector, with additional bounds check.- Type Parameters:
T- The vector type.- Parameters:
vector- The vector to remove the item from.index- The index to remove the item at.- Returns:
- Returns the new vector with the item removed.
-
replaceItem
public static <T> io.vavr.control.Try<io.vavr.collection.Vector<T>> replaceItem(io.vavr.collection.Vector<T> vector, Integer index, T item) Replaces - Updates an item in the vector, with additional bounds check.- Type Parameters:
T- The vector type.- Parameters:
vector- The vector to replace the item in.index- The index of the item to replace.item- The new item.- Returns:
- Returns the new vector with the item replaced.
-
outOfBounds
Checks if the specified parameters are out of bounds.- Parameters:
vector- The vector to check.index- The required index.- Returns:
- Returns true if it's out of bounds.
-
outOfBounds
Checks if the specified parameters are out of bounds.- Parameters:
itemCount- The item count in the collection.index- The required index.- Returns:
- Returns true if it's out of bounds.
-