Java Code Examples for io.vavr.control.Option#isEmpty()

The following examples show how to use io.vavr.control.Option#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagWriteProtocol.java    From ts-reaktive with MIT License 6 votes vote down vote up
/**
 * @param name The qualified name of the tag to write, or none() to have the last item of [getters] deliver a {@link QName}.
 * @param getters Getter function for each sub-protocol to write (and additional first element delivering a QName, if name == none())
 * @param protocols Protocols to use to write each of the getter elements
 */
public TagWriteProtocol(Option<QName> name, Vector<? extends WriteProtocol<XMLEvent,?>> protocols, Vector<Function1<T, ?>> g) {
    if (name.isDefined() && (protocols.size() != g.size()) ||
        name.isEmpty() && (protocols.size() != g.size() - 1)) {
        throw new IllegalArgumentException ("Number of protocols and getters does not match");
    }
    this.name = name;
    this.getName = t -> name.getOrElse(() -> (QName) g.head().apply(t));
    
    Vector<Function1<T, ?>> getters = (name.isEmpty()) ? g.drop(1) : g;
    
    Tuple2<Vector<Tuple2<WriteProtocol<XMLEvent,?>, Function1<T, ?>>>, Vector<Tuple2<WriteProtocol<XMLEvent,?>, Function1<T, ?>>>> partition =
        ((Vector<WriteProtocol<XMLEvent,?>>)protocols).zip(getters)
        .partition(t -> Attribute.class.isAssignableFrom(t._1.getEventType()));
    
    this.attrProtocols = partition._1().map(t -> t._1());
    this.attrGetters = partition._1().map(t -> t._2());
    this.otherProtocols = partition._2().map(t -> t._1());
    this.otherGetters = partition._2().map(t -> t._2());
}
 
Example 2
Source File: Patron.java    From library with MIT License 5 votes vote down vote up
public Either<BookHoldFailed, BookPlacedOnHoldEvents> placeOnHold(AvailableBook aBook, HoldDuration duration) {
    Option<Rejection> rejection = patronCanHold(aBook, duration);
    if (rejection.isEmpty()) {
        BookPlacedOnHold bookPlacedOnHold = bookPlacedOnHoldNow(aBook.getBookId(), aBook.type(), aBook.getLibraryBranch(), patron.getPatronId(), duration);
        if (patronHolds.maximumHoldsAfterHolding(aBook)) {
            return announceSuccess(events(bookPlacedOnHold, MaximumNumberOhHoldsReached.now(patron, MAX_NUMBER_OF_HOLDS)));
        }
        return announceSuccess(events(bookPlacedOnHold));
    }
    return announceFailure(bookHoldFailedNow(rejection.get(), aBook.getBookId(), aBook.getLibraryBranch(), patron));
}
 
Example 3
Source File: DataSort.java    From java-datatable with Apache License 2.0 5 votes vote down vote up
/**
 * 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.");
}
 
Example 4
Source File: AbstractCommandResultsAssert.java    From ts-reaktive with MIT License 5 votes vote down vote up
/**
 * Asserts there is a validation error and returns it, casting it to the given type.
 * Useful for subclasses for concrete Results implementations that have a fixed message type.
 */
protected <M> M validationError(Class<M> type) {
    Option<Object> err = actual.getValidationError(0);
    if (err.isEmpty()) {
        throwAssertionError(new BasicErrorMessageFactory("Expected a Result with validation errors, but instead was %s",
            actualToString()));
    }
    return type.cast(err.get());
}
 
Example 5
Source File: MaterializerWorkers.java    From ts-reaktive with MIT License 4 votes vote down vote up
private static long earliest(long a, Option<Instant> b) {
    return (b.isEmpty() || a < b.get().toEpochMilli()) ? a : b.get().toEpochMilli();
}
 
Example 6
Source File: OptionSerializer.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isEmpty(SerializerProvider provider, Option<?> value) {
    return value.isEmpty();
}