本文整理匯總了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();
});
}
示例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;
}
};
}
示例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");
}
示例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));
}
示例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);
}
示例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) {
}
}
示例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));
}
示例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();
}
示例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"));
}
示例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));
}
示例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");
}
示例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)
))
);
}
示例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;
}
示例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();
}