List of usage examples for java.util Collection stream
default Stream<E> stream()
From source file:net.dv8tion.jda.core.entities.impl.JDAImpl.java
@Override public List<Guild> getMutualGuilds(Collection<User> users) { Checks.notNull(users, "users"); for (User u : users) { Checks.notNull(u, "All users"); }/*from w w w.j av a2 s. co m*/ return Collections.unmodifiableList(getGuilds().stream() .filter(guild -> users.stream().allMatch(guild::isMember)).collect(Collectors.toList())); }
From source file:dk.dma.ais.abnormal.analyzer.analysis.FreeFlowAnalysis.java
private void analyseFreeFlow(Collection<Track> allTracks, Track t0) { LOG.debug("Performing free flow analysis of " + t0.getMmsi()); final float cog0 = t0.getCourseOverGround(); final Position pc0 = centerOfVessel(t0.getPosition(), t0.getTrueHeading(), t0.getShipDimensionStern(), t0.getShipDimensionBow(), t0.getShipDimensionPort(), t0.getShipDimensionStarboard()); Set<Track> tracksSailingSameDirection = allTracks.stream().filter(t -> t.getMmsi() != t0.getMmsi()) .filter(t -> !isLastAisTrackingReportTooOld(t, t.getTimeOfLastPositionReport())) .filter(t -> absoluteDirectionalDifference(cog0, t.getCourseOverGround()) < dCog) .collect(Collectors.toSet()); if (tracksSailingSameDirection.size() > 0) { Ellipse ellipse = createEllipse(pc0, pc0, cog0, t0.getVesselLength(), t0.getVesselBeam(), t0.getShipDimensionStern(), t0.getShipDimensionStarboard(), xL, xB, 1); LOG.debug("ellipse: " + ellipse); List<Track> tracksSailingSameDirectionAndContainedInEllipse = tracksSailingSameDirection.stream() .filter(t -> ellipse.contains(centerOfVessel(t.getPosition(), t.getTrueHeading(), t.getShipDimensionStern(), t.getShipDimensionBow(), t.getShipDimensionPort(), t.getShipDimensionStarboard()))) .collect(Collectors.toList()); if (tracksSailingSameDirectionAndContainedInEllipse.size() > 0) { LOG.debug("There are " + tracksSailingSameDirectionAndContainedInEllipse.size() + " tracks inside ellipse of " + t0.getMmsi() + " " + t0.getShipName()); LOG.debug(new DateTime(t0.getTimeOfLastPositionReport()) + " " + "MMSI " + t0.getMmsi() + " " + t0.getShipName() + " " + t0.getShipType()); List<FreeFlowData.TrackInsideEllipse> tracksInsideEllipse = Lists.newArrayList(); for (Track t1 : tracksSailingSameDirectionAndContainedInEllipse) { if (!reportedRecently(t0, t1, t0.getTimeOfLastPositionReport())) { final Position pc1 = centerOfVessel(t1.getPosition(), t1.getTrueHeading(), t1.getShipDimensionStern(), t1.getShipDimensionBow(), t1.getShipDimensionPort(), t1.getShipDimensionStarboard()); try { tracksInsideEllipse.add(new FreeFlowData.TrackInsideEllipse(t1.clone(), pc1)); markReported(t0, t1, t0.getTimeOfLastPositionReport()); } catch (CloneNotSupportedException e) { LOG.error(e.getMessage(), e); }//from w w w . jav a 2 s.co m } } if (tracksInsideEllipse.size() > 0) { try { writeToCSVFile(new FreeFlowData(t0.clone(), pc0, tracksInsideEllipse)); } catch (CloneNotSupportedException e) { LOG.error(e.getMessage(), e); } } else { LOG.debug("Nothing new to report."); } } } }
From source file:com.thinkbiganalytics.feedmgr.nifi.NifiFlowCache.java
/** * Add connections to the cache/*from w w w. j a v a 2s.com*/ * * @param templateName a template name * @param connections connections to add to the cache */ public void updateConnectionMap(String templateName, Collection<ConnectionDTO> connections) { Map<String, NifiFlowConnection> connectionIdToConnectionMap = new HashMap<>(); if (connections != null) { connections.stream().forEach(connectionDTO -> { NifiFlowConnection nifiFlowConnection = NiFiFlowConnectionConverter .toNiFiFlowConnection(connectionDTO); if (nifiFlowConnection != null) { connectionIdToConnectionMap.put(nifiFlowConnection.getConnectionIdentifier(), nifiFlowConnection); } }); } this.connectionIdToConnectionMap.putAll(toConnectionIdMap(connectionIdToConnectionMap.values())); }
From source file:com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCacheImpl.java
private Map<String, NifiFlowProcessor> toProcessorIdMap(Collection<NifiFlowProcessor> processors) { return processors.stream().collect(Collectors.toMap(NifiFlowProcessor::getId, Function.identity())); }
From source file:com.thinkbiganalytics.feedmgr.nifi.NifiFlowCache.java
private void updateProcessorIdMaps(String processGroupId, Collection<NifiFlowProcessor> processors) { Map<String, String> processorIdToProcessGroupId = new HashMap<>(); Map<String, String> processorIdToProcessorName = new HashMap<>(); processors.stream().forEach(flowProcessor -> { processorIdToProcessGroupId.put(flowProcessor.getId(), processGroupId); processorIdToProcessorName.put(flowProcessor.getId(), flowProcessor.getName()); });//from w w w . j a v a 2 s. c o m this.processorIdToFeedProcessGroupId.putAll(processorIdToProcessGroupId); this.processorIdToProcessorName.putAll(processorIdToProcessorName); }
From source file:simx.profiler.info.actor.ActorInstanceInfoTopComponent.java
@Override public void resultChanged(LookupEvent le) { Collection<? extends ActorInstance> allSelectedTypes = result.allInstances(); if (!allSelectedTypes.isEmpty()) { allSelectedTypes.stream().forEach((type) -> { this.setData(type); });//from w w w.j a va2 s. c o m } else { System.out.println("No selection"); } }
From source file:com.epam.catgenome.manager.vcf.VcfManager.java
private VcfFilterInfo getFiltersInfo(FeatureReader<VariantContext> reader) throws IOException { VcfFilterInfo filterInfo = new VcfFilterInfo(); VCFHeader header = (VCFHeader) reader.getHeader(); Collection<VCFInfoHeaderLine> headerLines = header.getInfoHeaderLines(); Map<String, InfoItem> infoItems = headerLines.stream().filter(l -> !isExtendedInfoLine(l.getDescription())) // Exclude ANN from fields, .map(InfoItem::new) // we don't need it in the index .collect(Collectors.toMap(InfoItem::getName, i -> i)); filterInfo.setAvailableFilters(/*from ww w . jav a 2 s . c om*/ header.getFilterLines().stream().map(VCFSimpleHeaderLine::getID).collect(Collectors.toSet())); List<String> filtersWhiteList = getFilterWhiteList(); if (!filtersWhiteList.isEmpty()) { infoItems = scourFilterList(infoItems, filtersWhiteList); } filterInfo.setInfoItemMap(infoItems); return filterInfo; }
From source file:com.thinkbiganalytics.feedmgr.nifi.cache.NifiFlowCacheImpl.java
private Map<String, String> toProcessorIdFeedNameMap(Collection<NifiFlowProcessor> processors, String feedName) {// w w w. java 2s.c o m return processors.stream().collect(Collectors.toMap(NifiFlowProcessor::getId, name -> feedName)); }
From source file:com.epam.catgenome.manager.vcf.VcfManager.java
/** * Loads VCF FILTER and INFO data for a {@code Collection} of VCF files * @param vcfFileIds {@code Collection} specifies VCF files of interest * @return VCF FILTER and INFO data/*ww w . j a v a2s. c o m*/ * @throws IOException if an error with file system occurred */ public VcfFilterInfo getFiltersInfo(Collection<Long> vcfFileIds) throws IOException { VcfFilterInfo filterInfo = new VcfFilterInfo(); Map<String, InfoItem> infoItems = new HashMap<>(); Set<String> availableFilters = new HashSet<>(); for (Long fileId : vcfFileIds) { VcfFile vcfFile = vcfFileManager.loadVcfFile(fileId); Assert.notNull(vcfFile, getMessage(ERROR_VCF_ID_INVALID, fileId)); try (FeatureReader<VariantContext> reader = AbstractFeatureReader.getFeatureReader(vcfFile.getPath(), new VCFCodec(), false)) { VCFHeader header = (VCFHeader) reader.getHeader(); Collection<VCFInfoHeaderLine> headerLines = header.getInfoHeaderLines(); infoItems.putAll(headerLines.stream().filter(l -> !isExtendedInfoLine(l.getDescription())) // Exclude ANN from fields, .map(InfoItem::new) // we don't need it in the index .collect(Collectors.toMap(InfoItem::getName, i -> i))); availableFilters.addAll(header.getFilterLines().stream().map(VCFSimpleHeaderLine::getID) .collect(Collectors.toList())); } } List<String> filtersWhiteList = getFilterWhiteList(); if (!filtersWhiteList.isEmpty()) { infoItems = scourFilterList(infoItems, filtersWhiteList); } infoItems.put(FeatureIndexDao.FeatureIndexFields.IS_EXON.getFieldName(), new InfoItem(FeatureIndexDao.FeatureIndexFields.IS_EXON.getFieldName(), VCFHeaderLineType.Flag, "Defines if a variation is " + "located in exon region")); filterInfo.setInfoItemMap(infoItems); filterInfo.setAvailableFilters(availableFilters); return filterInfo; }