io.vavr.collection.Array Java Examples
The following examples show how to use
io.vavr.collection.Array.
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: 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 #2
Source File: CQLKeyColumnValueStore.java From grakn with GNU Affero General Public License v3.0 | 6 votes |
private static CreateTableWithOptions compactionOptions(CreateTableWithOptions createTable, Configuration configuration) { if (!configuration.has(COMPACTION_STRATEGY)) { return createTable; } CompactionStrategy<?> compactionStrategy = Match(configuration.get(COMPACTION_STRATEGY)) .of( Case($("SizeTieredCompactionStrategy"), leveledCompactionStrategy()), Case($("TimeWindowCompactionStrategy"), timeWindowCompactionStrategy()), Case($("LeveledCompactionStrategy"), leveledCompactionStrategy())); Iterator<Array<String>> groupedOptions = Array.of(configuration.get(COMPACTION_OPTIONS)) .grouped(2); for (Array<String> keyValue : groupedOptions) { compactionStrategy = compactionStrategy.withOption(keyValue.get(0), keyValue.get(1)); } return createTable.withCompaction(compactionStrategy); }
Example #3
Source File: TableComponent.java From swagger2markup with Apache License 2.0 | 6 votes |
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { DataFrame dataFrame = params.dataFrame; java.util.List<MarkupTableColumn> columnSpecs = dataFrame.getColumns().map(column -> { Integer widthRatio = Integer.valueOf(column.getMetaData().get(WIDTH_RATIO).getOrElse("0")); return new MarkupTableColumn(column.getId().getName()) .withWidthRatio(widthRatio) .withHeaderColumn(Boolean.parseBoolean(column.getMetaData().get(HEADER_COLUMN).getOrElse("false"))) .withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^" + widthRatio + "a"); } ).toJavaList(); IndexedSeq<IndexedSeq<String>> columnValues = dataFrame.getColumns() .map(column -> ((StringColumn) column).getValues()); java.util.List<java.util.List<String>> cells = Array.range(0, dataFrame.getRowCount()) .map(rowNumber -> columnValues.map(values -> values.get(rowNumber)).toJavaList()).toJavaList(); return markupDocBuilder.tableWithColumnSpecs(columnSpecs, cells); }
Example #4
Source File: ArrayTest.java From vavr-jackson with Apache License 2.0 | 6 votes |
@Test void testSerializeWithContext() throws IOException { // Given an object containing dates to serialize FrenchDates src = new FrenchDates(); src.dates = Array.of(new Date(1591308000000L)); // When serializing them using object mapper // with VAVR module and Java Time module ObjectMapper mapper = mapper().registerModule(new JavaTimeModule()); String json = mapper.writeValueAsString(src); // Then the serialization is successful Assertions.assertEquals("{\"dates\":[\"05/06/2020\"]}", json); // And the deserialization is successful FrenchDates restored = mapper.readValue(json, FrenchDates.class); Assertions.assertEquals(src.dates, restored.dates); }
Example #5
Source File: BooleanColumnTest.java From paleo with Apache License 2.0 | 5 votes |
@Test public void valueTypeSpecificBuilding() { BooleanColumn column = builder().add(true).addAll(false, false, true).add(false).build(); assertEquals(ID, column.getId()); assertEquals(5, column.getRowCount()); assertEquals(true, column.getValueAt(0)); assertEquals(false, column.getValueAt(column.getRowCount() - 1)); assertEquals(Array.of(true, false, false, true, false), column.valueStream().toArray()); }
Example #6
Source File: CategoryColumnTest.java From paleo with Apache License 2.0 | 5 votes |
@Test public void createValues() { CategoryColumnId id = CategoryColumnId.of("test"); Array<String> values = Array.ofAll(this.wordGenerator.randomWords(100)); CategoryColumn column = CategoryColumn.builder(id).addAll(values).build(); assertEquals(93, column.getCategories().length()); assertEquals(values, column.valueStream().toArray()); }
Example #7
Source File: AbstractColumnTest.java From paleo with Apache License 2.0 | 5 votes |
@Test public void values() { V v0 = generateValue(); V v1 = generateValue(); V v2 = generateValue(); C column = builder().add(v0).add(v1).add(v2).build(); Array<V> expected = Array.of(v0, v1, v2); assertEquals(expected, column.getValues()); assertEquals(expected, column.valueStream().toArray()); }
Example #8
Source File: CollectionFactoryMethodsUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenAnArray_whenCreated_thenCorrect() { Array<Integer> array = Array(1, 2, 3, 4, 5); assertEquals(array.size(), 5); assertEquals(array.get(0).intValue(), 1); }
Example #9
Source File: TimestampColumnTest.java From paleo with Apache License 2.0 | 5 votes |
@Test public void valueTypeSpecificBuilding() { TimestampColumn column = builder().add(AUG_26_1975).addAll(JAN_08_2008, OCT_26_1947).build(); assertEquals(ID, column.getId()); assertEquals(3, column.getRowCount()); assertEquals(JAN_08_2008, column.getValueAt(1)); assertEquals(Array.of(AUG_26_1975, JAN_08_2008, OCT_26_1947), column.getValues()); }
Example #10
Source File: GenericColumnTest.java From paleo with Apache License 2.0 | 5 votes |
@Test public void of() { GenericColumn<File, GenericColumnId> column = GenericColumn.of(ID, FILE_A); assertEquals(ID, column.getId()); assertEquals(1, column.getRowCount()); assertEquals(FILE_A, column.getValueAt(0)); assertEquals(Array.of(FILE_A), column.getValues().toArray()); }
Example #11
Source File: CircuitBreakersHealthIndicatorTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testHealthStatus() { CircuitBreaker openCircuitBreaker = mock(CircuitBreaker.class); CircuitBreaker halfOpenCircuitBreaker = mock(CircuitBreaker.class); CircuitBreaker closeCircuitBreaker = mock(CircuitBreaker.class); Map<CircuitBreaker.State, CircuitBreaker> expectedStateToCircuitBreaker = new HashMap<>(); expectedStateToCircuitBreaker.put(OPEN, openCircuitBreaker); expectedStateToCircuitBreaker.put(HALF_OPEN, halfOpenCircuitBreaker); expectedStateToCircuitBreaker.put(CLOSED, closeCircuitBreaker); CircuitBreakerConfigurationProperties.InstanceProperties instanceProperties = mock(CircuitBreakerConfigurationProperties.InstanceProperties.class); CircuitBreakerConfigurationProperties circuitBreakerProperties = mock( CircuitBreakerConfigurationProperties.class); // given CircuitBreakerRegistry registry = mock(CircuitBreakerRegistry.class); CircuitBreakerConfig config = mock(CircuitBreakerConfig.class); CircuitBreaker.Metrics metrics = mock(CircuitBreaker.Metrics.class); // when when(registry.getAllCircuitBreakers()).thenReturn(Array.ofAll(expectedStateToCircuitBreaker.values())); boolean allowHealthIndicatorToFail = true; expectedStateToCircuitBreaker.forEach( (state, circuitBreaker) -> setCircuitBreakerWhen(state, circuitBreaker, config, metrics, instanceProperties, circuitBreakerProperties, allowHealthIndicatorToFail)); CircuitBreakersHealthIndicator healthIndicator = new CircuitBreakersHealthIndicator(registry, circuitBreakerProperties, new SimpleStatusAggregator()); // then Health health = healthIndicator.health(); then(health.getStatus()).isEqualTo(Status.DOWN); then(health.getDetails()).containsKeys(OPEN.name(), HALF_OPEN.name(), CLOSED.name()); assertState(OPEN, Status.DOWN, health.getDetails()); assertState(HALF_OPEN, new Status("CIRCUIT_HALF_OPEN"), health.getDetails()); assertState(CLOSED, Status.UP, health.getDetails()); }
Example #12
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testArray() throws Exception { Array<A> src = Array.of(new B("a", "b")); String json = MAPPER.writeValueAsString(new ArrayPojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}"); ArrayPojo pojo = MAPPER.readValue(json, ArrayPojo.class); Array<A> restored = pojo.getValue(); Assertions.assertTrue(restored.get(0) instanceof B); Assertions.assertEquals(restored.get(0).a, "a"); Assertions.assertEquals(((B) restored.get(0)).b, "b"); }
Example #13
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testArrayOfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; Array<String> src = Array.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new ParameterizedArrayPojo<>(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}"); ParameterizedArrayPojo<java.lang.String> restored = MAPPER.readValue(json, new TypeReference<ParameterizedArrayPojo<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 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 #15
Source File: SimplePojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testArrayOfString() throws Exception { String src0 = "A"; String src1 = "B"; String src2 = "C"; Array<String> src = Array.of(src0, src1, src2); String json = MAPPER.writeValueAsString(new ArrayOfString().setValue(src)); Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}"); ArrayOfString restored = MAPPER.readValue(json, ArrayOfString.class); Assertions.assertEquals(src, restored.getValue()); }
Example #16
Source File: SimplePojoTest.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 ArrayOfTuple().setValue(src)); Assertions.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}"); ArrayOfTuple restored = MAPPER.readValue(json, ArrayOfTuple.class); Assertions.assertEquals(src, restored.getValue()); }
Example #17
Source File: CircuitBreakersHealthIndicatorTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void healthIndicatorMaxImpactCanBeOverridden() { CircuitBreaker openCircuitBreaker = mock(CircuitBreaker.class); CircuitBreaker halfOpenCircuitBreaker = mock(CircuitBreaker.class); CircuitBreaker closeCircuitBreaker = mock(CircuitBreaker.class); Map<CircuitBreaker.State, CircuitBreaker> expectedStateToCircuitBreaker = new HashMap<>(); expectedStateToCircuitBreaker.put(OPEN, openCircuitBreaker); expectedStateToCircuitBreaker.put(HALF_OPEN, halfOpenCircuitBreaker); expectedStateToCircuitBreaker.put(CLOSED, closeCircuitBreaker); CircuitBreakerConfigurationProperties.InstanceProperties instanceProperties = mock(CircuitBreakerConfigurationProperties.InstanceProperties.class); CircuitBreakerConfigurationProperties circuitBreakerProperties = mock(CircuitBreakerConfigurationProperties.class); // given CircuitBreakerRegistry registry = mock(CircuitBreakerRegistry.class); CircuitBreakerConfig config = mock(CircuitBreakerConfig.class); CircuitBreaker.Metrics metrics = mock(CircuitBreaker.Metrics.class); // when when(registry.getAllCircuitBreakers()).thenReturn(Array.ofAll(expectedStateToCircuitBreaker.values())); boolean allowHealthIndicatorToFail = false; // do not allow health indicator to fail expectedStateToCircuitBreaker.forEach( (state, circuitBreaker) -> setCircuitBreakerWhen(state, circuitBreaker, config, metrics, instanceProperties, circuitBreakerProperties, allowHealthIndicatorToFail)); CircuitBreakersHealthIndicator healthIndicator = new CircuitBreakersHealthIndicator(registry, circuitBreakerProperties, new SimpleStatusAggregator()); // then Health health = healthIndicator.health(); then(health.getStatus()).isEqualTo(Status.UP); then(health.getDetails()).containsKeys(OPEN.name(), HALF_OPEN.name(), CLOSED.name()); assertState(OPEN, new Status("CIRCUIT_OPEN"), health.getDetails()); assertState(HALF_OPEN, new Status("CIRCUIT_HALF_OPEN"), health.getDetails()); assertState(CLOSED, Status.UP, health.getDetails()); }
Example #18
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 5 votes |
@Test void testArray() throws Exception { Array<I> src = Array.of(new A(), new B()); String json = MAPPER.writeValueAsString(new ArrayPojo().setValue(src)); Assertions.assertEquals(json, "{\"value\":[{\"type\":\"a\"},{\"type\":\"b\"}]}"); ArrayPojo pojo = MAPPER.readValue(json, ArrayPojo.class); Array<I> restored = pojo.getValue(); Assertions.assertTrue(restored.get(0) instanceof A); Assertions.assertTrue(restored.get(1) instanceof B); }
Example #19
Source File: PolymorphicPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Array<I> getValue() { return v; }
Example #20
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public ParameterizedArrayPojo(Array<T1> v) { this.v = v; }
Example #21
Source File: TimestampColumn.java From paleo with Apache License 2.0 | 4 votes |
@Override public TimestampColumn build() { return new TimestampColumn(id, Array.ofAll(values), metaDataBuilder.build()); }
Example #22
Source File: GenericColumn.java From paleo with Apache License 2.0 | 4 votes |
private GenericColumn(I id, Array<V> values, Map<String, String> metaData) { super(id, values, metaData); }
Example #23
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public ArrayPojo setValue(Array<A> v) { this.v = v; return this; }
Example #24
Source File: ExtFieldsPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Array<A> getValue() { return v; }
Example #25
Source File: GenericColumn.java From paleo with Apache License 2.0 | 4 votes |
public static <V, I extends ColumnIds.GenericColumnId> GenericColumn<V, I> of(I id, V value, Map<String, String> metaData) { return new GenericColumn<>(id, Array.of(value), Objects.requireNonNull(metaData, "metaData is null")); }
Example #26
Source File: IndexedSeqTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
@Override protected Seq<?> of(Object... objects) { return Array.ofAll(Arrays.asList(objects)); }
Example #27
Source File: IndexedSeqTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
@Override protected Class<?> clz() { return Array.class; }
Example #28
Source File: GenericColumn.java From paleo with Apache License 2.0 | 4 votes |
@SafeVarargs public static <V, I extends ColumnIds.GenericColumnId> GenericColumn<V, I> ofAll(I id, V... values) { return new GenericColumn<>(id, Array.of(values), LinkedHashMap.empty()); }
Example #29
Source File: ArrayTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
@Override protected Seq<?> of(Object... objects) { return Array.ofAll(Arrays.asList(objects)); }
Example #30
Source File: ParameterizedPojoTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public Array<T1> getValue() { return v; }