org.pcollections.TreePVector Java Examples
The following examples show how to use
org.pcollections.TreePVector.
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: WireTransferServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 6 votes |
@Override public ServiceCall<NotUsed, PSequence<TransactionSummary>> getAllTransactionsFor(String portfolioId) { return request -> { Predicate<TransactionSummary> predicate = s -> s.source.equals(portfolioId) || s.destination.equals(portfolioId); CompletionStage<PSequence<TransactionSummary>> result = db.selectAll( "SELECT transferId, status, dateTime, source, destination, amount FROM transfer_summary;").thenApply(rows -> { List<TransactionSummary> summary = rows.stream().map(row -> TransactionSummary.builder() .id(row.getString("transferid")) .status(row.getString("status")) .dateTime(row.getString("dateTime")) .source(row.getString("source")) .destination(row.getString("destination")) .amount(row.getString("amount")) .build()) .filter(predicate) .collect(Collectors.toList()); return TreePVector.from(summary); }); return result; }; }
Example #2
Source File: PCollectionsUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void whenTreePVectorMethods_thenPerformOperations() { TreePVector<String> pVector = TreePVector.empty(); TreePVector<String> pV1 = pVector.plus("e1"); TreePVector<String> pV2 = pV1.plusAll(Arrays.asList("e2", "e3", "e4")); assertEquals(1, pV1.size()); assertEquals(4, pV2.size()); TreePVector<String> pV3 = pV2.minus("e1"); TreePVector<String> pV4 = pV3.minusAll(Arrays.asList("e2", "e3", "e4")); assertEquals(pV3.size(), 3); assertEquals(pV4.size(), 0); TreePVector<String> pSub = pV2.subList(0, 2); assertTrue(pSub.contains("e1") && pSub.contains("e2")); PVector<String> pVW = pV2.with(0, "e10"); assertEquals(pVW.get(0), "e10"); }
Example #3
Source File: ListDeserialiser.java From octarine with Apache License 2.0 | 6 votes |
@Override public PVector<V> applyUnsafe(JsonParser p) throws IOException { List<V> values = new LinkedList<>(); /* * If we are in the root context (not inside an object or list) then we need to consume the next token * before attempting to call child deserialisers. */ if (p.getParsingContext().inRoot()) { if (p.nextToken() == JsonToken.END_ARRAY) { return TreePVector.empty(); } } if (JsonToken.VALUE_NULL != p.getCurrentToken()) { /* * When the parser has hit the end of input nextToken() will always return null. * So need to prevent infinite loops we check the parser closed flag. */ while (!p.isClosed() && (p.nextToken() != JsonToken.END_ARRAY)) { values.add(itemDeserialiser.apply(p)); } } return TreePVector.from(values); }
Example #4
Source File: RegistrationServiceImpl.java From activator-lagom-cargotracker with Apache License 2.0 | 6 votes |
/** * Get all registered Cargo * * @return */ @Override public ServiceCall<NotUsed, NotUsed, PSequence<Cargo>> getAllRegistrations() { return (userId, req) -> { CompletionStage<PSequence<Cargo>> result = db.selectAll("SELECT cargoid, name, description, owner, destination FROM cargo") .thenApply(rows -> { List<Cargo> cargos = rows.stream().map(row -> Cargo.of(row.getString("cargoid"), row.getString("name"), row.getString("description"), row.getString("owner"), row.getString("destination"))).collect(Collectors.toList()); return TreePVector.from(cargos); }); return result; }; }
Example #5
Source File: PortfolioServiceImpl.java From reactive-stock-trader with Apache License 2.0 | 6 votes |
@Override public ServiceCall<NotUsed, PSequence<PortfolioSummary>> getAllPortfolios() { return request -> { CompletionStage<PSequence<PortfolioSummary>> result = db.selectAll( "SELECT portfolioId, name FROM portfolio_summary;").thenApply(rows -> { List<PortfolioSummary> summary = rows.stream().map(row -> PortfolioSummary.builder() .portfolioId(new PortfolioId(row.getString("portfolioId"))) .name(row.getString("name")) .build()) .collect(Collectors.toList()); return TreePVector.from(summary); }); return result; }; }
Example #6
Source File: NotesListReducer.java From reductor with Apache License 2.0 | 5 votes |
@Action(value = NotesActions.TOGGLE, from = NotesActions.class) public List<Note> toggle(List<Note> notes, int noteId) { for (int i = 0; i < notes.size(); i++) { Note note = notes.get(i); if (note.id == noteId) return TreePVector.from(notes).with(i, new Note(noteId, note.note, !note.checked)); } return notes; }
Example #7
Source File: NotesListReducer.java From reductor with Apache License 2.0 | 5 votes |
@Action(value = NotesActions.REMOVE_ITEM, from = NotesActions.class) public List<Note> remove(List<Note> notes, int id) { for (int i = 0, notesSize = notes.size(); i < notesSize; i++) { Note note = notes.get(i); if (note.id == id) { return TreePVector.from(notes).minus(i); } } return notes; }
Example #8
Source File: TreePVectorTest.java From pcollections with MIT License | 5 votes |
public void testSubListStackOverflowRegression() { PVector<Integer> v = TreePVector.empty(); for (int i = 0; i < 20000; i++) { v = v.plus(i); } PVector<Integer> head = v.subList(0, 10000); assertEquals(head.size(), 10000 - 0); PVector<Integer> tail = v.subList(10000, 20000); assertEquals(tail.size(), 20000 - 10000); PVector<Integer> u = v.subList(9000, 11000); assertEquals(u.size(), 11000 - 9000); }
Example #9
Source File: Environment.java From vlingo-actors with Mozilla Public License 2.0 | 5 votes |
protected Environment( final Stage stage, final Address address, final Definition definition, final Actor parent, final Mailbox mailbox, final Supervisor maybeSupervisor, final Logger logger) { assert(stage != null); this.stage = stage; assert(address != null); this.address = address; assert(definition != null); this.definition = definition; if (address.id() != World.PRIVATE_ROOT_ID) assert(parent != null); this.parent = parent; assert(mailbox != null); this.mailbox = mailbox; this.maybeSupervisor = maybeSupervisor; this.failureMark = new FailureMark(); this.logger = logger; this.children = TreePVector.empty(); this.proxyCache = new HashMap<>(1); // this.stowage = new Stowage(); this.stowageOverrides = null; // this.suspended = new Stowage(); this.secured = new AtomicBoolean(false); this.stopped = new AtomicBoolean(false); }
Example #10
Source File: RecordTest.java From octarine with Apache License 2.0 | 5 votes |
@Test public void keys_are_lenses_on_valid_records() { Lens<Record, PVector<String>> linesLens = Person.address.assertPresent() .join(Address.addressLines.assertValidPresent(Address.schema)); assertThat(linesLens.get(validTestRecord), equalTo(Arrays.asList("1 Cat Road", "Smallville", "T11 M22"))); assertThat(linesLens.set(validTestRecord, TreePVector.from(Arrays.asList("1 Mouse Street", "Mouseville", "M11 T22"))), equalTo($$( Person.name.of("Tom Cat"), Person.age.of(9), Person.address.of( Address.addressLines.of("1 Mouse Street", "Mouseville", "M11 T22") ) )) ); Lens<Record, String> secondLineOfValidAddress = linesLens.join(Lens.intoPVector(1)); assertThat(secondLineOfValidAddress.get(validTestRecord), equalTo("Smallville")); assertThat(secondLineOfValidAddress.set(validTestRecord, "Big Town"), equalTo($$( Person.name.of("Tom Cat"), Person.age.of(9), Person.address.of( Address.addressLines.of("1 Cat Road", "Big Town", "T11 M22") ) )) ); }
Example #11
Source File: ListKey.java From octarine with Apache License 2.0 | 4 votes |
default Value of(Collection<? extends T> values) { return of(TreePVector.from(values)); }
Example #12
Source File: BsonListDeserialiser.java From octarine with Apache License 2.0 | 4 votes |
@Override public PVector<V> applyUnsafe(BsonValue p) throws BsonInvalidOperationException { BsonArray bsonArray = p.asArray(); List<V> values = bsonArray.getValues().stream().map(v -> itemDeserialiser.apply(v)).collect(Collectors.toList()); return TreePVector.from(values); }
Example #13
Source File: AnInstance.java From octarine with Apache License 2.0 | 4 votes |
private AnInstance(Class<? extends T> klass) { this.klass = klass; matchers = TreePVector.empty(); }
Example #14
Source File: AnInstance.java From octarine with Apache License 2.0 | 4 votes |
private AnInstance(Class<? extends T> klass) { this.klass = klass; matchers = TreePVector.empty(); }
Example #15
Source File: AnInstance.java From octarine with Apache License 2.0 | 4 votes |
private AnInstance(Class<? extends T> klass) { this.klass = klass; matchers = TreePVector.empty(); }
Example #16
Source File: AnInstance.java From octarine with Apache License 2.0 | 4 votes |
private AnInstance(Class<? extends T> klass) { this.klass = klass; matchers = TreePVector.empty(); }
Example #17
Source File: TreePVectorDeserializer.java From jackson-datatypes-collections with Apache License 2.0 | 4 votes |
@Override protected TreePVector<Object> createEmptyCollection() { return TreePVector.empty(); }
Example #18
Source File: MatchingExtractor.java From octarine with Apache License 2.0 | 4 votes |
static <S, T> MatchingExtractor<S, T> build(UnaryOperator<MatchingExtractor<S, T>> builder) { return builder.apply(new MatchingExtractor<S, T>(TreePVector.empty())); }
Example #19
Source File: NotesListReducer.java From reductor with Apache License 2.0 | 4 votes |
@Action(value = NotesActions.ADD_ACTION, from = NotesActions.class) public List<Note> add(List<Note> state, int id, String content) { return TreePVector.from(state).plus(new Note(id, content, false)); }
Example #20
Source File: NotesListReducer.java From reductor with Apache License 2.0 | 4 votes |
@AutoReducer.InitialState List<Note> initialState() { return TreePVector.empty(); }
Example #21
Source File: Environment.java From vlingo-actors with Mozilla Public License 2.0 | 4 votes |
private void stopChildren() { // TODO: re-implement as: children.forEach(child -> selfAs(Stoppable.class).stop()); children.forEach(child -> child.stop()); children = TreePVector.empty(); }
Example #22
Source File: ItineraryEntity.java From activator-lagom-cargotracker with Apache License 2.0 | 4 votes |
/** * An entity can define different behaviours for different states, but it will always start with an * initial behaviour. This entity only has one behaviour. */ @Override public Behavior initialBehavior(Optional<ItineraryState> snapshotState) { /* * Behaviour is defined using a behaviour builder. The behaviour builder starts with a state, if this * entity supports snapshotting (an optimisation that allows the state itself to be persisted to combine * many events into one), then the passed in snapshotState may have a value that can be used. * * Otherwise, the default state is to use a dummy Cargo with and id of 0L.. */ BehaviorBuilder b = newBehaviorBuilder(snapshotState.orElse( ItineraryState.builder() .id("") .cargoId("") .origin("") .destination("") .legs(TreePVector.empty()) .timestamp(LocalDateTime.now()).build())); /* * Command handler for the create itinerary command. */ b.setCommandHandler(CreateItinerary.class, (cmd, ctx) -> // In response to this command, we want to first persist it as a itinerary created event ctx.thenPersist( ItineraryCreated.of( cmd.getItinerary().getId(), cmd.getItinerary().getCargoId(), cmd.getItinerary().getOrigin(), cmd.getItinerary().getDestination()), // Then once the event is successfully persisted, we respond with done. evt -> ctx.reply(Done.getInstance()) ) ); /* * Command handler for the create itinerary command. */ b.setCommandHandler(AddLeg.class, (cmd, ctx) -> // In response to this command, we want to first persist it as a itinerary created event ctx.thenPersist( LegAdded.of( cmd.getLeg().getId(), cmd.getLeg().getCargoId(), cmd.getLeg().getLocation(), cmd.getLeg().getArrivalTime(), cmd.getLeg().getDepartureTime()), // Then once the event is successfully persisted, we respond with done. evt -> ctx.reply(Done.getInstance()) ) ); /* * Event handler for the itinerary created event. */ b.setEventHandler(LegAdded.class, evt -> { final Leg leg = Leg.builder() .id(evt.getId()) .cargoId(evt.getCargoId()) .location(evt.getLocation()) .arrivalTime(evt.getArrivalTime()) .departureTime(evt.getDepartureTime()) .build(); return state().withLegs(state().getLegs().plus(leg)); } ); /* * Event handler for the itinerary created event. */ b.setEventHandler(ItineraryCreated.class, // We simply update the current state to use the greeting message from the event. evt -> state() .withId(evt.getId()) .withCargoId(evt.getCargoId()) .withOrigin(evt.getOrigin()) .withDestination(evt.getDestination()) .withTimestamp(LocalDateTime.now()) ); /* * We've defined all our behaviour, so build and return it. */ return b.build(); }