Java Code Examples for io.vavr.collection.Vector#of()
The following examples show how to use
io.vavr.collection.Vector#of() .
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: MaterializerWorkers.java From ts-reaktive with MIT License | 6 votes |
/** Returns a new MaterializerWorkers where the single expected worker has progressed to the given timestamp */ public MaterializerWorkers applyEvent(long event) { if (workers.size() == 0) { return new MaterializerWorkers(Vector.of(Worker.newBuilder() .setId(toProtobuf(UUID.randomUUID())) .setTimestamp(event) .build()), rollback); } else if (workers.size() == 1) { return new MaterializerWorkers(Vector.of(workers.head().toBuilder() .setTimestamp(event) .build()), rollback); } else { throw new IllegalStateException("Encountered legacy Long event " + event + " AFTER having more than 1 worker: " + workers); } }
Example 2
Source File: NamedColumnWriteProtocol.java From ts-reaktive with MIT License | 6 votes |
@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: DataColumnTests.java From java-datatable with Apache License 2.0 | 5 votes |
@Test public void testVectorDataColumnCreation() { Vector<Integer> data = Vector.of(5, 7, 9); DataColumn<Integer> column = new DataColumn<>(Integer.class, "IntegerCol", data); assertEquals(column.data().length(), 3); assertTrue(column.data().get(1) == 7); }
Example 4
Source File: AbstractStatefulPersistentActorSpec.java From ts-reaktive with MIT License | 5 votes |
@Override public Results<MyEvent> handleSynchronously(MyState state, String cmd) { return new Results<MyEvent>() { @Override public Seq<MyEvent> getEventsToEmit() { return Vector.of(new MyEvent(cmd)); } @Override public Object getReply(Seq<MyEvent> emittedEvents, long lastSequenceNr) { return Done.getInstance(); } }; }
Example 5
Source File: Writer.java From ts-reaktive with MIT License | 5 votes |
/** * 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 6
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testVector() throws Exception { Vector<I> src = Vector.of(new A(), new B()); String json = MAPPER.writeValueAsString(new VectorPojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"type\":\"a\"},{\"type\":\"b\"}]}"); VectorPojo pojo = MAPPER.readValue(json, VectorPojo.class); Vector<I> restored = pojo.getValue(); Assertions.assertTrue(restored.get(0) instanceof A); Assertions.assertTrue(restored.get(1) instanceof B); }
Example 7
Source File: TagWriteProtocol.java From ts-reaktive with MIT License | 5 votes |
@Override public Writer<XMLEvent,T> writer() { return new Writer<XMLEvent, T>() { boolean started = false; private EndElement endElement; @Override public Seq<XMLEvent> apply(T value) { log.debug("{}: Writing {}", TagWriteProtocol.this, value); Seq<XMLEvent> prefix = (started) ? Vector.empty() : Vector.of(startElement(value)); started = true; endElement = factory.createEndElement(getName.apply(value), null); return prefix.appendAll( Vector.range(0, otherProtocols.size()).map(i -> { Writer<XMLEvent,Object> w = (Writer<XMLEvent,Object>) otherProtocols.get(i).writer(); return w.applyAndReset(otherGetters.get(i).apply(value)); }).flatMap(Function.identity()) ); } @Override public Seq<XMLEvent> reset() { log.debug("{}: Resetting", TagWriteProtocol.this); if (started) { started = false; return Vector.of(endElement); } else { return Vector.empty(); } } }; }
Example 8
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Writes a tag and child elements (tag or attribute) using [p*], getting values using [g*] for writing. */ public static <F1,F2,T> TagWriteProtocol<T> tag(QName qname, Function1<T,F1> g1, WriteProtocol<XMLEvent,F1> p1, Function1<T,F2> g2, WriteProtocol<XMLEvent,F2> p2) { return new TagWriteProtocol<>(Option.of(qname), Vector.of(p1, p2), Vector.of(g1, g2)); }
Example 9
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Reads and writes a tag and child elements (tag or attribute) using [p*], using [f] to create the result on reading, getting values using [g*] for writing. */ public static <F1,F2,F3,F4,F5,F6,T> TagProtocol<T> tag(QName qname, Protocol<XMLEvent,F1> p1, Protocol<XMLEvent,F2> p2, Protocol<XMLEvent,F3> p3, Protocol<XMLEvent,F4> p4, Protocol<XMLEvent,F5> p5, Protocol<XMLEvent,F6> p6, Function6<F1,F2,F3,F4,F5,F6,T> f, Function1<T,F1> g1, Function1<T,F2> g2, Function1<T,F3> g3, Function1<T,F4> g4, Function1<T,F5> g5, Function1<T,F6> g6) { return new TagProtocol<>(Option.of(qname), Vector.of(p1, p2, p3, p4, p5, p6), args -> f.apply((F1) args.get(0), (F2) args.get(1), (F3) args.get(2), (F4) args.get(3), (F5) args.get(4), (F6) args.get(5)), Vector.of(g1, g2, g3, g4, g5, g6)); }
Example 10
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Reads and writes a tag and one child element (tag or attribute) using [p1], using [f] to create the result on reading, getting values using [g1] for writing. */ public static <F1,T> TagProtocol<T> tag(QName qname, Protocol<XMLEvent,F1> p1, Function1<F1,T> f, Function1<T,F1> g1) { return new TagProtocol<>(Option.of(qname), Vector.of(p1), args -> f.apply((F1) args.get(0)), Vector.of(g1)); }
Example 11
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Writes a tag and one child element (tag or attribute), where the result of this tag is the result of the single child. */ public static <T> TagWriteProtocol<T> tag(QName name, WriteProtocol<XMLEvent,T> p1) { return new TagWriteProtocol<>(Option.of(name), Vector.of(p1), Vector.of(Function1.identity())); }
Example 12
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Writes a tag and child elements (tag or attribute) using [p*], getting values using [g*] for writing. */ public static <F1,F2,F3,F4,F5,T> TagWriteProtocol<T> tag(QName qname, Function1<T,F1> g1, WriteProtocol<XMLEvent,F1> p1, Function1<T,F2> g2, WriteProtocol<XMLEvent,F2> p2, Function1<T,F3> g3, WriteProtocol<XMLEvent,F3> p3, Function1<T,F4> g4, WriteProtocol<XMLEvent,F4> p4, Function1<T,F5> g5, WriteProtocol<XMLEvent,F5> p5) { return new TagWriteProtocol<>(Option.of(qname), Vector.of(p1, p2, p3, p4, p5), Vector.of(g1, g2, g3, g4, g5)); }
Example 13
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Writes a tag and child elements (tag or attribute) using [p*], getting values using [g*] for writing. */ public static <F1,F2,F3,F4,F5,F6,T> TagWriteProtocol<T> tag(QName qname, Function1<T,F1> g1, WriteProtocol<XMLEvent,F1> p1, Function1<T,F2> g2, WriteProtocol<XMLEvent,F2> p2, Function1<T,F3> g3, WriteProtocol<XMLEvent,F3> p3, Function1<T,F4> g4, WriteProtocol<XMLEvent,F4> p4, Function1<T,F5> g5, WriteProtocol<XMLEvent,F5> p5, Function1<T,F6> g6, WriteProtocol<XMLEvent,F6> p6) { return new TagWriteProtocol<>(Option.of(qname), Vector.of(p1, p2, p3, p4, p5, p6), Vector.of(g1, g2, g3, g4, g5, g6)); }
Example 14
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * 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 15
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Writes a tag and child elements (tag or attribute) using [p*], getting values using [g*] for writing. */ public static <F1,F2,F3,F4,T> TagWriteProtocol<T> tag(QName qname, Function1<T,F1> g1, WriteProtocol<XMLEvent,F1> p1, Function1<T,F2> g2, WriteProtocol<XMLEvent,F2> p2, Function1<T,F3> g3, WriteProtocol<XMLEvent,F3> p3, Function1<T,F4> g4, WriteProtocol<XMLEvent,F4> p4) { return new TagWriteProtocol<>(Option.of(qname), Vector.of(p1, p2, p3, p4), Vector.of(g1, g2, g3, g4)); }
Example 16
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Reads a tag and child elements (tag or attribute) using [p*], using [f] to create the result on reading. */ public static <F1,F2,F3,T> TagReadProtocol<T> tag(QName qname, ReadProtocol<XMLEvent,F1> p1, ReadProtocol<XMLEvent,F2> p2, ReadProtocol<XMLEvent,F3> p3, Function3<F1,F2,F3,T> f) { return new TagReadProtocol<>(Option.of(qname), Vector.of(p1, p2, p3), args -> f.apply((F1) args.get(0), (F2) args.get(1), (F3) args.get(2))); }
Example 17
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Reads and writes a tag and child elements (tag or attribute) using [p*], using [f] to create the result on reading, getting values using [g*] for writing. */ public static <F1,F2,F3,F4,F5,T> TagProtocol<T> tag(QName qname, Protocol<XMLEvent,F1> p1, Protocol<XMLEvent,F2> p2, Protocol<XMLEvent,F3> p3, Protocol<XMLEvent,F4> p4, Protocol<XMLEvent,F5> p5, Function5<F1,F2,F3,F4,F5,T> f, Function1<T,F1> g1, Function1<T,F2> g2, Function1<T,F3> g3, Function1<T,F4> g4, Function1<T,F5> g5) { return new TagProtocol<>(Option.of(qname), Vector.of(p1, p2, p3, p4, p5), args -> f.apply((F1) args.get(0), (F2) args.get(1), (F3) args.get(2), (F4) args.get(3), (F5) args.get(4)), Vector.of(g1, g2, g3, g4, g5)); }
Example 18
Source File: MultiWriteProtocol.java From ts-reaktive with MIT License | 4 votes |
@Override public Writer<CsvEvent, T> writer() { @SuppressWarnings("unchecked") Seq<Writer<CsvEvent, Object>> writers = protocols.map(c -> (Writer<CsvEvent,Object>) c.writer()); return new Writer<CsvEvent,T>() { @Override public Seq<CsvEvent> apply(T value) { return emit(i -> writers.apply(i).apply(getters.apply(i).apply(value))); } @Override public Seq<CsvEvent> reset() { return emit(i -> writers.apply(i).reset()); } private Seq<CsvEvent> emit(Function1<Integer, Seq<CsvEvent>> getEvents) { List<Seq<CsvEvent>> resultRows = new ArrayList<>(); for (int writerIdx = 0; writerIdx < writers.size(); writerIdx++) { Seq<CsvEvent> events = getEvents.apply(writerIdx); int row = 0; if (events.isEmpty()) { log.warn("{} did not emit any events. Emitting empty column instead.", protocols.apply(writerIdx)); events = Vector.of(CsvEvent.endRecord()); } else { if (!events.endsWith(Vector.of(CsvEvent.endValue(), CsvEvent.endRecord()))) { throw new IllegalArgumentException("Expecting nested writer to end its write with endValue, endRecord but did not: " + events); } events = events.dropRight(1); while (!events.isEmpty()) { Seq<CsvEvent> rowEvents = events.takeWhile(e -> !(e instanceof CsvEvent.EndRecord)); log.debug("Row {}, writer {}: {}", row, writerIdx, rowEvents); events = events.drop(rowEvents.size()); if (!events.isEmpty()) { // drop the endRecord() separator between two rows of a single inner write events = events.drop(1); } while (row >= resultRows.size()) { if (row == resultRows.size()) { // empty columns until current writer resultRows.add(Vector.fill(writerIdx, () -> CsvEvent.endValue())); } else { // completely empty row resultRows.add(Vector.fill(writers.size(), () -> CsvEvent.endValue())); } } resultRows.set(row, resultRows.get(row).appendAll(rowEvents)); row++; } } // fill the rows that weren't emitted from this writer (but were from others) with empty columns while (row < resultRows.size()) { resultRows.set(row, resultRows.get(row).append(CsvEvent.endValue())); row++; } } return Vector.ofAll(resultRows).map(row -> row.append(CsvEvent.endRecord())).fold(Vector.empty(), (a,b) -> a.appendAll(b)); } }; }
Example 19
Source File: XMLProtocol.java From ts-reaktive with MIT License | 4 votes |
/** * Reads a tag with any name and inner protocols using [p*], using [f] to create the result on reading. */ public static <F2,F3,T> TagReadProtocol<T> tagName(ReadProtocol<XMLEvent,F2> p2, ReadProtocol<XMLEvent,F3> p3, Function3<QName,F2,F3,T> f) { return new TagReadProtocol<>(Option.none(), Vector.of(p2, p3), args -> f.apply((QName) args.get(0), (F2) args.get(1), (F3) args.get(2))); }
Example 20
Source File: DataColumn.java From java-datatable with Apache License 2.0 | 2 votes |
/** * DataColumn constructor. * * @param type Stores the type of data stored in this column. * @param columnName The column name. * @param data The data items stored in the column. */ public DataColumn(Class<T> type, String columnName, T[] data) { this(type, columnName, Vector.of(data)); }