本文整理匯總了Java中java.util.stream.Stream.filter方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.filter方法的具體用法?Java Stream.filter怎麽用?Java Stream.filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.filter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getRelationEntityTypes
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Get stream of entity types to based on given strategy, relation row will be created for each one
*
* @param instance instance to get types from
* @return stream of entity types based on given strategy, relation row will be created for each one
*/
private Stream<Integer> getRelationEntityTypes(Instance instance) {
RelationSchemaStrategy strategy = config.getSchemaStrategy();
// in default, return all types
Stream<Integer> types = instance.getTypes().stream();
if (strategy == Predicates || strategy == SingleTable) {
// create row for one type only
types = types.limit(1);
} else if (config.isRootTypesOnly()) {
// filter out types that have a superclass to ensure relations are only created between root classes
if (instance.getTypes().size() > 1) {
types = types.filter(type -> !classGraph.hasSuperClasses(type));
}
}
return types;
}
示例2: getIntersectingStates
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* From a list of potential states, generate the list of intersecting
* states. This means all state intervals that actually cross the target
* timestamp.
*
* Note that we've already verified one of the start/end time for back/forth
* navigation when generating the potential states, this method only needs
* to check the other bound.
*/
private static List<StateRectangle> getIntersectingStates(List<StateRectangle> potentialStates,
long targetTimestamp, boolean forward) {
Stream<StateRectangle> intersectingStates = potentialStates.stream();
if (forward) {
intersectingStates = intersectingStates.filter(rect -> {
long start = rect.getStateInterval().getStartEvent().getTimestamp();
return (targetTimestamp >= start);
});
} else {
intersectingStates = intersectingStates.filter(rect -> {
long end = rect.getStateInterval().getEndEvent().getTimestamp();
return (targetTimestamp <= end);
});
}
return intersectingStates.collect(Collectors.toList());
}
示例3: classStream
import java.util.stream.Stream; //導入方法依賴的package包/類
Stream<PsiClass> classStream() {
if (context.isValid()) {
Stream<PsiClass> stream = StreamSupport.stream(
AnnotatedElementsSearch.searchPsiClasses(
context.getConfigAnnotationClass(),
GlobalSearchScope.allScope(context.getProject())).spliterator(),
false);
Predicate<PsiClass> filter = context.getFilter();
if (filter != null) {
stream = stream.filter(filter);
}
return stream;
} else {
return Stream.empty();
}
}
示例4: getSentences
import java.util.stream.Stream; //導入方法依賴的package包/類
Set<WordUsage> getSentences(List<Sentence> sentences, Function<Token, String> customMapper,
Predicate<String> customFilter) {
final Map<String, Set<String>> words = new HashMap<>();
for (Sentence sentence: sentences) {
Stream<String> wordsStream = sentence.getTokens().stream()
.filter(t -> t.getToken().matches(WORD_REGEX))
.filter(t -> getTags().contains(t.getTag()))
.filter(t -> !isUpperCase(t.getToken().charAt(0)))
.filter(t -> t.getProb() >= config.getVocabularyProb())
.map(customMapper);
if (customFilter != null) {
wordsStream = wordsStream.filter(customFilter);
}
wordsStream.forEach(word -> {
final Set<String> wordSentences = words.getOrDefault(word, new HashSet<>());
wordSentences.add(sentence.getSentence());
words.put(word, wordSentences);
});
}
return words.entrySet().stream()
.sorted(reverseOrder(comparingInt(e -> e.getValue().size())))
.map(e -> new WordUsage(e.getKey(), e.getValue())).collect(toSet());
}
示例5: retrieve
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public List<Movie> retrieve(Query query) throws PersistException {
List<Movie> movies = getMovies();
Stream<Movie> stream = movies.stream();
// filter
if (query.hasFilters() || query.getSearch() != null) {
stream = stream.filter(movie -> query.match(new JsonMatcher(movie.toJson())));
}
// sort
if ((query.getSort() != null && !"title".equals(query.getSort())) || query.isDescending()) {
stream = stream.sorted(new JsonableComparator(query, (j1, j2) -> {
return getSortTitle(j1).compareToIgnoreCase(getSortTitle(j2));
}));
}
// paginate
if (query.getStart() > 0)
stream = stream.skip(query.getStart());
if (query.getMax() != Query.MAX_ALL)
stream = stream.limit(query.getMax());
return stream.collect(Collectors.toList());
}
示例6: select
import java.util.stream.Stream; //導入方法依賴的package包/類
public static Stream<Activation> select(INeuron.ThreadState th, INeuron n, Integer rid, Range r, Range.Relation rr, InterprNode o, InterprNode.Relation or) {
Stream<Activation> results;
int s = th.activations.size();
Node node = n.node.get();
if(s == 0) return Stream.empty();
else if(s == 1) {
results = th.activations
.values()
.stream();
} else if(rid != null) {
Key bk = new Key(node, Range.MIN, rid, InterprNode.MIN);
Key ek = new Key(node, Range.MAX, rid, InterprNode.MAX);
if(th.activationsRid != null) {
results = th.activationsRid.subMap(bk, true, ek, true)
.values()
.stream();
} else return Stream.empty();
} else {
if(rr == null) {
results = th.activations.values()
.stream();
} else {
return getActivationsByRange(th, n, rid, r, rr, o, or);
}
}
return results.filter(act -> act.filter(node, rid, r, rr, o, or));
}
示例7: getLeader
import java.util.stream.Stream; //導入方法依賴的package包/類
public RaftServerImpl getLeader(RaftGroupId groupId) {
Stream<RaftServerImpl> stream = getServerAliveStream();
if (groupId != null) {
stream = stream.filter(s -> groupId.equals(s.getGroupId()));
}
return getLeader(stream);
}
示例8: testWeatherServiceLazy
import java.util.stream.Stream; //導入方法依賴的package包/類
@Test
public void testWeatherServiceLazy(){
/**
* Arrange WeatherService --> WeatherWebApi --> Countify --> FileRequest
*/
ICounter<String, CompletableFuture<Stream<String>>> req = Countify.of(new FileRequest()::getContent);
WeatherService api = new WeatherService(new WeatherWebApi(req::apply));
/**
* Act and Assert
*/
Stream<Location> locals = api.search("Porto").join();
assertEquals(1, req.getCount());
locals = locals.filter(l -> l.getLatitude() > 0 );
assertEquals(1, req.getCount());
/**
* When we get the first item from Stream we are instantiating a new
* Location object and thus requesting its last 30 days past weather.
*/
Location loc = locals.findFirst().get();
assertEquals(2, req.getCount());
Stream<WeatherInfo> infos = loc.getPastWeather(of(2017,02,01), of(2017,02,28));
assertEquals(3, req.getCount());
infos = infos.filter(info -> info.getDescription().toLowerCase().contains("sun"));
Stream<Integer> temps = infos.map(WeatherInfo::getTempC);
temps = temps.distinct();
assertEquals(3, req.getCount());
assertEquals(5, temps.count()); // iterates all items
assertEquals(3, req.getCount());
}
示例9: testWeatherServiceLazy
import java.util.stream.Stream; //導入方法依賴的package包/類
@Test
public void testWeatherServiceLazy(){
/**
* Arrange WeatherService --> WeatherWebApi --> Countify --> FileRequest
*/
ICounter<String, Stream<String>> req = Countify.of(new FileRequest()::getContent);
WeatherService api = new WeatherService(new WeatherWebApi(req::apply));
/**
* Act and Assert
*/
Stream<Location> locals = api.search("Porto");
assertEquals(1, req.getCount());
locals = locals.filter(l -> l.getLatitude() > 0 );
assertEquals(1, req.getCount());
Location loc = locals.findFirst().get();
assertEquals(1, req.getCount());
Stream<WeatherInfo> infos = loc.getPastWeather(of(2017,02,01), of(2017,02,28));
assertEquals(2, req.getCount());
infos = infos.filter(info -> info.getDescription().toLowerCase().contains("sun"));
Stream<Integer> temps = infos.map(WeatherInfo::getTempC);
temps = temps.distinct();
assertEquals(2, req.getCount());
/**
* When we iterate over the pastWeather then we make one more request
*/
assertEquals(5, temps.count()); // iterates all items
assertEquals(2, req.getCount());
}
示例10: getVertexFilter
import java.util.stream.Stream; //導入方法依賴的package包/類
private QueryBuilder getVertexFilter(EnumSet<ElasticsearchDocumentType> elementTypes) {
List<QueryBuilder> filters = new ArrayList<>();
List<String> edgeLabels = getParameters().getEdgeLabels();
String[] edgeLabelsArray = edgeLabels == null || edgeLabels.size() == 0
? null
: edgeLabels.toArray(new String[edgeLabels.size()]);
Stream<EdgeInfo> edgeInfos = stream(sourceVertex.getEdgeInfos(
direction,
edgeLabelsArray,
getParameters().getAuthorizations()
));
if (otherVertexId != null) {
edgeInfos = edgeInfos.filter(ei -> ei.getVertexId().equals(otherVertexId));
}
if (getParameters().getIds().size() > 0) {
edgeInfos = edgeInfos.filter(ei -> getParameters().getIds().contains(ei.getVertexId()));
}
String[] ids = edgeInfos.map(EdgeInfo::getVertexId).toArray(String[]::new);
if (elementTypes.contains(ElasticsearchDocumentType.VERTEX)) {
filters.add(QueryBuilders.idsQuery().addIds(ids));
}
if (elementTypes.contains(ElasticsearchDocumentType.VERTEX_EXTENDED_DATA)) {
for (String vertexId : ids) {
filters.add(
QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery(Elasticsearch5SearchIndex.ELEMENT_TYPE_FIELD_NAME, ElasticsearchDocumentType.VERTEX_EXTENDED_DATA.getKey()))
.must(QueryBuilders.termQuery(Elasticsearch5SearchIndex.EXTENDED_DATA_ELEMENT_ID_FIELD_NAME, vertexId)));
}
}
return orFilters(filters);
}
示例11: getElements
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public Object[] getElements(Object inputElement) {
Stream<PgObjLocation> stream = sqlEditor.getParser().getObjsForEditor(
sqlEditor.getEditorInput()).stream().filter(
e -> e.getAction() != StatementActions.NONE);
if (filterDangerous) {
stream = stream.filter(PgObjLocation::isDanger);
}
if (sortStatements) {
stream = stream.sorted((a,b) -> a.getObjName().compareTo(b.getObjName()));
}
return stream.map(Segments::new).toArray();
}
示例12: getJobsHistory
import java.util.stream.Stream; //導入方法依賴的package包/類
@Override
public List<JobHistory> getJobsHistory(final int count,final String operation,final String status) {
final List<JobHistory> result = new ArrayList<>(count);
NodeRef node = monitorStorage.getOrCreateMonitorJobsContainer();
final List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(node);
Collections.reverse(childAssocs);
Stream<ChildAssociationRef> streamChildrenAssocs = childAssocs.stream();
if (operation != null && !operation.isEmpty()) {
streamChildrenAssocs = streamChildrenAssocs.filter(ch -> ((String) nodeService.getProperty(ch.getChildRef(), MonitorModel.PROP_OPERATION)).equalsIgnoreCase(operation));
}
if (status != null && !status.isEmpty()) {
streamChildrenAssocs = streamChildrenAssocs.filter(ch -> ((String) nodeService.getProperty(ch.getChildRef(), MonitorModel.PROP_STATUS)).equalsIgnoreCase(status));
}
final List<ChildAssociationRef> childAssocsLimit = streamChildrenAssocs.limit(count).collect(Collectors.toList());
for (ChildAssociationRef child : childAssocsLimit) {
final NodeRef nodeRef = child.getChildRef();
final String nodeStatus = INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, MonitorModel.PROP_STATUS));
final Date date = INSTANCE.convert(Date.class, nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED));
final String operHist = INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, MonitorModel.PROP_OPERATION));
result.add(new JobHistory(operHist, nodeRef, nodeStatus, date));
}
return result;
}
開發者ID:Vitezslav-Sliz,項目名稱:tieto-alfresco-repository_monitor,代碼行數:29,代碼來源:MonitorSearchServiceImpl.java
示例13: meters
import java.util.stream.Stream; //導入方法依賴的package包/類
public Collection<Meter> meters() {
Stream<Entry<Id, Meter>> entryStream =
meterMap.entrySet().stream().filter(e -> e.getKey().getName().equals(name));
if (!tags.isEmpty()) {
entryStream = entryStream.filter(e -> {
final List<Tag> idTags = new ArrayList<>();
e.getKey().getTags().forEach(idTags::add);
return idTags.containsAll(tags);
});
}
return entryStream.map(Map.Entry::getValue)
.collect(Collectors.toList());
}
示例14: successfulCases
import java.util.stream.Stream; //導入方法依賴的package包/類
private static <R> Stream<Match<R>> successfulCases(
List<Matcher<R>> cases,
SortedSetMultimap<Class<?>, Indexed<Matcher<R>>> matchersByScopeType,
Object object
) {
Stream<Matcher<R>> potentialMatchersInOrder = potentialMatchersInOrder(cases, matchersByScopeType, object);
Stream<Match<R>> caseResults = potentialMatchersInOrder
.map(matcher -> matcher.match(object));
return caseResults.filter(Match::isPresent);
}
示例15: findNodes
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Returns an immutable set of nodes that can be used to instantiate the
* specified class. This method uses reflection to scan over all the classes
* fields and constructors to determine what dependencies every constructor
* comes with. If at least one constructor has the
* {@link Inject}-annotation, then only constructors with that annotation
* will be considered.
*
* @param <T> the type
* @param clazz the class to get nodes for
* @param qualifier the qualifier
*
* @return immutable set of nodes for the given class
*/
static <T> Set<Node<?>> findNodes(Class<T> clazz, String qualifier) {
// Determine if there are any members that need to be injected.
final Set<String> dependencies = unmodifiableSet(traverseFields(clazz)
.filter(f -> f.getAnnotation(Inject.class) != null)
.map(f -> ofNullable(f.getAnnotation(Inject.class))
.map(Inject::value).filter(StringUtil::notEmpty)
.orElseGet(() -> f.getType().getName())
).collect(toSet())
);
// If the specified type has at least one annotated constructor, we
// should only look at them. Otherwise, consider all constructors
// candidates for injection.
Stream<Constructor<?>> constructors = Stream.of(clazz.getDeclaredConstructors());
if (Stream.of(clazz.getDeclaredConstructors()).anyMatch(INJECTABLE)) {
constructors = constructors.filter(INJECTABLE);
}
// Compute the necessary dependencies for every constructor and add
// them to the map.
final Set<Node<?>> nodes = new LinkedHashSet<>();
constructors.forEach(constr -> {
final Set<String> deps = new HashSet<>(dependencies);
Stream.of(constr.getParameters())
.map(p -> ofNullable(p.getAnnotation(Inject.class))
.map(Inject::value).filter(StringUtil::notEmpty)
.orElseGet(() -> p.getType().getName())
).forEach(deps::add);
nodes.add(new NodeImpl<>(
qualifier,
unmodifiableSet(deps),
constr
));
});
return unmodifiableSet(nodes);
}