@Override public Vector<T> replaceAll(T currentElement, T newElement) { Vector<T> result = this; int index = 0; for (T value : iterator()) { if (Objects.equals(value, currentElement)) { result = result.update(index, newElement); } index++; } return result; }
@Override public Vector<T> update(int index, Function<? super T, ? extends T> updater) { Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); }
@Override public Vector<T> replace(T currentElement, T newElement) { return indexOfOption(currentElement) .map(i -> update(i, newElement)) .getOrElse(this); }
@Override public Vector<T> update(int index, Function<? super T, ? extends T> updater) { Objects.requireNonNull(updater, "updater is null"); return update(index, updater.apply(get(index))); }
@Override public Vector<T> replaceAll(T currentElement, T newElement) { Vector<T> result = this; int index = 0; for (T value : iterator()) { if (Objects.equals(value, currentElement)) { result = result.update(index, newElement); } index++; } return result; }
/** * Replaces the existing item at the specified index with the new item. * * @param index The index to replace the existing item. * @param value The new item to replace the existing one. * @return Returns a new DataColumn with the specified item replaced. */ public Try<DataColumn<T>> replaceItem(Integer index, T value) { return Try.of(() -> createColumn(this.data.update(index, value))); }
@Override public Vector<T> replace(T currentElement, T newElement) { return indexOfOption(currentElement) .map(i -> update(i, newElement)) .getOrElse(this); }
/** * Replaces - Updates an item in the vector, with additional bounds check. * * @param vector The vector to replace the item in. * @param index The index of the item to replace. * @param item The new item. * @param <T> The vector type. * @return Returns the new vector with the item replaced. */ public static <T> Try<Vector<T>> replaceItem(Vector<T> vector, Integer index, T item) { return outOfBounds(vector, index) ? error("Item index out of bounds for replace.") : Try.success(vector.update(index, item)); }
/** * Attempts to replace an existing item with a new item in the column. * A type check is performed before replacement. * * @param index The index the item is to be replaced at. * @param value The new item. * @return Returns a Success with the new modified DataColumn, or a Failure. */ @Override public Try<IDataColumn> replace(Integer index, Object value) { return Match(GenericExtensions.tryCast(this.type, value)).of( Case($Success($()), typedVal -> Try.of(() -> createColumn(this.data.update(index, typedVal)))), Case($Failure($()), DataTableException.tryError("tryReplace failed. Item of invalid type passed.")) ); }