io.vavr.Tuple Java Examples
The following examples show how to use
io.vavr.Tuple.
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: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple7OfTuple() 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); String src30 = "F"; String src31 = "1"; Tuple2<String, String> src3 = Tuple.of(src30, src31); String src4 = "A"; String src50 = "B"; String src51 = "C"; Tuple2<String, String> src5 = Tuple.of(src50, src51); String src60 = "D"; String src61 = "E"; Tuple2<String, String> src6 = Tuple.of(src60, src61); Tuple7<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>, String, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6); String json = MAPPER.writeValueAsString(new Tuple7OfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\",[\"B\",\"C\"],[\"D\",\"E\"]]}"); Tuple7OfTuple restored = MAPPER.readValue(json, Tuple7OfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #2
Source File: CQLStoreManager.java From grakn with GNU Affero General Public License v3.0 | 6 votes |
private void initialiseKeyspace() { // if the keyspace already exists, just return if (this.session.getMetadata().getKeyspace(this.keyspace).isPresent()) { return; } Configuration configuration = getStorageConfig(); // Setting replication strategy based on value reading from the configuration: either "SimpleStrategy" or "NetworkTopologyStrategy" Map<String, Object> replication = Match(configuration.get(REPLICATION_STRATEGY)).of( Case($("SimpleStrategy"), strategy -> HashMap.<String, Object>of("class", strategy, "replication_factor", configuration.get(REPLICATION_FACTOR))), Case($("NetworkTopologyStrategy"), strategy -> HashMap.<String, Object>of("class", strategy) .merge(Array.of(configuration.get(REPLICATION_OPTIONS)) .grouped(2) .toMap(array -> Tuple.of(array.get(0), Integer.parseInt(array.get(1))))))) .toJavaMap(); session.execute(createKeyspace(this.keyspace) .ifNotExists() .withReplicationOptions(replication) .build()); }
Example #3
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple5OfTuple() 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); String src30 = "F"; String src31 = "1"; Tuple2<String, String> src3 = Tuple.of(src30, src31); String src4 = "A"; Tuple5<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>, String> src = Tuple.of(src0, src1, src2, src3, src4); String json = MAPPER.writeValueAsString(new ParameterizedTuple5Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\"]}"); ParameterizedTuple5Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedTuple5Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.String>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #4
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple6() throws Exception { Tuple6<A, A, A, A, A, A> src = Tuple.of(new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b")); String json = MAPPER.writeValueAsString(new Tuple6Pojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); Tuple6Pojo pojo = MAPPER.readValue(json, Tuple6Pojo.class); Tuple6<A, A, A, 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"); Assertions.assertTrue(restored._4 instanceof B); Assertions.assertEquals(restored._4.a, "a"); Assertions.assertEquals(((B) restored._4).b, "b"); Assertions.assertTrue(restored._5 instanceof B); Assertions.assertEquals(restored._5.a, "a"); Assertions.assertEquals(((B) restored._5).b, "b"); Assertions.assertTrue(restored._6 instanceof B); Assertions.assertEquals(restored._6.a, "a"); Assertions.assertEquals(((B) restored._6).b, "b"); }
Example #5
Source File: StatisticsServiceImpl.java From retro-game with GNU Affero General Public License v3.0 | 6 votes |
@Override public List<Tuple2<Date, PointsAndRankPairDto>> getDistinctChanges(long bodyId, long userId, StatisticsKindDto kind, StatisticsPeriodDto period) { List<? extends Statistics> statistics; switch (kind) { case OVERALL: default: statistics = fetch(overallStatisticsRepository, period, userId); break; case BUILDINGS: statistics = fetch(buildingsStatisticsRepository, period, userId); break; case TECHNOLOGIES: statistics = fetch(technologiesStatisticsRepository, period, userId); break; case FLEET: statistics = fetch(fleetStatisticsRepository, period, userId); break; case DEFENSE: statistics = fetch(defenseStatisticsRepository, period, userId); break; } return statistics.stream() .map(s -> Tuple.of(s.getAt(), new PointsAndRankPairDto(s.getPoints(), s.getRank()))) .collect(Collectors.toList()); }
Example #6
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testHashMultimapOfSeqTuple() throws Exception { String src00 = "A"; String src010 = "A"; String src011 = "B"; Tuple2<String, String> src01 = Tuple.of(src010, src011); Tuple2<String, Tuple2<String, String>> src0 = Tuple.of(src00, src01); String src10 = "A"; String src110 = "C"; String src111 = "D"; Tuple2<String, String> src11 = Tuple.of(src110, src111); Tuple2<String, Tuple2<String, String>> src1 = Tuple.of(src10, src11); HashMultimap<String, Tuple2<String, String>> src = HashMultimap.withSeq().ofEntries(src0, src1); String json = MAPPER.writeValueAsString(new ParameterizedHashMultimapPojo<>(src)); Assertions.assertEquals(json, "{\"value\":{\"A\":[[\"A\",\"B\"],[\"C\",\"D\"]]}}"); ParameterizedHashMultimapPojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedHashMultimapPojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #7
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple8OfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; String src3 = "D"; String src4 = "E"; String src5 = "F"; String src6 = "1"; String src7 = "2"; Tuple8<String, String, String, String, String, String, String, String> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6, src7); String json = MAPPER.writeValueAsString(new ParameterizedTuple8Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"1\",\"2\"]}"); ParameterizedTuple8Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedTuple8Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #8
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple4OfTuple() 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); String src30 = "F"; String src31 = "1"; Tuple2<String, String> src3 = Tuple.of(src30, src31); Tuple4<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2, src3); String json = MAPPER.writeValueAsString(new Tuple4OfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"]]}"); Tuple4OfTuple restored = MAPPER.readValue(json, Tuple4OfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #9
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testLinkedHashMultimapOfSeqTuple() throws Exception { String src00 = "A"; String src010 = "A"; String src011 = "B"; Tuple2<String, String> src01 = Tuple.of(src010, src011); Tuple2<String, Tuple2<String, String>> src0 = Tuple.of(src00, src01); String src10 = "A"; String src110 = "C"; String src111 = "D"; Tuple2<String, String> src11 = Tuple.of(src110, src111); Tuple2<String, Tuple2<String, String>> src1 = Tuple.of(src10, src11); LinkedHashMultimap<String, Tuple2<String, String>> src = LinkedHashMultimap.withSeq().ofEntries(src0, src1); String json = MAPPER.writeValueAsString(new LinkedHashMultimapOfSeqTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":{\"A\":[[\"A\",\"B\"],[\"C\",\"D\"]]}}"); LinkedHashMultimapOfSeqTuple restored = MAPPER.readValue(json, LinkedHashMultimapOfSeqTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #10
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple7OfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; String src3 = "D"; String src4 = "E"; String src5 = "F"; String src6 = "1"; Tuple7<String, String, String, String, String, String, String> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6); String json = MAPPER.writeValueAsString(new ParameterizedTuple7Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"1\"]}"); ParameterizedTuple7Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedTuple7Pojo<java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #11
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testTuple5() throws Exception { Tuple5<A, A, A, A, A> src = Tuple.of(new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b"), new B("a", "b")); String json = MAPPER.writeValueAsString(new Tuple5Pojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}},{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); Tuple5Pojo pojo = MAPPER.readValue(json, Tuple5Pojo.class); Tuple5<A, A, 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"); Assertions.assertTrue(restored._4 instanceof B); Assertions.assertEquals(restored._4.a, "a"); Assertions.assertEquals(((B) restored._4).b, "b"); Assertions.assertTrue(restored._5 instanceof B); Assertions.assertEquals(restored._5.a, "a"); Assertions.assertEquals(((B) restored._5).b, "b"); }
Example #12
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple1() throws Exception { Tuple1<A> src = Tuple.of(new B("a", "b")); String json = MAPPER.writeValueAsString(new Tuple1Pojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); Tuple1Pojo pojo = MAPPER.readValue(json, Tuple1Pojo.class); Tuple1<A> restored = pojo.getValue(); Assertions.assertTrue(restored._1 instanceof B); Assertions.assertEquals(restored._1.a, "a"); Assertions.assertEquals(((B) restored._1).b, "b"); }
Example #13
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple1OfString() throws Exception { String src0 = "A"; Tuple1<String> src = Tuple.of(src0); String json = MAPPER.writeValueAsString(new ParameterizedTuple1Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\"]}"); ParameterizedTuple1Pojo<java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedTuple1Pojo<java.lang.String>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #14
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testQueueOfTuple() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); Queue<Tuple2<String, String>> src = Queue.of(src0); String json = MAPPER.writeValueAsString(new ParameterizedQueuePojo<>(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); ParameterizedQueuePojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedQueuePojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #15
Source File: TupleTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testWithOption() throws IOException { verifySerialization(typeReferenceWithOption(), List.of( Tuple.of(ofObjects(Option.some("1"), Option.none()), genJsonTuple("1", null)), Tuple.of(ofObjects(Option.some("1"), Option.some("17")), genJsonTuple("1", "17")), Tuple.of(ofObjects(Option.none(), Option.some("17")), genJsonTuple(null, "17")), Tuple.of(ofObjects(Option.none(), Option.none()), genJsonTuple(null, null)) )); }
Example #16
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testArrayOfTuple() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); Array<Tuple2<String, String>> src = Array.of(src0); String json = MAPPER.writeValueAsString(new ParameterizedArrayPojo<>(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); ParameterizedArrayPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedArrayPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #17
Source File: BindingClass.java From vavr-jackson with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { java.util.Map<Class<?>, Tuple2<String, String>> cases1 = new java.util.HashMap<>(); cases1.put(List.class, Tuple.of("List.of(new ImplementedClass())", "head()")); cases1.put(HashSet.class, Tuple.of("HashSet.of(new ImplementedClass())", "head()")); cases1.put(Option.class, Tuple.of("Option.of(new ImplementedClass())", "get()")); cases1.put(Lazy.class, Tuple.of("Lazy.of(ImplementedClass::new)", "get()")); cases1.put(Tuple1.class, Tuple.of("new Tuple1<>(new ImplementedClass())", "_1")); java.util.Map<Class<?>, Tuple2<String, String>> cases2 = new java.util.HashMap<>(); cases2.put(Either.class, Tuple.of("Either.right(new ImplementedClass())", "get()")); cases2.put(HashMap.class, Tuple.of("HashMap.of(42, new ImplementedClass())", "head()._2")); cases2.put(HashMultimap.class, Tuple.of("HashMultimap.withSeq().of(42, new ImplementedClass())", "head()._2")); cases2.put(Tuple2.class, Tuple.of("new Tuple2<>(42, new ImplementedClass())", "_2")); generate(cases1, cases2); }
Example #18
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testHashMapOfTuple() throws Exception { Integer src00 = 1; String src010 = "A"; String src011 = "B"; Tuple2<String, String> src01 = Tuple.of(src010, src011); Tuple2<Integer, Tuple2<String, String>> src0 = Tuple.of(src00, src01); HashMap<Integer, Tuple2<String, String>> src = HashMap.ofEntries(src0); String json = MAPPER.writeValueAsString(new ParameterizedHashMapPojo<>(src)); Assertions.assertEquals(json, "{\"value\":{\"1\":[\"A\",\"B\"]}}"); ParameterizedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #19
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testLinkedHashMapOfTuple() throws Exception { Integer src00 = 1; String src010 = "A"; String src011 = "B"; Tuple2<String, String> src01 = Tuple.of(src010, src011); Tuple2<Integer, Tuple2<String, String>> src0 = Tuple.of(src00, src01); LinkedHashMap<Integer, Tuple2<String, String>> src = LinkedHashMap.ofEntries(src0); String json = MAPPER.writeValueAsString(new ParameterizedLinkedHashMapPojo<>(src)); Assertions.assertEquals(json, "{\"value\":{\"1\":[\"A\",\"B\"]}}"); ParameterizedLinkedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedLinkedHashMapPojo<java.lang.Integer, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #20
Source File: RetryRegistryTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void shouldInitRegistryTags() { RetryConfig retryConfig = RetryConfig.ofDefaults(); Map<String, RetryConfig> retryConfigs = Collections.singletonMap("default", retryConfig); RetryRegistry registry = RetryRegistry.of(retryConfigs,new NoOpRetryEventConsumer(),io.vavr.collection.HashMap.of("Tag1Key","Tag1Value")); assertThat(registry.getTags()).isNotEmpty(); assertThat(registry.getTags()).containsOnly(Tuple.of("Tag1Key","Tag1Value")); }
Example #21
Source File: Event.java From camunda-bpm-reactor with Apache License 2.0 | 5 votes |
/** * Returns an unmodifiable Iterator over a copy of this Headers' contents. */ @Override public Iterator<Tuple2<String, Object>> iterator() { synchronized (this.monitor) { List<Tuple2<String, Object>> headers = new ArrayList<Tuple2<String, Object>>(this.headers.size()); for (Map.Entry<String, Object> header : this.headers.entrySet()) { headers.add(Tuple.of(header.getKey(), header.getValue())); } return Collections.unmodifiableList(headers).iterator(); } }
Example #22
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testRightEitherOfTuple() throws Exception { String srcr0 = "A"; String srcr1 = "B"; Tuple2<String, String> srcr = Tuple.of(srcr0, srcr1); Either<Object, Tuple2<String, String>> src = Either.right(srcr); String json = MAPPER.writeValueAsString(new ParameterizedEitherPojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"right\",[\"A\",\"B\"]]}"); ParameterizedEitherPojo<java.lang.Object, io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = MAPPER.readValue(json, new TypeReference<ParameterizedEitherPojo<java.lang.Object, io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){}); Assertions.assertEquals(src, restored.getValue()); }
Example #23
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testLinkedHashMultimapOfSeqString() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); String src10 = "A"; String src11 = "C"; Tuple2<String, String> src1 = Tuple.of(src10, src11); LinkedHashMultimap<String, String> src = LinkedHashMultimap.withSeq().ofEntries(src0, src1); String json = MAPPER.writeValueAsString(new LinkedHashMultimapOfSeqString().setValue(src)); Assertions.assertEquals(json, "{\"value\":{\"A\":[\"B\",\"C\"]}}"); LinkedHashMultimapOfSeqString restored = MAPPER.readValue(json, LinkedHashMultimapOfSeqString.class); Assertions.assertEquals(src, restored.getValue()); }
Example #24
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testTuple8OfTuple() 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); String src30 = "F"; String src31 = "1"; Tuple2<String, String> src3 = Tuple.of(src30, src31); String src4 = "A"; String src50 = "B"; String src51 = "C"; Tuple2<String, String> src5 = Tuple.of(src50, src51); String src60 = "D"; String src61 = "E"; Tuple2<String, String> src6 = Tuple.of(src60, src61); String src70 = "F"; String src71 = "1"; Tuple2<String, String> src7 = Tuple.of(src70, src71); Tuple8<String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>, String, Tuple2<String, String>, Tuple2<String, String>, Tuple2<String, String>> src = Tuple.of(src0, src1, src2, src3, src4, src5, src6, src7); String json = MAPPER.writeValueAsString(new ParameterizedTuple8Pojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"],\"A\",[\"B\",\"C\"],[\"D\",\"E\"],[\"F\",\"1\"]]}"); ParameterizedTuple8Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.String, io.vavr.Tuple2<java.lang.String, 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<ParameterizedTuple8Pojo<java.lang.String, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.String, io.vavr.Tuple2<java.lang.String, 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 #25
Source File: AnyAttributeProtocol.java From ts-reaktive with MIT License | 5 votes |
@Override public Reader<XMLEvent,Tuple2<QName,String>> reader() { return new Reader<XMLEvent,Tuple2<QName,String>>() { private int level = 0; @Override public Try<Tuple2<QName,String>> reset() { level = 0; return none(); } @Override public Try<Tuple2<QName,String>> apply(XMLEvent evt) { if (level == 0 && evt.isAttribute()) { Attribute attr = Attribute.class.cast(evt); return Try.success(Tuple.of(attr.getName(), attr.getValue())); } else if (evt.isStartElement()) { level++; return none(); } else if (evt.isEndElement()) { level--; return none(); } else { return none(); } } }; }
Example #26
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testHashMultimapOfSeqString() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); String src10 = "A"; String src11 = "C"; Tuple2<String, String> src1 = Tuple.of(src10, src11); HashMultimap<String, String> src = HashMultimap.withSeq().ofEntries(src0, src1); String json = MAPPER.writeValueAsString(new HashMultimapOfSeqString().setValue(src)); Assertions.assertEquals(json, "{\"value\":{\"A\":[\"B\",\"C\"]}}"); HashMultimapOfSeqString restored = MAPPER.readValue(json, HashMultimapOfSeqString.class); Assertions.assertEquals(src, restored.getValue()); }
Example #27
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testHashSetOfTuple() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); HashSet<Tuple2<String, String>> src = HashSet.of(src0); String json = MAPPER.writeValueAsString(new HashSetOfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); HashSetOfTuple restored = MAPPER.readValue(json, HashSetOfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #28
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testListOfTuple() throws Exception { String src00 = "A"; String src01 = "B"; Tuple2<String, String> src0 = Tuple.of(src00, src01); List<Tuple2<String, String>> src = List.of(src0); String json = MAPPER.writeValueAsString(new ListOfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); ListOfTuple restored = MAPPER.readValue(json, ListOfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #29
Source File: MantisClutchConfigurationSelector.java From mantis with Apache License 2.0 | 5 votes |
@Override public ClutchConfiguration apply(Map<Clutch.Metric, UpdateDoublesSketch> sketches) { updateTrueMaxValues(sketches); double numberOfCpuCores = stageSchedulingInfo.getMachineDefinition().getCpuCores(); // Setpoint double setPoint = getSetpoint(sketches, numberOfCpuCores); // ROPE Tuple2<Double, Double> rope = Tuple.of(setPoint * 0.3, 0.0); // Gain long deltaT = stageSchedulingInfo.getScalingPolicy().getCoolDownSecs() / 30l; //double minMaxMidPoint = stageSchedulingInfo.getScalingPolicy().getMax() - stageSchedulingInfo.getScalingPolicy().getMin(); double dampeningFactor = 0.33; // 0.4 caused a little oscillation too. We'll try 1/3 across each. double kp = 1.0 / setPoint / deltaT * stageSchedulingInfo.getScalingPolicy().getMin(); //minMaxMidPoint * dampeningFactor; double ki = 0.0 * dampeningFactor; // We don't want any "state" from integral gain right now. double kd = 1.0 / setPoint / deltaT * stageSchedulingInfo.getScalingPolicy().getMin(); // minMaxMidPoint * dampeningFactor; // TODO: Do we want to reset sketches, we need at least one day's values //resetSketches(sketches); return com.netflix.control.clutch.ClutchConfiguration.builder() .metric(Clutch.Metric.RPS) .setPoint(setPoint) .kp(kp) .ki(ki) .kd(kd) .minSize(stageSchedulingInfo.getScalingPolicy().getMin()) .maxSize(stageSchedulingInfo.getScalingPolicy().getMax()) .rope(rope) .cooldownInterval(stageSchedulingInfo.getScalingPolicy().getCoolDownSecs()) .cooldownUnits(TimeUnit.SECONDS) .build(); }
Example #30
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testLeftEitherOfTuple() throws Exception { String srcl0 = "A"; String srcl1 = "B"; Tuple2<String, String> srcl = Tuple.of(srcl0, srcl1); Either<Tuple2<String, String>, Object> src = Either.left(srcl); String json = MAPPER.writeValueAsString(new ParameterizedEitherPojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"left\",[\"A\",\"B\"]]}"); ParameterizedEitherPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.Object> restored = MAPPER.readValue(json, new TypeReference<ParameterizedEitherPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>, java.lang.Object>>(){}); Assertions.assertEquals(src, restored.getValue()); }