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

The following examples show how to use io.vavr.collection.List#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: AriEventProcessing.java    From ari-proxy with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Seq<MetricsGatherer> determineMetricsGatherer(AriMessageType type) {

		List<MetricsGatherer> metricsGatherers = List.of(callContextSupplier -> new IncreaseCounter(type.name()));

		switch (type) {
			case STASIS_START:
				metricsGatherers = metricsGatherers.appendAll(List.of(
						callContextSupplier -> new IncreaseCounter("CallsStarted"),
						callContextSupplier -> new StartCallSetupTimer(callContextSupplier.get())
				));
				break;
			case STASIS_END:
				metricsGatherers = metricsGatherers.append(
						callContextSupplier -> new IncreaseCounter("CallsEnded")
				);
				break;
		}

		return metricsGatherers;
	}
 
Example 2
Source File: CollectionAPIUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenList_whenPrependTail_thenCorrect() {
    List<Integer> intList = List.of(1, 2, 3);

    List<Integer> newList = intList.tail()
      .prepend(0);

    assertEquals(new Integer(1), intList.get(0));
    assertEquals(new Integer(2), intList.get(1));
    assertEquals(new Integer(3), intList.get(2));

    assertNotSame(intList.get(0), newList.get(0));
    assertEquals(new Integer(0), newList.get(0));
    assertSame(intList.get(1), newList.get(1));
    assertSame(intList.get(2), newList.get(2));
}
 
Example 3
Source File: IntervalFunctionTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPassPositiveRandomizationFactor() {
    final Duration duration = Duration.ofMillis(100);
    final float multiplier = 1.5f;
    final List<Float> correctFactors = List.of(0.0f, 0.25f, 0.5f, 0.75f, 0.1f);

    correctFactors.forEach(v -> IntervalFunction.ofRandomized(duration, v));
    correctFactors
        .forEach(v -> IntervalFunction.ofExponentialRandomBackoff(duration, multiplier, v));

    assertThat(true).isTrue();
}
 
Example 4
Source File: DataColumnTests.java    From java-datatable with Apache License 2.0 5 votes vote down vote up
@Test
public void testIterableDataColumnCreation() {
    List<String> data = List.of("AA", "BB", "CC");
    DataColumn<String> column = new DataColumn<>(String.class, "StringCol", data);

    assertEquals(column.data().length(), 3);
    assertEquals(column.data().get(1), "BB");
}
 
Example 5
Source File: IntervalFunctionTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRejectAttemptLessThenOne() {
    final List<IntervalFunction> fns = List.of(
        IntervalFunction.ofDefaults(),
        IntervalFunction.ofRandomized(),
        IntervalFunction.ofExponentialBackoff(),
        IntervalFunction.ofExponentialRandomBackoff()
    );

    final List<Try> tries = fns.map(fn -> Try.of(() -> fn.apply(0)));

    assertThat(tries.forAll(Try::isFailure)).isTrue();
    assertThat(tries.map(Try::getCause).forAll(t -> t instanceof IllegalArgumentException))
        .isTrue();
}
 
Example 6
Source File: VavrUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCreatesVavrList_thenCorrect() {
    List<Integer> intList = List.of(1, 2, 3);
    assertEquals(3, intList.length());
    assertEquals(new Integer(1), intList.get(0));
    assertEquals(new Integer(2), intList.get(1));
    assertEquals(new Integer(3), intList.get(2));
}
 
Example 7
Source File: Issue154Test.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void itShouldSerializeVavrListWithVavrModule() throws Exception {
    MyVavrClass myClass = new MyVavrClass();
    myClass.dates = List.of(new Date(1591221600000L), new Date(1591308000000L));

    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new VavrModule());

    String json = mapper.writeValueAsString(myClass);
    assertEquals("{\"dates\":[\"2020-06-04\",\"2020-06-05\"]}", json);
}
 
Example 8
Source File: PatronFixture.java    From library with MIT License 5 votes vote down vote up
static Patron regularPatronWith3_OverdueCheckoutsAt(LibraryBranchId libraryBranchId) {
    Map<LibraryBranchId, Set<BookId>> overdueCheckouts = new HashMap<>();
    overdueCheckouts.put(libraryBranchId, Set.of(anyBookId(), anyBookId(), anyBookId()));
    return new Patron(
            patronInformation(anyPatronId(), Regular),
            List.of(overdueCheckoutsRejectionPolicy),
            new OverdueCheckouts(overdueCheckouts),
            noHolds());
}
 
Example 9
Source File: CollectionsInteroperabilityUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenParams_whenVavrList_thenReturnJavaList() {
  List<String> vavrStringList = List.of("JAVA", "Javascript", "Scala");

  java.util.List<String> javaStringList = vavrStringList.toJavaList();
  assertTrue(javaStringList instanceof java.util.List);
}
 
Example 10
Source File: SimplePojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testListOfString() throws Exception {
    String src0 = "A";
    String src1 = "B";
    String src2 = "C";
    List<String> src = List.of(src0, src1, src2);
    String json = MAPPER.writeValueAsString(new ListOfString().setValue(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
    ListOfString restored = MAPPER.readValue(json, ListOfString.class);
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 11
Source File: PatronFixture.java    From library with MIT License 5 votes vote down vote up
public static Patron regularPatron(PatronId patronId) {
    return new Patron(
            patronInformation(patronId, Regular),
            List.of(onlyResearcherPatronsCanHoldRestrictedBooksPolicy),
            new OverdueCheckouts(new HashMap<>()),
            noHolds());
}
 
Example 12
Source File: ParameterizedPojoTest.java    From vavr-jackson with Apache License 2.0 5 votes vote down vote up
@Test
void testListOfString() throws Exception {
    String src0 = "A";
    String src1 = "B";
    String src2 = "C";
    List<String> src = List.of(src0, src1, src2);
    String json = MAPPER.writeValueAsString(new ParameterizedListPojo<>(src));
    Assertions.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
    ParameterizedListPojo<java.lang.String> restored =
            MAPPER.readValue(json, new TypeReference<ParameterizedListPojo<java.lang.String>>(){});
    Assertions.assertEquals(src, restored.getValue());
}
 
Example 13
Source File: CollectionAPIUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenParams_whenListAPI_thenCorrect() {

    List<String> list
      = List.of("Java", "PHP", "Jquery", "JavaScript", "JShell", "JAVA");

    List list1 = list.drop(2);
    assertFalse(list1.contains("Java") && list1.contains("PHP"));

    List list2 = list.dropRight(2);
    assertFalse(list2.contains("JAVA") && list2.contains("JShell"));

    List list3 = list.dropUntil(s -> s.contains("Shell"));
    assertEquals(list3.size(), 2);
    
    List list4 = list.dropWhile(s -> s.length() > 0);
    assertTrue(list4.isEmpty());

    List list5 = list.take(1);
    assertEquals(list5.single(), "Java");

    List list6 = list.takeRight(1);
    assertEquals(list6.single(), "JAVA");

    List list7 = list.takeUntil(s -> s.length() > 6);
    assertEquals(list7.size(), 3);

    List list8
      = list.distinctBy( (s1, s2) -> s1.startsWith(s2.charAt(0)+"") ? 0 : 1);
    assertEquals(list8.size(), 2);

    Iterator<List<String>> iterator = list.grouped(2);
    assertEquals(iterator.head().size(), 2);

    Map<Boolean, List<String>> map = list.groupBy(e -> e.startsWith("J"));
    assertEquals(map.size(), 2);
    assertEquals(map.get(false).get().size(), 1);
    assertEquals(map.get(true).get().size(), 5);

    String words = List.of("Boys", "Girls")
                     .intersperse("and")
                     .reduce((s1, s2) -> s1.concat( " " + s2 ))
                     .trim();
    
    assertEquals(words, "Boys and Girls");

}
 
Example 14
Source File: MixedTest.java    From vavr-jackson with Apache License 2.0 4 votes vote down vote up
@Test
void test5() throws IOException {
    Object src = List.of(List.of(1));
    String json = mapper().writer().writeValueAsString(src);
    Assertions.assertEquals(mapper().readValue(json, new TypeReference<List<List<?>>>() {}), src);
}
 
Example 15
Source File: DataTableTests.java    From java-datatable with Apache License 2.0 4 votes vote down vote up
private DataColumn<String> createStringColumn() {
    List<String> data = List.of("AA", "BB", "CC");
    return new DataColumn<>(String.class, "StringCol", data);
}
 
Example 16
Source File: DataColumnTests.java    From java-datatable with Apache License 2.0 4 votes vote down vote up
private DataColumn<String> createStringColumn() {
    List<String> data = List.of("AA", "BB", "CC");
    return new DataColumn<>(String.class, "StringCol", data);
}
 
Example 17
Source File: DataTableTests.java    From java-datatable with Apache License 2.0 4 votes vote down vote up
private DataColumn<Boolean> createBooleanColumn() {
    List<Boolean> data = List.of(true, false, true);
    return new DataColumn<>(Boolean.class, "BooleanCol", data);
}
 
Example 18
Source File: DataColumnCollectionTests.java    From java-datatable with Apache License 2.0 4 votes vote down vote up
private DataColumn<Integer> createIntegerColumn() {
    List<Integer> data = List.of(5, 7, 9);
    return new DataColumn<>(Integer.class, "IntegerCol", data);
}
 
Example 19
Source File: DataColumnCollectionTests.java    From java-datatable with Apache License 2.0 4 votes vote down vote up
private DataColumn<Boolean> createBooleanColumn() {
    List<Boolean> data = List.of(true, false, true);
    return new DataColumn<>(Boolean.class, "BooleanCol", data);
}
 
Example 20
Source File: PatronFixture.java    From library with MIT License 4 votes vote down vote up
private static Patron patronWithPolicy(PatronId patronId, PatronType type, PlacingOnHoldPolicy placingOnHoldPolicy) {
    return new Patron(patronInformation(patronId, type),
            List.of(placingOnHoldPolicy),
            new OverdueCheckouts(new HashMap<>()),
            noHolds());
}