本文整理汇总了Java中io.vavr.control.Try.success方法的典型用法代码示例。如果您正苦于以下问题:Java Try.success方法的具体用法?Java Try.success怎么用?Java Try.success使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vavr.control.Try
的用法示例。
在下文中一共展示了Try.success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSortColumnIdentity
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Validates that all the columns specified in the collection of items
* to sort are actually contained and identifiable in the DataTable.
*
* @param table The table to sort.
* @param sortItems The collection of sort items.
* @return Returns validation as a Try.
*/
private static Try<Seq<IDataColumn>> validateSortColumnIdentity(DataTable table, Seq<SortItem> sortItems) {
// Validate we can get the column for all sort items.
Seq<Try<IDataColumn>> checkCols = sortItems.map(item -> item.getColumn(table));
// Any failures, return error else return columns.
return checkCols.find(Try::isFailure).isEmpty()
? Try.success(checkCols.map(Try::get))
: DataTableException.tryError("Column for Sort Item not found.");
}
示例2: validateColumnsAreComparable
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Validates that all the columns being sorted are comparable.
*
* @param columns The columns to sort.
* @return Returns the result as a Try : Success / Failure.
*/
private static Try<Void> validateColumnsAreComparable(Seq<IDataColumn> columns) {
Option<IDataColumn> invalidCol = columns.find(col -> !col.IsComparable());
return invalidCol.isEmpty()
? Try.success(null)
: DataTableException.tryError("Column '" + invalidCol.get().name() + "' doesn't support comparable.");
}
示例3: build
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Builds an instance of a DataRow.
* Row Index is validated before creation, returning a Failure on error.
*
* @param table The DataTable the DataRow is pointing to.
* @param rowIdx The row index.
* @return Returns a DataRow wrapped in a Try.
*/
public static Try<DataRow> build(DataTable table, Integer rowIdx) {
Guard.notNull(table, "table");
// Check row index bounds, and return new DataRow if success.
return VectorExtensions.outOfBounds(table.rowCount(), rowIdx)
? DataTableException.tryError("Invalid row index for DataRow.")
: Try.success(new DataRow(table, rowIdx));
}
示例4: value
import io.vavr.control.Try; //导入方法依赖的package包/类
@Override
public final Try<T> value() {
List<Try<X>> outcomes = results.map(Result::value);
if (!outcomes.filter(Try::isFailure).isEmpty()) {
return Try.failure(
new RuntimeException(
String.join("\r\n", issues())
)
);
}
return Try.success(
outcomes.map(Try::get).transform(transformFunction)
);
}
示例5: tryGetAs
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Returns the value of a particular row column as a specific type.
* This method performs bounds checks and type checks. Any errors
* will return a Try.failure.
*
* @param type The data type.
* @param idx The index of the column.
* @param <T> The value type.
* @return Returns the value at the specified index.
*/
public <T> Try<T> tryGetAs(Class<T> type, Integer idx) {
// Get the column as it's typed version.
Try<DataColumn<T>> col = this.table.columns()
.tryGet(idx)
.flatMap(c -> c.asType(type));
return col.isFailure()
? Try.failure(col.getCause())
: Try.success(col.get().valueAt(this.rowIdx));
}
示例6: value
import io.vavr.control.Try; //导入方法依赖的package包/类
@Override
public final Try<T> value() {
return Try.success(value);
}
示例7: validateDataRows
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Validates the passed data rows belong to the passed table.
* @param dataRows The Data Rows to check.
* @return Returns a Success or Failure.
*/
private static Try<Void> validateDataRows(DataTable table, Iterable<DataRow> dataRows) {
return List.ofAll(dataRows).forAll(row -> row.table() == table)
? Try.success(null)
: DataTableException.tryError("DataRows do not all belong to the specified table.");
}
示例8: columnToValue
import io.vavr.control.Try; //导入方法依赖的package包/类
private Try<Object> columnToValue(Try<IDataColumn> column) {
return column.isSuccess()
? Try.success(column.get().valueAt(this.rowIdx))
: Try.failure(column.getCause());
}
示例9: tryCast
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Used to perform a type check and cast on an object instance.
* Returns a Try success or failure depending on if it was valid cast.
*
* @param <T> The type to return.
* @param type The type to cast to.
* @param obj The object to cast.
* @return Returns a Success<T> or a Failure.
*/
@SuppressWarnings({"unchecked"})
static <T> Try<T> tryCast(Class<T> type, Object obj) {
return type.isInstance(obj)
? Try.success((T)obj)
: Try.failure(new DataTableException("Invalid cast."));
}
示例10: asType
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Returns the generic data column as it's typed implementation.
* If the types don't match, then it'll return Failure.
*
* @param type The type of the column.
* @param <V> The type.
* @return Returns the typed Data Column wrapped in a Try.
*/
@Override
@SuppressWarnings("unchecked")
public <V> Try<DataColumn<V>> asType(Class<V> type) {
return this.type == type
? Try.success((DataColumn<V>)this)
: DataTableException.tryError("Column type doesn't match type requested.");
}
示例11: tryNotNull
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Asserts the argument is not null. Returns in a Try.
*
* @param <T> The argument type.
* @param argument The argument to check.
* @param name The name of the argument.
* @return Returns a Try testing the argument being null.
*/
public static <T> Try<T> tryNotNull(T argument, String name) {
return argument == null
? Try.failure(new IllegalArgumentException("Invalid value [NULL] for argument " + name))
: Try.success(argument);
}
示例12: validateColumnNames
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Validates there are no duplicate columns names.
*
* @param columns The columns to check.
* @return Returns a Success or Failure.
*/
private static Try<Seq<IDataColumn>> validateColumnNames(Seq<IDataColumn> columns) {
return columns.groupBy(IDataColumn::name).length() != columns.length()
? DataTableException.tryError("Columns contain duplicate names.")
: Try.success(columns);
}
示例13: insertItem
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Inserts a new item into the vector, with additional bounds check.
*
* @param vector The vector to insert the item into.
* @param index The index to insert the item at.
* @param item The item to insert.
* @param <T> The vector type.
* @return Returns the new vector with the item inserted.
*/
public static <T> Try<Vector<T>> insertItem(Vector<T> vector, Integer index, T item) {
return outOfBounds(vector, index)
? error("Item index out of bounds for insert.")
: Try.success(vector.insert(index, item));
}
示例14: removeItem
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* Removes an item from the vector, with additional bounds check.
*
* @param vector The vector to remove the item from.
* @param index The index to remove the item at.
* @param <T> The vector type.
* @return Returns the new vector with the item removed.
*/
public static <T> Try<Vector<T>> removeItem(Vector<T> vector, Integer index) {
return outOfBounds(vector, index)
? error("Item index out of bounds for remove.")
: Try.success(vector.removeAt(index));
}
示例15: replaceItem
import io.vavr.control.Try; //导入方法依赖的package包/类
/**
* 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));
}