当前位置: 首页>>代码示例>>Java>>正文


Java Stream.of方法代码示例

本文整理汇总了Java中java.util.stream.Stream.of方法的典型用法代码示例。如果您正苦于以下问题:Java Stream.of方法的具体用法?Java Stream.of怎么用?Java Stream.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.stream.Stream的用法示例。


在下文中一共展示了Stream.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllocatedResources

import java.util.stream.Stream; //导入方法依赖的package包/类
<T> Stream<ContinuousResource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls) {
    Set<ContinuousResource> children = getChildResources(parent);
    if (children.isEmpty()) {
        return Stream.of();
    }

    return children.stream()
            .filter(x -> x.id().equals(parent.child(cls)))
            // we don't use cascading simple predicates like follows to reduce accesses to consistent map
            // .filter(x -> continuousConsumers.containsKey(x.id()))
            // .filter(x -> continuousConsumers.get(x.id()) != null)
            // .filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty());
            .filter(resource -> {
                Versioned<ContinuousResourceAllocation> allocation = consumers.get(resource.id());
                if (allocation == null) {
                    return false;
                }
                return !allocation.value().allocations().isEmpty();
            });
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:ConsistentContinuousResourceSubStore.java

示例2: of

import java.util.stream.Stream; //导入方法依赖的package包/类
/**
 * Returns a header to describe the column with the specified properties
 * @param key           the column key
 * @param type          the data type for column
 * @param <C>           the column type
 * @return              the newly created header
 */
static <C> DataFrameHeader<C> of(C key, Class<?> type) {
    return new DataFrameHeader<C>() {
        @Override
        public int size() {
            return 1;
        }
        @Override
        public Stream<C> keys() {
            return Stream.of(key);
        }
        @Override
        public Class<?> type(C colKey) {
            return type;
        }
    };
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:24,代码来源:DataFrameHeader.java

示例3: should_stream_a_non_empty_stream_into_a_stream

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void should_stream_a_non_empty_stream_into_a_stream() {

    // Given
    Stream<String> strings = Stream.of("one", "two", "three", "four", "five", "six");

    // When
    Map<Integer, Stream<String>> map =
            strings.collect(
                    Collectors.groupingBy(
                            String::length,
                            CollectorsUtils.mapToStream()
                    )
            );

    // Then
    assertThat(map.size()).isEqualTo(3);
    assertThat(map.get(3).collect(toList())).containsExactly("one", "two", "six");
    assertThat(map.get(4).collect(toList())).containsExactly("four", "five");
    assertThat(map.get(5).collect(toList())).containsExactly("three");
}
 
开发者ID:JosePaumard,项目名称:collectors-utils,代码行数:22,代码来源:ToStreamTest.java

示例4: should_return_the_max_for_groupingBy_and_maxBy_on_a_non_empty_stream

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void should_return_the_max_for_groupingBy_and_maxBy_on_a_non_empty_stream() {

    // Given
    Stream<String> strings = Stream.of("one", "one", "two", "two", "two");

    Collector<String, ?, Optional<Map.Entry<String, Long>>> collector =
            CollectorsUtils.groupingByAndMaxBy(
                    identity(),
                    counting(),
                    Map.Entry.comparingByValue()
            );

    // When
    Optional<Map.Entry<String, Long>> result = strings.collect(collector);

    // Then
    assertThat(result.isPresent()).isTrue();
    assertThat(result.get()).isEqualTo(new AbstractMap.SimpleImmutableEntry<>("two", 3L));
}
 
开发者ID:JosePaumard,项目名称:collectors-utils,代码行数:21,代码来源:GroupingByAndMaxByTest.java

示例5: getFieldsUpToJpaOlingoEntity

import java.util.stream.Stream; //导入方法依赖的package包/类
/**
 * Extracts fields from the whole hierarchy.
 *
 * @param firstClass
 *         first class in the hierarchy
 * @return array of extracted fields
 */
public static Field[] getFieldsUpToJpaOlingoEntity(Class<?> firstClass) {
    Stream<Field> result = Stream.of(firstClass.getDeclaredFields());
    Class<?> superclass = firstClass.getSuperclass();
    if (!isLastClass(superclass)) {
        result = Stream.concat(result, Stream.of(getFieldsUpToJpaOlingoEntity(superclass)));
    }
    return result.toArray(Field[]::new);
}
 
开发者ID:mat3e,项目名称:olingo-jpa,代码行数:16,代码来源:ReflectionUtil.java

示例6: BiIndexedCacheColumnDecisionTreeTrainerInput

import java.util.stream.Stream; //导入方法依赖的package包/类
/**
 * Construct an input for {@link ColumnDecisionTreeTrainer}.
 *
 * @param cache Bi-indexed cache.
 * @param catFeaturesInfo Information about categorical feature in the form (feature index -> number of
 * categories).
 * @param samplesCnt Count of samples.
 * @param featuresCnt Count of features.
 */
public BiIndexedCacheColumnDecisionTreeTrainerInput(IgniteCache<BiIndex, Double> cache,
    Map<Integer, Integer> catFeaturesInfo, int samplesCnt, int featuresCnt) {
    super(cache,
        () -> IntStream.range(0, samplesCnt).mapToObj(s -> new BiIndex(s, featuresCnt)),
        e -> Stream.of(new IgniteBiTuple<>(e.getKey().row(), e.getValue())),
        DoubleStream::of,
        fIdx -> IntStream.range(0, samplesCnt).mapToObj(s -> new BiIndex(s, fIdx)),
        catFeaturesInfo,
        featuresCnt,
        samplesCnt);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:21,代码来源:BiIndexedCacheColumnDecisionTreeTrainerInput.java

示例7: testToOptionalNull

import java.util.stream.Stream; //导入方法依赖的package包/类
public void testToOptionalNull() {
  Stream<Object> stream = Stream.of((Object) null);
  try {
    stream.collect(MoreCollectors.toOptional());
    fail("Expected NullPointerException");
  } catch (NullPointerException expected) {
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:MoreCollectorsTest.java

示例8: gameStateMappings

import java.util.stream.Stream; //导入方法依赖的package包/类
private static Stream<Arguments> gameStateMappings() {
    return Stream.of(
            Arguments.of(DebugGameState.SHOW_MAP, Debug.DebugGameState.show_map),
            Arguments.of(DebugGameState.CONTROL_ENEMY, Debug.DebugGameState.control_enemy),
            Arguments.of(DebugGameState.FOOD, Debug.DebugGameState.food),
            Arguments.of(DebugGameState.FREE, Debug.DebugGameState.free),
            Arguments.of(DebugGameState.ALL_RESOURCES, Debug.DebugGameState.all_resources),
            Arguments.of(DebugGameState.GOD, Debug.DebugGameState.god),
            Arguments.of(DebugGameState.MINERALS, Debug.DebugGameState.minerals),
            Arguments.of(DebugGameState.GAS, Debug.DebugGameState.gas),
            Arguments.of(DebugGameState.COOLDOWN, Debug.DebugGameState.cooldown),
            Arguments.of(DebugGameState.TECH_TREE, Debug.DebugGameState.tech_tree),
            Arguments.of(DebugGameState.UPGRADE, Debug.DebugGameState.upgrade),
            Arguments.of(DebugGameState.FAST_BUILD, Debug.DebugGameState.fast_build));
}
 
开发者ID:ocraft,项目名称:ocraft-s2client,代码行数:16,代码来源:DebugGameStateTest.java

示例9: explorationStream

import java.util.stream.Stream; //导入方法依赖的package包/类
private Stream<Board> explorationStream(Predicate<Board> predicate) {
  // Currently using recursion and flatMap to descend, use Explorer::explore(Board board)
  // for a more efficient multicore approach.
  if (predicate.test(this)) {
    return Stream.concat(
        Stream.of(this),
        availableChoices()
            .parallel()
            .map(this::choose)
            .flatMap(chosenBoard -> chosenBoard.exploreWhile(predicate)));
  }
  return Stream.of();
}
 
开发者ID:sudhirj,项目名称:switchboard,代码行数:14,代码来源:ImmutableBoard.java

示例10: exampleSplitResults

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void exampleSplitResults() {
    Stream<String> inputs = Stream.of("6", "5", "NaN");

    Pair<List<Long>, List<String>> halvedNumbers = inputs
            .map(tryTo(Long::parseLong, Exception::toString))
            .map(attempt(x -> x % 2 == 0 ? success(x / 2) : failure(x + " is odd")))
            .collect(split());

    assertThat(halvedNumbers.left, hasItems(3L));
    assertThat(halvedNumbers.right, hasItems("java.lang.NumberFormatException: For input string: \"NaN\"", "5 is odd"));
}
 
开发者ID:unruly,项目名称:control,代码行数:14,代码来源:ResultsTest.java

示例11: getCurrentState

import java.util.stream.Stream; //导入方法依赖的package包/类
@Procedure(value = "graph.versioner.get.current.state", mode = DEFAULT)
@Description("graph.versioner.get.current.state(entity) - Get the current State node for the given Entity.")
public Stream<NodeOutput> getCurrentState(
        @Name("entity") Node entity) {

    return Stream.of(Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
.map(Relationship::getEndNode).map(NodeOutput::new).orElse(null));
}
 
开发者ID:h-omer,项目名称:neo4j-versioner-core,代码行数:9,代码来源:Get.java

示例12: validateJobDependency

import java.util.stream.Stream; //导入方法依赖的package包/类
private Stream<String> validateJobDependency(Path jobSpecDir, JobDependencyConfiguration jobDependencyConfiguration) {
    final Path sourcePath = jobSpecDir.resolve(jobDependencyConfiguration.getSource());

    if (sourcePath.toFile().exists()) {
        return Stream.empty();
    } else return Stream.of(sourcePath + ": dependency does not exist");
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:8,代码来源:ValidateSpecCommand.java

示例13: goodStringParsableAndResult

import java.util.stream.Stream; //导入方法依赖的package包/类
static Stream<Arguments> goodStringParsableAndResult() {
    return Stream.of(
        Arguments.of("2017-04-04T12:12:12", Collections.singletonList(LocalDateTime.of(2017, 4, 4, 12, 12, 12))),
        Arguments.of("2017-04-04T12:12:12,2017-05-04T12:17:12,2017-12-25T12:15", Arrays.asList(
            LocalDateTime.of(2017, 4, 4, 12, 12, 12),
            LocalDateTime.of(2017, 5, 4, 12, 17, 12),
            LocalDateTime.of(2017, 12, 25, 12, 15)
        ))
    );
}
 
开发者ID:Blackdread,项目名称:filter-sort-jooq-api,代码行数:11,代码来源:FilterMultipleValueParserDateTimeTest.java

示例14: getBaseDate

import java.util.stream.Stream; //导入方法依赖的package包/类
@Override
Stream<LocalDate> getBaseDate(Element element) {
    Stream<LocalDate> result = Stream.empty();
    String text = StringUtils.defaultString(element.text());
    try {
        result = Stream.of(LocalDate.parse(text, formatter));
    } catch (DateTimeParseException e) {
        log.warn("Failed to parse base date from string: {}", text);
    }
    return result;

}
 
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:13,代码来源:SingleDayScraper.java

示例15: polygonsFrom

import java.util.stream.Stream; //导入方法依赖的package包/类
public static Stream<Polygon> polygonsFrom(Geometry g) {
    if (g instanceof Polygon) {
        return Stream.of((Polygon) g);
    }
    else if (g instanceof MultiPolygon) {
        Builder<Polygon> builder = Stream.builder();
        for (int i = 0; i < g.getNumGeometries(); i++) {
            builder.add((Polygon) g.getGeometryN(i));
        }
        return builder.build();
    }
    return Stream.empty();
}
 
开发者ID:Mappy,项目名称:fpm,代码行数:14,代码来源:PolygonsUtils.java


注:本文中的java.util.stream.Stream.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。