本文整理汇总了Java中io.vavr.collection.Seq类的典型用法代码示例。如果您正苦于以下问题:Java Seq类的具体用法?Java Seq怎么用?Java Seq使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Seq类属于io.vavr.collection包,在下文中一共展示了Seq类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import io.vavr.collection.Seq; //导入依赖的package包/类
static Validation<String, MonthSpec> parse(String cronSpec) {
Function1<Integer, Validation<String, Month>> parseMonth = item ->
Try.of(() -> Month.of(item))
.toValidation(String.format("Invalid month: %d", item));
return SpecItemParser.parseSpecItem(cronSpec.toLowerCase(), 12, monthMap)
.flatMap(intSet -> Vavr.sequenceS(intSet.map(parseMonth)))
.map(Seq::toSet)
.flatMap(MonthSpec::build);
}
示例2: writer
import io.vavr.collection.Seq; //导入依赖的package包/类
@Override
public Writer<CsvEvent, String> writer() {
return new Writer<CsvEvent, String>() {
@Override
public Seq<CsvEvent> apply(String value) {
if (value.isEmpty()) {
return Vector.empty();
} else {
return Vector.of(CsvEvent.text(value));
}
}
@Override
public Seq<CsvEvent> reset() {
return Vector.empty();
}
};
}
示例3: writer
import io.vavr.collection.Seq; //导入依赖的package包/类
@Override
public Writer<CsvEvent, T> writer() {
Writer<CsvEvent, T> innerWriter = inner.writer();
return new Writer<CsvEvent, T>() {
boolean first = true;
@Override
public Seq<CsvEvent> apply(T value) {
Seq<CsvEvent> events =
(first) ? Vector.of(CsvEvent.text(name), CsvEvent.endValue(), CsvEvent.endRecord()) : Vector.empty();
first = false;
return events.appendAll(innerWriter.apply(value)).append(CsvEvent.endValue()).append(CsvEvent.endRecord());
}
@Override
public Seq<CsvEvent> reset() {
if (first) {
first = false;
return Vector.of(CsvEvent.text(name), CsvEvent.endValue(), CsvEvent.endRecord());
} else {
return Vector.empty();
}
}
};
}
示例4: readWrite
import io.vavr.collection.Seq; //导入依赖的package包/类
/**
* Returns a Protocol that uses an AlternativesProtocol for reading, and always picks the first alternative when writing.
*/
public static <E,T> Protocol<E,T> readWrite(Seq<Protocol<E,T>> alternatives) {
Protocol<E,T> write = alternatives.head();
AnyOfProtocol<E,T> read = new AnyOfProtocol<>(Seq.narrow(alternatives));
return new Protocol<E,T>() {
@Override
public Writer<E,T> writer() {
return write.writer();
}
@Override
public Class<? extends E> getEventType() {
return write.getEventType();
}
@Override
public Reader<E,T> reader() {
return read.reader();
}
};
}
示例5: set
import io.vavr.collection.Seq; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void set(Consumer<Object> dispatcher, Object node, String name, VProperty vProperty) {
if (! (node instanceof Node)) {
throw new IllegalStateException("Unable to read value of property styleClass from class " + node.getClass());
}
if (vProperty.isValueDefined()) {
final ObservableList<String> styleClasses = ((Node) node).getStyleClass();
styleClasses.retainAll(node.getClass().getSimpleName().toLowerCase());
if (vProperty.getValue() != null) {
styleClasses.addAll(((Seq) vProperty.getValue()).toJavaList());
}
}
}
示例6: create
import io.vavr.collection.Seq; //导入依赖的package包/类
@Override
Seq<?> create(List<Object> result, DeserializationContext ctxt) throws JsonMappingException {
if (Array.class.isAssignableFrom(javaType.getRawClass())) {
return Array.ofAll(result);
}
if (Queue.class.isAssignableFrom(javaType.getRawClass())) {
return Queue.ofAll(result);
}
if (Stream.class.isAssignableFrom(javaType.getRawClass())) {
return Stream.ofAll(result);
}
if (Vector.class.isAssignableFrom(javaType.getRawClass())) {
return Vector.ofAll(result);
}
// default deserialization [...] -> Seq
return io.vavr.collection.List.ofAll(result);
}
示例7: toDataTable
import io.vavr.collection.Seq; //导入依赖的package包/类
/**
* Return a new DataTable based on this table (clone).
*
* @return Returns a new DataTable based on the columns and data in this view.
*/
@Override
public DataTable toDataTable() {
// Get the list of row indexes used in this data view.
Seq<Integer> rowIndexes = this.rows.map(DataRow::rowIdx);
// Build a set of new columns with just the data at the specified indexes.
return this.table.columns()
.map(col -> col.buildFromRows(rowIndexes).get())
.collect(transform(cols -> DataTable.build(this.name(), cols).get()));
}
示例8: validateSortColumnIdentity
import io.vavr.collection.Seq; //导入依赖的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.");
}
示例9: validateColumnsAreComparable
import io.vavr.collection.Seq; //导入依赖的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.");
}
示例10: compareBySortItem
import io.vavr.collection.Seq; //导入依赖的package包/类
/**
* Recursive sort method, handles multi-sort on columns.
*
* @param rowOne The first row to compare.
* @param rowTwo The second row to compare.
* @param sortItems The collection of Sort Item details.
* @return Returns a single integer for the sort.
*/
private static int compareBySortItem(DataRow rowOne, DataRow rowTwo, Seq<SortItem> sortItems) {
// No more items to sort, then return 0;
if (sortItems.isEmpty()) return 0;
// Compare the values in the two rows for the current sort item.
Integer compareResult = compareValues(rowOne, rowTwo, sortItems.head());
// If it's the same, then compare again on the next item until finished.
return compareResult == 0
? compareBySortItem(rowOne, rowTwo, sortItems.tail())
: compareResult;
}
示例11: parse
import io.vavr.collection.Seq; //导入依赖的package包/类
static Validation<String, DayOfWeekSpec> parse(String cronSpec) {
Function1<Integer, Validation<String, DayOfWeek>> parseDow = item ->
Try.of(() -> item == 0 ? DayOfWeek.SUNDAY : DayOfWeek.of(item))
.toValidation(String.format("Invalid day of week: %d", item));
return SpecItemParser.parseSpecItem(cronSpec.toLowerCase(), 7, dayMap)
.flatMap(intSet -> Vavr.sequenceS(intSet.map(parseDow)))
.map(Seq::toSet)
.flatMap(DayOfWeekSpec::build);
}
示例12: handleCommand
import io.vavr.collection.Seq; //导入依赖的package包/类
/**
* Executes the given command using the given handler, emitting any events, and responding to sender().
*/
protected void handleCommand(C cmd, AbstractCommandHandler<C, E, S> handler) {
Option<Object> error = handler.getValidationError(lastSequenceNr());
if (error.isDefined()) {
log.debug(" invalid: {}", error.get());
sender().tell(error.get(), self());
} else if (handler.isAlreadyApplied()) {
log.debug(" was already applied.");
sender().tell(handler.getIdempotentReply(lastSequenceNr()), self());
} else {
Seq<E> events = handler.getEventsToEmit();
log.debug(" emitting {}", events);
if (events.isEmpty()) {
sender().tell(handler.getReply(events, lastSequenceNr()), self());
} else {
if (lastSequenceNr() == 0) {
validateFirstEvent(events.head());
}
AtomicInteger need = new AtomicInteger(events.size());
persistAllEvents(events, evt -> {
if (need.decrementAndGet() == 0) {
sender().tell(handler.getReply(events, lastSequenceNr()), self());
}
});
}
}
}
示例13: getDataCenterNames
import io.vavr.collection.Seq; //导入依赖的package包/类
@Override
public Seq<String> getDataCenterNames(TestEvent e) {
if (e.getMsg().startsWith("dc:")) {
return Vector.of(e.getMsg().substring(3));
} else {
return Vector.empty();
}
}
示例14: store
import io.vavr.collection.Seq; //导入依赖的package包/类
/**
* Stores the given buffered events into S3, under a key that includes the tag and the offset of the first event.
* @param tag Persistence tag that the events were for
*/
public CompletionStage<Done> store(String tag, Seq<EventEnvelope> events) {
String key = tag + SEPARATOR + FMT.format(Instant.ofEpochMilli(UUIDs.unixTimestamp(TimeBasedUUID.class.cast(events.get(0).offset()).value())));
return Source.from(events)
.map(e -> {
ByteStringBuilder b = new ByteStringBuilder();
serializer.toProtobuf(e).writeDelimitedTo(b.asOutputStream());
return b.result();
})
.runWith(upload(key), materializer)
.thenApply(result -> {
log.info("Uploaded to {} with etag {}", result.key(), result.etag());
return Done.getInstance();
});
}
示例15: ObjectWriteProtocol
import io.vavr.collection.Seq; //导入依赖的package包/类
ObjectWriteProtocol(
Seq<WriteProtocol<JSONEvent, ?>> protocols,
List<Function1<T, ?>> getters,
Seq<WriteProtocol<JSONEvent, ConstantProtocol.Present>> conditions
) {
this.protocols = protocols;
this.getters = getters;
this.conditions = conditions;
if (protocols.size() != getters.size()) {
throw new IllegalArgumentException("protocols must match getters");
}
}