Java Code Examples for java.util.stream.Stream#of()

The following examples show how to use java.util.stream.Stream#of() . These examples are extracted from open source projects. 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
@SuppressWarnings("unused")
private static Stream<Arguments> emails() {
  return Stream.of(
      Arguments.of("[email protected]", true),
      Arguments.of("[email protected]", true),
      Arguments.of("[email protected]", true),
      Arguments.of("[email protected]", true),
      Arguments.of("emailexample", false),
      Arguments.of("[email protected]", false),
      Arguments.of("[email protected]", false),
      Arguments.of("[email protected]", false),
      Arguments.of("[email protected]", false),
      Arguments.of("[email protected]", false),
      Arguments.of("[email protected]", false)
  );
}
 
Example 2
Source Project: incubator-tuweni   File: UInt384Test.java    License: Apache License 2.0 6 votes vote down vote up
private static Stream<Arguments> multiplyModProvider() {
  return Stream
      .of(
          Arguments.of(v(0), v(5), UInt384.valueOf(2), v(0)),
          Arguments.of(v(2), v(3), UInt384.valueOf(7), v(6)),
          Arguments.of(v(2), v(3), UInt384.valueOf(6), v(0)),
          Arguments.of(v(2), v(0), UInt384.valueOf(6), v(0)),
          Arguments
              .of(
                  hv(
                      "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"),
                  v(2),
                  UInt384.MAX_VALUE,
                  hv(
                      "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD")));
}
 
Example 3
Source Project: incubator-tuweni   File: UInt256Test.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> powUInt256Provider() {
  return Stream
      .of(
          Arguments.of(v(0), UInt256.valueOf(2), v(0)),
          Arguments.of(v(2), UInt256.valueOf(2), v(4)),
          Arguments.of(v(2), UInt256.valueOf(8), v(256)),
          Arguments.of(v(3), UInt256.valueOf(3), v(27)),
          Arguments
              .of(
                  hv("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F0F0"),
                  UInt256.valueOf(3),
                  hv("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF2A920E119A2F000")));
}
 
Example 4
@Test
public void headAndTailTest(){
    Stream<String> s = Stream.of("hello","world");
    Iterator<String> it = s.iterator();
    String head = it.next();
    Stream<String> tail = Streams.stream(it);
    tail.forEach(System.out::println);
}
 
Example 5
@SuppressWarnings("unused")
private static Stream<Arguments> generateRandomRecords() {
    return Stream.of(
        // From https://stackoverflow.com/questions/45581437/how-to-specify-converter-for-default-value-in-avro-union-logical-type-fields
        Arguments.of("BuggyRecord.avsc"),
        // From https://github.com/davidmc24/gradle-avro-plugin/issues/120
        Arguments.of("Messages.avsc")
    );
}
 
Example 6
private static Stream<Arguments> useCases()
{
  return Stream.of(Arguments.of(new String[]{"3", "+", "5"}, 8),
      Arguments.of(new String[]{"3", "-", "5"}, -2),
      Arguments.of(new String[]{"3", "*", "5"}, 15),
      Arguments.of(new String[]{"15", "/", "3"}, 5),
      Arguments.of(new String[]{"9", "+", "3"}, 12),
      Arguments.of(new String[]{"1", "+", "2", "*", "3", "-", "4", "/", "5"}, 1));
}
 
Example 7
Source Project: incubator-tuweni   File: TomlTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> stringSupplier() {
  return Stream
      .of(
          Arguments.of("foo = \"\"", ""),
          Arguments.of("foo = \"\\\"\"", "\""),
          Arguments
              .of("foo = \"bar \\b \\f \\n \\\\ \\u0053 \\U0010FfFf baz\"", "bar \b \f \n \\ S \uDBFF\uDFFF baz"),
          Arguments.of("foo = \"\"\"\"\"\"", ""),
          Arguments.of("foo = \"\"\"  foo\nbar\"\"\"", "  foo" + System.lineSeparator() + "bar"),
          Arguments.of("foo = \"\"\"\n  foobar\"\"\"", "  foobar"),
          Arguments.of("foo = \"\"\"\n  foo\nbar\"\"\"", "  foo" + System.lineSeparator() + "bar"),
          Arguments.of("foo = \"\"\"\\n  foo\nbar\"\"\"", "\n  foo" + System.lineSeparator() + "bar"),
          Arguments
              .of(
                  "foo = \"\"\"\n\n  foo\nbar\"\"\"",
                  System.lineSeparator() + "  foo" + System.lineSeparator() + "bar"),
          Arguments.of("foo = \"\"\"  foo \\  \nbar\"\"\"", "  foo " + System.lineSeparator() + "bar"),
          Arguments.of("foo = \"\"\"  foo \\\nbar\"\"\"", "  foo " + System.lineSeparator() + "bar"),
          Arguments.of("foo = \"\"\"  foo \\       \nbar\"\"\"", "  foo " + System.lineSeparator() + "bar"),
          Arguments.of("foo = \"foobar#\" # comment", "foobar#"),
          Arguments.of("foo = \"foobar#\"", "foobar#"),
          Arguments.of("foo = \"foo \\\" bar #\" # \"baz\"", "foo \" bar #"),
          Arguments.of("foo = ''", ""),
          Arguments.of("foo = '\"'", "\""),
          Arguments.of("foo = 'foobar \\'", "foobar \\"),
          Arguments.of("foo = '''foobar \n'''", "foobar " + System.lineSeparator()),
          Arguments.of("foo = '''\nfoobar \n'''", "foobar " + System.lineSeparator()),
          Arguments.of("foo = '''\nfoobar \\    \n'''", "foobar \\    " + System.lineSeparator()),
          Arguments.of("# I am a comment. Hear me roar. Roar.\nfoo = \"value\" # Yeah, you can do this.", "value"),
          Arguments
              .of(
                  "foo = \"I'm a string. \\\"You can quote me\\\". Name\\tJos\\u00E9\\nLocation\\tSF.\"",
                  "I'm a string. \"You can quote me\". Name\tJosé\nLocation\tSF."),
          Arguments
              .of(
                  "foo=\"\"\"\nRoses are red\nViolets are blue\"\"\"",
                  "Roses are red" + System.lineSeparator() + "Violets are blue"));
}
 
Example 8
Source Project: mug   File: BiStreamTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test public void testGroupingBy_withMapperAndReducer_twoElementsDifferentGroups() {
  Stream<String> inputs = Stream.of("foo", "blah");
  assertKeyValues(
          inputs
              .collect(BiStream.groupingBy(s -> s.charAt(0), String::length, Integer::sum)))
      .containsExactly('f', 3, 'b', 4)
      .inOrder();
}
 
Example 9
Source Project: incubator-tuweni   File: TomlTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> floatSupplier() {
  // @formatter:off
  return Stream.of(
      Arguments.of("foo = 0.0", 0D),
      Arguments.of("foo = 0E100", 0D),
      Arguments.of("foo = 0.00e+100", 0D),
      Arguments.of("foo = 0.00e-100", 0D),
      Arguments.of("foo = +0.0", 0D),
      Arguments.of("foo = -0.0", -0D),
      Arguments.of("foo = 0.000000000000000000000000000000000000000000"
          + "000000000000000000000000000000000000000000000000000000000"
          + "000000000000000000000000000000000000000000000000000000000"
          + "000000000000000000000000000000000000000000000000000000000"
          + "000000000000000000000000000000000000000000000000000000000"
          + "000000000000000000000000000000000000000000000000000000000", 0D),
      Arguments.of("foo = -0.0E999999999999999999999999999999999999999", -0D),
      Arguments.of("foo = 1.0", 1D),
      Arguments.of("foo = 43.55E34", 43.55E34D),
      Arguments.of("foo = 43.557_654E-34", 43.557654E-34D),
      Arguments.of("foo = inf", Double.POSITIVE_INFINITY),
      Arguments.of("foo = +inf", Double.POSITIVE_INFINITY),
      Arguments.of("foo = -inf", Double.NEGATIVE_INFINITY),
      Arguments.of("foo = nan", Double.NaN),
      Arguments.of("foo = +nan", Double.NaN),
      Arguments.of("foo = -nan", Double.NaN)
  );
  // @formatter:on
}
 
Example 10
@Test
public void should_correctly_count_the_elements_of_a_sized_stream() {
    // Given
    Stream<String> strings = Stream.of("1", "2", "3", "4", "5", "6", "7");
    int groupingFactor = 3;
    Stream<LongSummaryStatistics> stream = StreamsUtils.shiftingWindowSummarizingLong(strings, groupingFactor, Long::parseLong);

    // When
    long count = stream.count();

    // Then
    assertThat(count).isEqualTo(5L);
}
 
Example 11
Source Project: cava   File: UInt256Test.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> toMinimalBytesProvider() {
  return Stream.of(
      Arguments.of(hv("0x00"), Bytes.EMPTY),
      Arguments.of(hv("0x01000000"), Bytes.fromHexString("0x01000000")),
      Arguments.of(hv("0x0100000000"), Bytes.fromHexString("0x0100000000")),
      Arguments.of(hv("0xf100000000ab"), Bytes.fromHexString("0xf100000000ab")),
      Arguments.of(
          hv("0x0400000000000000000000000000000000000000000000000000f100000000ab"),
          Bytes.fromHexString("0x0400000000000000000000000000000000000000000000000000f100000000ab")));
}
 
Example 12
static Stream<Arguments> testParse() {
    return Stream.of(
    // @formatter:off
    // (1) Parse a filter with new syntax
    Arguments.of("configuration-filter-parser-test-input-01.json", new Expectation(Expectation.Type.JSON, "configuration-filter-parser-test-output-01.json")),
    // (2) Parse a filter with old syntax
    Arguments.of("configuration-filter-parser-test-input-02.json", new Expectation(Expectation.Type.JSON, "configuration-filter-parser-test-output-02.json")),
    // (3) Deployment namespace and resource namespace differ - filter should contain the resource one
    Arguments.of("configuration-filter-parser-test-input-03.json", new Expectation(Expectation.Type.JSON, "configuration-filter-parser-test-output-03.json"))
    // @formatter:on
    );
}
 
Example 13
private Stream<TimeSeriesCollection> create_tsdata_(int count) {
    final DateTime now = NOW.minusMinutes(count - 1);
    final Histogram hist = new Histogram(Stream.of(new Histogram.RangeWithCount(new Histogram.Range(0, 10), 10d), new Histogram.RangeWithCount(new Histogram.Range(100, 110), 10d)));

    return Stream.generate(
            new Supplier<Integer>() {
        private int idx = 0;

        @Override
        public Integer get() {
            return idx++;
        }
    })
            .map(new Function<Integer, TimeSeriesCollection>() {
                public TimeSeriesCollection apply(Integer i) {
                    return new SimpleTimeSeriesCollection(now.plusMinutes(i), Stream.of(
                            new ImmutableTimeSeriesValue(
                                    GroupName.valueOf(SimpleGroupPath.valueOf("foo", "bar")),
                                    singletonMap(MetricName.valueOf("x"), MetricValue.fromIntValue(i))),
                            new ImmutableTimeSeriesValue(
                                    GroupName.valueOf(SimpleGroupPath.valueOf("h", "i", "s", "t", "o", "g", "r", "a", "m")),
                                    singletonMap(MetricName.valueOf("x"), MetricValue.fromHistValue(hist)))
                    ));
                }
            })
            .limit(count);
}
 
Example 14
private static Stream<Arguments> subtractUInt64Provider() {
  return Stream
      .of(
          Arguments.of(v(1), UInt64.ZERO, v(1)),
          Arguments.of(v(5), UInt64.ZERO, v(5)),
          Arguments.of(v(2), UInt64.ONE, v(1)),
          Arguments.of(v(100), UInt64.valueOf(100), v(0)),
          Arguments.of(v(0), UInt64.ONE, Value.MAX_VALUE),
          Arguments.of(v(1), UInt64.valueOf(2), Value.MAX_VALUE),
          Arguments.of(Value.MAX_VALUE, UInt64.ONE, hv("0xFFFFFFFFFFFFFFFE")));
}
 
Example 15
Source Project: incubator-tuweni   File: MergeTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> mergeVectors() {
  return Stream
      .of(
          Arguments
              .of(
                  UInt32.fromHexString("0x3B0BB37D"),
                  UInt32.fromHexString("0xA0212004"),
                  UInt32.fromHexString("0x9BD26AB0"),
                  UInt32.fromHexString("0x3CA34321"),
                  "mul/add"),
          Arguments
              .of(
                  UInt32.fromHexString("0x10C02F0D"),
                  UInt32.fromHexString("0x870FA227"),
                  UInt32.fromHexString("0xD4F45515"),
                  UInt32.fromHexString("0x91C1326A"),
                  "xor/mul"),
          Arguments
              .of(
                  UInt32.fromHexString("0x24D2BAE4"),
                  UInt32.fromHexString("0x0FFB4C9B"),
                  UInt32.fromHexString("0x7FDBC2F2"),
                  UInt32.fromHexString("0x2EDDD94C"),
                  "rotl/xor"),
          Arguments
              .of(
                  UInt32.fromHexString("0xDA39E821"),
                  UInt32.fromHexString("0x089C4008"),
                  UInt32.fromHexString("0x8B6CD8C3"),
                  UInt32.fromHexString("0x8A81E396"),
                  "rotr/xor"));
}
 
Example 16
Source Project: incubator-tuweni   File: UInt32Test.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> powLongProvider() {
  return Stream
      .of(
          Arguments.of(v(0), 2, v(0)),
          Arguments.of(v(2), 2, v(4)),
          Arguments.of(v(2), 8, v(256)),
          Arguments.of(v(3), 3, v(27)),
          Arguments.of(hv("0xFFF0F0F0"), 3, hv("0x19A2F000")));
}
 
Example 17
Source Project: cava   File: BaseUInt64ValueTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Stream<Arguments> subtractUInt64Provider() {
  return Stream.of(
      Arguments.of(v(1), UInt64.ZERO, v(1)),
      Arguments.of(v(5), UInt64.ZERO, v(5)),
      Arguments.of(v(2), UInt64.ONE, v(1)),
      Arguments.of(v(100), UInt64.valueOf(100), v(0)),
      Arguments.of(v(0), UInt64.ONE, Value.MAX_VALUE),
      Arguments.of(v(1), UInt64.valueOf(2), Value.MAX_VALUE),
      Arguments.of(Value.MAX_VALUE, UInt64.ONE, hv("0xFFFFFFFFFFFFFFFE")));
}
 
Example 18
static Stream<String> attachmentNameProvider() {
    return Stream.of("Request", "Response");
}
 
Example 19
@Override
@SuppressWarnings( "unchecked" )
public Stream<Class<?>> types()
{
    return Stream.of( type );
}
 
Example 20
Source Project: james-project   File: DTOConverterTest.java    License: Apache License 2.0 4 votes vote down vote up
private static Stream<Arguments> allKnownTypes() {
    return Stream.of(
            Arguments.of(SECOND, SECOND_DTO),
            Arguments.of(FIRST, FIRST_DTO)
    );
}