Java Code Examples for io.vavr.collection.Array#of()

The following examples show how to use io.vavr.collection.Array#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: ArrayTest.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: AbstractColumnTest.java    From paleo with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: ExtFieldsPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: PolymorphicPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: GenericColumn.java    From paleo with Apache License 2.0 4 votes vote down vote up
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 10
Source File: GenericColumn.java    From paleo with Apache License 2.0 4 votes vote down vote up
@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 11
Source File: RetryMetrics.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
public static RetryMetrics ofRetry(Retry retry) {
    return new RetryMetrics(Array.of(retry));
}
 
Example 12
Source File: RateLimiterMetrics.java    From resilience4j with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of {@link RateLimiterMetrics} with a rate limiter as a source.
 *
 * @param rateLimiter the rate limiter
 */
public static RateLimiterMetrics ofRateLimiter(RateLimiter rateLimiter) {
    return new RateLimiterMetrics(Array.of(rateLimiter));
}
 
Example 13
Source File: BulkheadMetrics.java    From resilience4j with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of BulkheadMetrics {@link BulkheadMetrics} with a bulkhead as a
 * source.
 *
 * @param bulkhead the circuit breaker
 */
public static BulkheadMetrics ofBulkhead(Bulkhead bulkhead) {
    return new BulkheadMetrics(Array.of(bulkhead));
}
 
Example 14
Source File: CircuitBreakerMetrics.java    From resilience4j with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of CircuitBreakerMetrics {@link CircuitBreakerMetrics} with a circuit
 * breaker as a source.
 *
 * @param circuitBreaker the circuit breaker
 */
public static CircuitBreakerMetrics ofCircuitBreaker(CircuitBreaker circuitBreaker) {
    return new CircuitBreakerMetrics(Array.of(circuitBreaker));
}
 
Example 15
Source File: ThreadPoolBulkheadMetrics.java    From resilience4j with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of BulkheadMetrics {@link ThreadPoolBulkheadMetrics} with a bulkhead
 * as a source.
 *
 * @param bulkhead the circuit breaker
 */
public static ThreadPoolBulkheadMetrics ofBulkhead(ThreadPoolBulkhead bulkhead) {
    return new ThreadPoolBulkheadMetrics(Array.of(bulkhead));
}
 
Example 16
Source File: TimeLimiterMetrics.java    From resilience4j with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new instance of {@link TimeLimiterMetrics} with a time limiter as a source.
 *
 * @param timeLimiter the time limiter
 */
public static TimeLimiterMetrics ofTimeLimiter(TimeLimiter timeLimiter) {
    return new TimeLimiterMetrics(Array.of(timeLimiter));
}