Java Code Examples for io.vavr.collection.Vector#empty()

The following examples show how to use io.vavr.collection.Vector#empty() . 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: ValueProtocol.java    From ts-reaktive with MIT License 6 votes vote down vote up
@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();
        }
    };
}
 
Example 2
Source File: NamedColumnWriteProtocol.java    From ts-reaktive with MIT License 6 votes vote down vote up
@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();
            }
        }
    };
}
 
Example 3
Source File: Writer.java    From ts-reaktive with MIT License 5 votes vote down vote up
/**
 * Returns a writer that emits an event for every element, the event being the element itself.
 */
public static <E, T extends E> Writer<E,T> identity() {
    return new Writer<E,T>() {
        @Override
        public Seq<E> apply(T value) {
            return Vector.of(value);
        }
        
        @Override
        public Seq<E> reset() {
            return Vector.empty();
        }
    };
}
 
Example 4
Source File: Writer.java    From ts-reaktive with MIT License 5 votes vote down vote up
/**
 * Returns a Writer that calls the given function for apply(), and nothing for reset().
 */
public static <E,T> Writer<E,T> of (Function<T,Seq<E>> f) {
    return new Writer<E, T>() {
        @Override
        public Seq<E> apply(T value) {
            return f.apply(value);
        }

        @Override
        public Seq<E> reset() {
            return Vector.empty();
        }
    };
}
 
Example 5
Source File: TestEventClassifier.java    From ts-reaktive with MIT License 5 votes vote down vote up
@Override
public Seq<String> getDataCenterNames(TestEvent e) {
    if (e.getMsg().startsWith("dc:")) {
        return Vector.of(e.getMsg().substring(3));
    } else {
        return Vector.empty();
    }
}
 
Example 6
Source File: ObjectProtocol.java    From ts-reaktive with MIT License 5 votes vote down vote up
public ObjectProtocol(
    List<Protocol<JSONEvent, ?>> protocols,
    Function<List<?>, T> produce,
    List<Function1<T, ?>> getters
) {
    this.read = new ObjectReadProtocol<>(Vector.ofAll(protocols), produce, Vector.empty());
    this.write = new ObjectWriteProtocol<>(Vector.ofAll(protocols), getters, Vector.empty());
}
 
Example 7
Source File: ObjectReadProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
public ObjectReadProtocol(ReadProtocol<JSONEvent, T> inner) {
    this(Vector.of(inner), identity(), Vector.empty());
}
 
Example 8
Source File: XMLProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
/**
 * Writes a tag and with any name, getting values using [g1] for writing.
 */
public static <T> TagWriteProtocol<T> writeTagName(Function1<T,QName> g1) {
    return new TagWriteProtocol<>(Option.none(), Vector.empty(), Vector.of(g1));
}
 
Example 9
Source File: XMLProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
/**
 * Reads a tag with any name, creating its result using [f].
 */
public static <T> TagReadProtocol<T> readTagName(Function1<QName,T> f) {
    return new TagReadProtocol<>(Option.none(), Vector.empty(), args -> f.apply((QName) args.get(0)));
}
 
Example 10
Source File: XMLProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
/**
 * Reads and writes a tag with any name, using [f] to create the result on reading, getting values using [g1] for writing.
 */
public static <T> TagProtocol<T> tagName(Function1<QName,T> f, Function1<T,QName> g1) {
    return new TagProtocol<>(Option.none(), Vector.empty(), args -> f.apply((QName) args.get(0)), Vector.of(g1));
}
 
Example 11
Source File: Schema.java    From paleo with Apache License 2.0 4 votes vote down vote up
private static Vector<Field> safeFields(FieldList fields) {
    return fields == null ? Vector.empty() : Vector.ofAll(fields);
}
 
Example 12
Source File: TagReadProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
/**
 * Reads a tag and one child element (tag or attribute), where the result of this tag is the result of the single child.
 */
public TagReadProtocol(Option<QName> name, ReadProtocol<XMLEvent,?> protocol) {
    this(name, Vector.of(protocol), identity(), Vector.empty());
}
 
Example 13
Source File: ObjectReadProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
public ObjectReadProtocol(
    List<ReadProtocol<JSONEvent, ?>> protocols,
    Function<List<?>, T> produce
) {
    this(Vector.ofAll(protocols), produce, Vector.empty());
}
 
Example 14
Source File: ObjectWriteProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
public ObjectWriteProtocol(WriteProtocol<JSONEvent, T> inner) {
    this(Vector.of((WriteProtocol<JSONEvent, ?>)inner), Arrays.asList(Function1.identity()), Vector.empty());
}
 
Example 15
Source File: ObjectWriteProtocol.java    From ts-reaktive with MIT License 4 votes vote down vote up
public ObjectWriteProtocol(
    List<WriteProtocol<JSONEvent, ?>> protocols,
    List<Function1<T, ?>> getters
) {
    this(Vector.ofAll(protocols), getters, Vector.empty());
}
 
Example 16
Source File: GroupWhile.java    From ts-reaktive with MIT License 4 votes vote down vote up
@Override
public GraphStageLogic createLogic(Attributes inheritedAttributes) {
    return new TimerGraphStageLogic(shape) {
        Seq<T> buffer = Vector.empty();

        {
            setHandler(in, new AbstractInHandler() {
                @Override
                public void onPush() {
                    T t = grab(in);

                    if (buffer.isEmpty() || test.apply(buffer.get(buffer.size() - 1), t)) {
                        buffer = buffer.append(t);
                        scheduleOnce("idle", idleEmitTimeout);
                        pull(in);
                    } else {
                        emitBuffer();
                        scheduleOnce("idle", idleEmitTimeout);
                        buffer = buffer.append(t);
                    }
                    if (buffer.size() > maxGroupSize) {
                        failStage(new BufferOverflowException("Exceeded configured GroupWhile buffer size of " + maxGroupSize));
                        return;
                    }
                }

                @Override
                public void onUpstreamFinish() {
                    emitBuffer();
                    completeStage();
                }
            });

            setHandler(out, new AbstractOutHandler() {
                @Override
                public void onPull() {
                    if (!hasBeenPulled(in)) {
                        pull(in);
                    }
                }
            });
        }

        private void emitBuffer() {
            if (!buffer.isEmpty() && isAvailable(out)) {
                emit(out, buffer);
                buffer = Vector.empty();
                cancelTimer("idle");
            }
        }

        @Override
        public void onTimer(Object timerKey) {
            log.debug("Idle timeout reached with {} elements waiting", buffer.size());
            emitBuffer();
        }
    };
}
 
Example 17
Source File: MaterializerWorkers.java    From ts-reaktive with MIT License 4 votes vote down vote up
public static MaterializerWorkers empty(TemporalAmount rollback) {
    return new MaterializerWorkers(Vector.empty(), rollback);
}
 
Example 18
Source File: TagReadProtocol.java    From ts-reaktive with MIT License 2 votes vote down vote up
/**
 * Creates a new TagReadProtocol
 * @param name Name of the tag to match, or none() to match any tag ([produce] will get another argument (at position 0) with the tag's QName in that case)
 * @param protocols Attributes and child tags to read
 * @param produce Function that must accept a list of (attributes.size + tags.size) objects and turn that into T
 */
public TagReadProtocol(Option<QName> name, Vector<? extends ReadProtocol<XMLEvent,?>> protocols, Function<List<?>, T> produce) {
    this(name, protocols, produce, Vector.empty());
}
 
Example 19
Source File: DataColumn.java    From java-datatable with Apache License 2.0 2 votes vote down vote up
/**
 * DataColumn constructor.
 *
 * @param type Stores the type of data stored in this column.
 * @param columnName The column name.
 */
public DataColumn(Class<T> type, String columnName) {
    this(type, columnName, Vector.empty());
}
 
Example 20
Source File: CommandHandler.java    From ts-reaktive with MIT License 2 votes vote down vote up
/**
 * Returns the events to be emitted as a result of applying the command. 
 * 
 * By default, no events are emitted (which is appropriate for read-only commands).
 */
default public Seq<E> getEventsToEmit() {
    return Vector.empty();
}