io.vavr.Tuple3 Java Examples
The following examples show how to use
io.vavr.Tuple3.
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: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple3() throws Exception { Tuple3<A, A, A> src = Tuple.of(new B("a", "b"), new B("a", "b"), new B("a", "b")); String json = MAPPER.writeValueAsString(new Tuple3Pojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); Tuple3Pojo pojo = MAPPER.readValue(json, Tuple3Pojo.class); Tuple3<A, A, A> restored = pojo.getValue(); Assertions.assertTrue(restored._1 instanceof B); Assertions.assertEquals(restored._1.a, "a"); Assertions.assertEquals(((B) restored._1).b, "b"); Assertions.assertTrue(restored._2 instanceof B); Assertions.assertEquals(restored._2.a, "a"); Assertions.assertEquals(((B) restored._2).b, "b"); Assertions.assertTrue(restored._3 instanceof B); Assertions.assertEquals(restored._3.a, "a"); Assertions.assertEquals(((B) restored._3).b, "b"); }
Example #2
Source File: PregelComputation.java From kafka-graphs with Apache License 2.0 | 6 votes |
@Override public KeyValue<K, Tuple2<Integer, Map<K, List<Message>>>> transform( final K readOnlyKey, final Tuple3<Integer, K, List<Message>> value ) { Map<K, Map<K, List<Message>>> messages = localworkSetStore.get(value._1); if (messages == null) { messages = new HashMap<>(); } Map<K, List<Message>> messagesForSuperstep = messages.computeIfAbsent(readOnlyKey, k -> new HashMap<>()); if (value._3 != null) { messagesForSuperstep.put(value._2, value._3); } localworkSetStore.put(value._1, messages); positions.merge(new TopicPartition(context.topic(), context.partition()), context.offset() + 1, Math::max); Set<K> forwarded = forwardedVertices.get(value._1); if (forwarded != null) { forwarded.remove(readOnlyKey); } return null; }
Example #3
Source File: PregelComputation.java From kafka-graphs with Apache License 2.0 | 6 votes |
@Override public Tuple3<Integer, Tuple4<Integer, VV, Integer, VV>, Map<K, List<Message>>> transform( final K readOnlyKey, final Tuple2<Integer, Map<K, List<Message>>> value ) { int superstep = value._1; Tuple4<Integer, VV, Integer, VV> vertex = localSolutionSetStore.get(readOnlyKey); if (vertex == null) { VV vertexValue = ValueAndTimestamp.getValueOrNull(verticesStore.get(readOnlyKey)); if (vertexValue == null) { log.warn("No vertex value for {}", readOnlyKey); } vertex = new Tuple4<>(-1, vertexValue, 0, vertexValue); } Map<K, List<Message>> messages = value._2; Tuple3<Integer, Tuple4<Integer, VV, Integer, VV>, Map<K, List<Message>>> result = apply(superstep, readOnlyKey, vertex, messages); if (result._2 != null) { localSolutionSetStore.put(readOnlyKey, result._2); } return result; }
Example #4
Source File: PregelComputation.java From kafka-graphs with Apache License 2.0 | 6 votes |
@Override public void process(final K readOnlyKey, final Tuple2<Integer, Map<K, List<Message>>> value) { try { int superstep = value._1 - 1; for (Map.Entry<K, List<Message>> entry : value._2.entrySet()) { // List of messages may be empty in case of sending to self Tuple3<Integer, K, List<Message>> tuple = new Tuple3<>(superstep + 1, readOnlyKey, entry.getValue()); ProducerRecord<K, Tuple3<Integer, K, List<Message>>> producerRecord = new ProducerRecord<>(workSetTopic, entry.getKey(), tuple); Callback cb = callback(superstep, readOnlyKey, entry.getKey(), entry.getValue()); producer.send(producerRecord, cb); } producer.flush(); // Deactivate this vertex deactivateVertex(superstep, readOnlyKey); } catch (Exception e) { throw toRuntimeException(e); } }
Example #5
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple3OfTuple() throws Exception { String src0 = "A"; String src10 = "B"; String src11 = "C"; Tuple2<String, String> src1 = Tuple.of(src10, src11); String src20 = "D"; String src21 = "E"; Tuple2<String, String> src2 = Tuple.of(src20, src21); Tuple3<String, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new ParameterizedTuple3Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}"); ParameterizedTuple3Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedTuple3Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #6
Source File: CQLResultSetKeyIterator.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
EntryRecordIterator(SliceQuery sliceQuery, CQLColValGetter getter, Iterator<Row> iterator, StaticBuffer key) { this.getter = getter; StaticBuffer sliceEnd = sliceQuery.getSliceEnd(); this.iterator = iterator .<Tuple3<StaticBuffer, StaticBuffer, Row>> map(row -> Tuple.of( StaticArrayBuffer.of(row.getByteBuffer(CQLKeyColumnValueStore.COLUMN_COLUMN_NAME)), StaticArrayBuffer.of(row.getByteBuffer(CQLKeyColumnValueStore.VALUE_COLUMN_NAME)), row)) .takeWhile(tuple -> key.equals(StaticArrayBuffer.of(tuple._3.getByteBuffer(CQLKeyColumnValueStore.KEY_COLUMN_NAME))) && !sliceEnd.equals(tuple._1)) .take(sliceQuery.getLimit()); }
Example #7
Source File: ClutchMantisStageActuator.java From mantis with Apache License 2.0 | 5 votes |
protected Double processStep(Tuple3<String, Double, Integer> tup) { int desiredNumWorkers = ((Double) Math.ceil(tup._2)).intValue(); logger.info("Received request to scale to {} from {} workers.", desiredNumWorkers, tup._3); String reason = tup._1; if (desiredNumWorkers < tup._3) { scaler.scaleDownStage(tup._3, desiredNumWorkers, reason); } else if (desiredNumWorkers > tup._3) { scaler.scaleUpStage(tup._3, desiredNumWorkers, reason); } else { } return desiredNumWorkers * 1.0; }
Example #8
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple3OfTuple() throws Exception { String src0 = "A"; String src10 = "B"; String src11 = "C"; Tuple2<String, String> src1 = Tuple.of(src10, src11); String src20 = "D"; String src21 = "E"; Tuple2<String, String> src2 = Tuple.of(src20, src21); Tuple3<String, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new Tuple3OfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}"); Tuple3OfTuple restored = MAPPER.readValue(json, Tuple3OfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #9
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple3OfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; Tuple3<String, String, String> src = Tuple.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new Tuple3OfString().setValue(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}"); Tuple3OfString restored = MAPPER.readValue(json, Tuple3OfString.class); Assertions.assertEquals(src, restored.getValue()); }
Example #10
Source File: CQLKeyColumnValueStore.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
private static EntryList fromResultSet(ResultSet resultSet, StaticArrayEntry.GetColVal<Tuple3<StaticBuffer, StaticBuffer, Row>, StaticBuffer> getter) { Lazy<ArrayList<Row>> lazyList = Lazy.of(() -> Lists.newArrayList(resultSet)); // Use the Iterable overload of of ByteBuffer as it's able to allocate // the byte array up front. // To ensure that the Iterator instance is recreated, it is created // within the closure otherwise // the same iterator would be reused and would be exhausted. return StaticArrayEntryList.ofStaticBuffer(() -> Iterator.ofAll(lazyList.get()).map(row -> Tuple.of( StaticArrayBuffer.of(row.getByteBuffer(COLUMN_COLUMN_NAME)), StaticArrayBuffer.of(row.getByteBuffer(VALUE_COLUMN_NAME)), row)), getter); }
Example #11
Source File: CQLColValGetter.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
@Override public Object getMetaData(Tuple3<StaticBuffer, StaticBuffer, Row> tuple, EntryMetaData metaData) { switch (metaData) { case TIMESTAMP: return tuple._3.getLong(grakn.core.graph.diskstorage.cql.CQLKeyColumnValueStore.WRITETIME_COLUMN_NAME); case TTL: return tuple._3.getInt(grakn.core.graph.diskstorage.cql.CQLKeyColumnValueStore.TTL_COLUMN_NAME); default: throw new UnsupportedOperationException("Unsupported meta data: " + metaData); } }
Example #12
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple3OfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; Tuple3<String, String, String> src = Tuple.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new ParameterizedTuple3Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}"); ParameterizedTuple3Pojo<java.lang.String, java.lang.String, java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedTuple3Pojo<java.lang.String, java.lang.String, java.lang.String>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #13
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple3() throws Exception { Tuple3<I, I, I> src = Tuple.of(new A(), new B(), new A()); String json = MAPPER.writeValueAsString(new Tuple3Pojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"type\":\"a\"},{\"type\":\"b\"},{\"type\":\"a\"}]}"); Tuple3Pojo pojo = MAPPER.readValue(json, Tuple3Pojo.class); Tuple3<I, I, I> restored = pojo.getValue(); Assertions.assertTrue(restored._1 instanceof A); Assertions.assertTrue(restored._2 instanceof B); Assertions.assertTrue(restored._3 instanceof A); }
Example #14
Source File: PregelComputation.java From kafka-graphs with Apache License 2.0 | 5 votes |
private Callback callback(int superstep, K readOnlyKey, K vertex, List<Message> messages) { return (metadata, error) -> { if (error == null) { try { // Activate partition for next step int p = vertexToPartition(vertex, serialized.keySerde().serializer(), numPartitions); log.debug("Step {}, adding partition {} for vertex {}", superstep, p, vertex); ZKUtils.addChild(curator, applicationId, new PregelState(State.RUNNING, superstep + 1, Stage.SEND), childPath(p)); Map<Integer, Long> endOffsets = lastWrittenOffsets.computeIfAbsent(superstep, k -> new ConcurrentHashMap<>()); endOffsets.merge(metadata.partition(), metadata.offset(), Math::max); } catch (Exception e) { throw toRuntimeException(e); } } else if (error instanceof RecordTooLargeException && messages.size() > 1) { log.warn("Record too large, retrying with smaller messages"); for (Message message : messages) { List<Message> singleton = Collections.singletonList(message); Tuple3<Integer, K, List<Message>> tuple = new Tuple3<>(superstep + 1, readOnlyKey, singleton); ProducerRecord<K, Tuple3<Integer, K, List<Message>>> record = new ProducerRecord<>(workSetTopic, vertex, tuple); producer.send(record, callback(superstep, readOnlyKey, vertex, singleton)); } } else { log.error("Failed to send record to {}: {}", workSetTopic, error); } }; }
Example #15
Source File: PregelComputation.java From kafka-graphs with Apache License 2.0 | 5 votes |
private Tuple3<Integer, Tuple4<Integer, VV, Integer, VV>, Map<K, List<Message>>> apply( int superstep, K key, Tuple4<Integer, VV, Integer, VV> vertex, Map<K, List<Message>> incomingMessages ) { // Find the value that applies to this step VV oldVertexValue = vertex._3 <= superstep ? vertex._4 : vertex._2; int partition = vertexToPartition(key, serialized.keySerde().serializer(), numPartitions); if (!hasAggregators(superstep, partition)) { ComputeFunction.Aggregators aggregators = new ComputeFunction.Aggregators( previousAggregates(superstep), aggregators(superstep, partition)); computeFunction.preSuperstep(superstep, aggregators); } ComputeFunction.Callback<K, VV, EV, Message> cb = new ComputeFunction.Callback<>(context, key, edgesStore, previousAggregates(superstep), vertexAggregates(superstep, partition)); Iterable<Message> messages = () -> incomingMessages.values().stream() .flatMap(List::stream) .iterator(); Iterable<EdgeWithValue<K, EV>> edges = () -> { Map<K, EV> outgoingEdges = ValueAndTimestamp.getValueOrNull(edgesStore.get(key)); if (outgoingEdges == null) { outgoingEdges = Collections.emptyMap(); } return outgoingEdges.entrySet().stream() .map(e -> new EdgeWithValue<>(key, e.getKey(), e.getValue())) .iterator(); }; computeFunction.compute(superstep, new VertexWithValue<>(key, oldVertexValue), messages, edges, cb); Tuple4<Integer, VV, Integer, VV> newVertex = cb.newVertexValue != null ? new Tuple4<>(superstep, oldVertexValue, superstep + 1, cb.newVertexValue) : null; Map<K, List<Message>> outgoingMessages = cb.outgoingMessages; if (!cb.voteToHalt) { // Send to self to keep active outgoingMessages.computeIfAbsent(key, k -> new ArrayList<>()); } return new Tuple3<>(superstep + 1, newVertex, outgoingMessages); }
Example #16
Source File: CollectionFactoryMethodsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenATupleElement_whenCreated_thenCorrect() { Tuple3<Character, String, Integer> tuple = Tuple('a', "chain", 2); assertTrue(tuple!=null); assertEquals(tuple._1(), new Character('a')); assertEquals(tuple._2(), "chain"); assertEquals(tuple._3().intValue(), 2); }
Example #17
Source File: ClutchAutoScaler.java From mantis with Apache License 2.0 | 5 votes |
private ClutchControllerOutput findDominatingResource(Tuple3<ClutchControllerOutput, ClutchControllerOutput, ClutchControllerOutput> triple) { if (triple._1.scale >= triple._2.scale && triple._1.scale >= triple._3.scale) { return triple._1; } else if (triple._2.scale >= triple._1.scale && triple._2.scale >= triple._3.scale) { return triple._2; } else { return triple._3; } }
Example #18
Source File: VavrUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenCreatesTuple_thenCorrect2() { Tuple3<String, Integer, Double> java8 = Tuple.of("Java", 8, 1.8); String element1 = java8._1; int element2 = java8._2(); double element3 = java8._3(); assertEquals("Java", element1); assertEquals(8, element2); assertEquals(1.8, element3, 0.1); }
Example #19
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3<T1, T2, T3> getValue() { return v; }
Example #20
Source File: Tuple3Test.java From vavr-jackson with Apache License 2.0 | 4 votes |
@Override protected TypeReference<Tuple3<Option<String>, Option<String>, Option<String>>> typeReferenceWithOption() { return new TypeReference<Tuple3<Option<String>, Option<String>, Option<String>>>() {}; }
Example #21
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public ParameterizedTuple3Pojo setValue(Tuple3<T1, T2, T3> v) { this.v = v; return this; }
Example #22
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3<String, String, String> getValue() { return v; }
Example #23
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3OfString setValue(Tuple3<String, String, String> v) { this.v = v; return this; }
Example #24
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3<String, Tuple2<String, String>, Tuple2<String, String>> getValue() { return v; }
Example #25
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3OfTuple setValue(Tuple3<String, Tuple2<String, String>, Tuple2<String, String>> v) { this.v = v; return this; }
Example #26
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3<I, I, I> getValue() { return v; }
Example #27
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3Pojo setValue(Tuple3<I, I, I> v) { this.v = v; return this; }
Example #28
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public ParameterizedTuple3Pojo(Tuple3<T1, T2, T3> v) { this.v = v; }
Example #29
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3Pojo setValue(Tuple3<A, A, A> v) { this.v = v; return this; }
Example #30
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Tuple3<A, A, A> getValue() { return v; }