List of usage examples for com.google.common.collect ImmutableListMultimap get
@Override
public ImmutableList<V> get(@Nullable K key)
From source file:io.crate.frameworks.mesos.config.Resources.java
@SuppressWarnings("RedundantIfStatement") public static boolean matches(List<Protos.Resource> offeredResources, Configuration configuration) { ImmutableListMultimap<String, Protos.Resource> resourceMap = Multimaps.index(offeredResources, RESOURCE_NAME);/*from w ww . ja va 2 s. c o m*/ Protos.Resource cpus1 = getOnlyElement(resourceMap.get("cpus")); if (cpus1.getScalar().getValue() < configuration.resCpus) { return false; } Protos.Resource mem = getOnlyElement(resourceMap.get("mem")); if (mem.getScalar().getValue() < configuration.resMemory) { return false; } ImmutableList<Protos.Resource> ports = resourceMap.get("ports"); if (!isPortInRange(configuration.httpPort, ports)) { return false; } if (!isPortInRange(configuration.transportPort, ports)) { return false; } return true; }
From source file:edu.cmu.cs.lti.ark.fn.evaluation.PrepareFullAnnotationJson.java
/** * Given predicted frame instances, including their frame elements, create a SemaforParseResult ready to be serialized to * JSON//from ww w. ja v a2 s .c om * * @param rankedScoredRoleAssignments Lines encoding predicted frames & FEs in the same format as the .sentences.frame.elements files */ public static SemaforParseResult getSemaforParse( Collection<RankedScoredRoleAssignment> rankedScoredRoleAssignments, List<String> tokens) { final ArrayList<Frame> frames = Lists.newArrayList(); // group by target span (assumes only one predicted frame per target span) final ImmutableListMultimap<Range0Based, RankedScoredRoleAssignment> predictionsByFrame = Multimaps .index(rankedScoredRoleAssignments, getTargetSpan); for (Range0Based targetSpan : predictionsByFrame.keySet()) { final List<RankedScoredRoleAssignment> predictionsForFrame = predictionsByFrame.get(targetSpan); final RankedScoredRoleAssignment first = predictionsForFrame.get(0); final NamedSpanSet target = makeSpan(first.targetSpan.start, first.targetSpan.end + 1, first.frame, tokens); final List<Frame.ScoredRoleAssignment> scoredRoleAssignments = Lists.newArrayList(); for (RankedScoredRoleAssignment ra : predictionsForFrame) { // extract frame elements final List<FrameElementAndSpan> frameElementsAndSpans = ra.fesAndSpans; final List<NamedSpanSet> frameElements = Lists.newArrayList(); for (FrameElementAndSpan frameElementAndSpan : frameElementsAndSpans) { final Range0Based range = frameElementAndSpan.span; frameElements.add(makeSpan(range.start, range.end + 1, frameElementAndSpan.name, tokens)); } scoredRoleAssignments.add(new Frame.ScoredRoleAssignment(ra.rank, ra.score, frameElements)); } frames.add(new Frame(target, scoredRoleAssignments)); } return new SemaforParseResult(frames, tokens); }
From source file:com.facebook.buck.java.intellij.IjModuleGraph.java
/** * Create all the modules we are capable of representing in IntelliJ from the supplied graph. * * @param targetGraph graph whose nodes will be converted to {@link IjModule}s. * @return map which for every BuildTarget points to the corresponding IjModule. Multiple * BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which * can't be prepresented in IntelliJ are missing from this mapping. *//*from w w w . j a va 2s . c o m*/ private static ImmutableMap<BuildTarget, IjModule> createModules(TargetGraph targetGraph, IjModuleFactory moduleFactory, final Function<Path, Path> basePathTransform) { ImmutableSet<TargetNode<?>> supportedTargets = FluentIterable.from(targetGraph.getNodes()) .filter(IjModuleFactory.SUPPORTED_MODULE_TYPES_PREDICATE).toSet(); ImmutableListMultimap<Path, TargetNode<?>> baseTargetPathMultimap = FluentIterable.from(supportedTargets) .index(new Function<TargetNode<?>, Path>() { @Override public Path apply(TargetNode<?> input) { return basePathTransform.apply(input.getBuildTarget().getBasePath()); } }); ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>(); for (Path baseTargetPath : baseTargetPathMultimap.keySet()) { ImmutableSet<TargetNode<?>> targets = FluentIterable.from(baseTargetPathMultimap.get(baseTargetPath)) .toSet(); IjModule module = moduleFactory.createModule(baseTargetPath, targets); for (TargetNode<?> target : targets) { moduleMapBuilder.put(target.getBuildTarget(), module); } } return moduleMapBuilder.build(); }
From source file:org.eclipse.sw360.components.summary.ComponentSummary.java
private Component makeDetailedExportSummary(Component document, ImmutableListMultimap<String, Release> fullReleases) { final ImmutableList<Release> releases = fullReleases.get(document.getId()); document.setReleases(releases);/*from w w w . j av a 2 s. com*/ return document; }
From source file:com.publictransitanalytics.scoregenerator.console.InteractiveNetworkConsole.java
private void showDeltas(final String route, final String beginningStopId, final String endingStopId) { final TransitStop beginningStop = stopIdMap.get(beginningStopId); final TransitStop endingStop = stopIdMap.get(endingStopId); final Set<EntryPoint> entryPoints = transitNetwork.getEntryPoints(beginningStop); final ImmutableListMultimap.Builder<Hop, Duration> durationsBuilder = ImmutableListMultimap.builder(); for (final EntryPoint entryPoint : entryPoints) { final Trip trip = entryPoint.getTrip(); if (trip.getRouteNumber().equals(route)) { final String tripId = trip.getTripId().toString(); final LocalDateTime beginningTime = entryPoint.getTime(); System.out.println(String.format("Trip %s %s", tripId, beginningTime)); TransitStop stop = beginningStop; LocalDateTime time = beginningTime; final Iterator<VehicleEvent> iterator = trip.getForwardIterator(entryPoint.getSequence()); while (iterator.hasNext() && !stop.equals(endingStop)) { final VehicleEvent nextScheduledLocation = iterator.next(); final LocalDateTime nextTime = nextScheduledLocation.getScheduledTime(); final TransitStop nextStop = nextScheduledLocation.getLocation(); final Duration delta = Duration.between(time, nextTime); final Hop hop = new Hop(stop, nextStop); durationsBuilder.put(hop, delta); System.out// w w w .j a va 2 s . co m .println(String.format("%s -> %s: %s", stop.getStopId(), nextStop.getStopId(), delta)); stop = nextStop; time = nextTime; } System.out.println("---"); } } final ImmutableListMultimap<Hop, Duration> hopDurations = durationsBuilder.build(); for (final Hop hop : hopDurations.keySet()) { final ImmutableList<Duration> durations = hopDurations.get(hop); final Duration min = durations.stream().min(Comparator.naturalOrder()).get(); final Duration max = durations.stream().max(Comparator.naturalOrder()).get(); final double averageSeconds = durations.stream() .collect(Collectors.averagingLong(Duration::getSeconds)); final Duration average = Duration.ofSeconds(Math.round(averageSeconds)); System.out.println(String.format("%s -> %s: min: %s max: %s avg: %s", hop.getStart().getStopId(), hop.getEnd().getStopId(), min, max, average)); } }
From source file:net.oneandone.maven.rules.common.AbstractFilterableRule.java
protected void compareDependenciesWithParentManagement(MavenProject project, Log log, DifferenceHandler differenceHandler) { if (project.getParent() != null) { List<Dependency> projectDependencies = project.getDependencies(); if (project.getDependencyManagement() != null) { projectDependencies.addAll(project.getDependencyManagement().getDependencies()); }//w ww. j a va 2 s.c o m ImmutableListMultimap<String, Dependency> parentProjectDependencies = RuleHelper .getManagedDependenciesAsMap(project.getParent()); for (Dependency dependency : projectDependencies) { ImmutableList<Dependency> parentDependencies = parentProjectDependencies .get(RuleHelper.getDependencyIdentifier(dependency)); if (parentDependencies != null && !isExcluded(dependency.getManagementKey())) { for (Dependency parentDependency : parentDependencies) { if (dependency.getManagementKey().equals(parentDependency.getManagementKey())) { if (!dependency.getVersion().equals(parentDependency.getVersion())) { differenceHandler.handleDifference(log, dependency, parentDependency); } break; } } } } } }
From source file:com.todoroo.astrid.service.StartupService.java
private void removeDuplicateTagMetadata(String uuid) { Criterion fullCriterion = Criterion.and(Metadata.KEY.eq(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(uuid), Metadata.DELETION_DATE.eq(0)); List<Metadata> metadatas = metadataDao.toList(fullCriterion); ImmutableListMultimap<Long, Metadata> metadataByTask = Multimaps.index(metadatas, Metadata::getTask); for (Long key : metadataByTask.keySet()) { ImmutableList<Metadata> tagData = metadataByTask.get(key); for (int i = 1; i < tagData.size(); i++) { metadataDao.delete(tagData.get(i).getId()); }//from ww w .ja va 2s . co m } }
From source file:com.facebook.buck.jvm.java.intellij.IjModuleGraph.java
/** * Create all the modules we are capable of representing in IntelliJ from the supplied graph. * * @param targetGraph graph whose nodes will be converted to {@link IjModule}s. * @return map which for every BuildTarget points to the corresponding IjModule. Multiple * BuildTarget can point to one IjModule (many:one mapping), the BuildTargets which * can't be prepresented in IntelliJ are missing from this mapping. *///from w ww . ja va 2 s . c om private static ImmutableMap<BuildTarget, IjModule> createModules(IjProjectConfig projectConfig, TargetGraph targetGraph, IjModuleFactory moduleFactory, final int minimumPathDepth) { final BlockedPathNode blockedPathTree = createAggregationHaltPoints(projectConfig, targetGraph); ImmutableListMultimap<Path, TargetNode<?, ?>> baseTargetPathMultimap = targetGraph.getNodes().stream() .filter(input -> IjModuleFactory.SUPPORTED_MODULE_DESCRIPTION_CLASSES .contains(input.getDescription().getClass())) .collect(MoreCollectors.toImmutableListMultimap(targetNode -> { Path path; Path basePath = targetNode.getBuildTarget().getBasePath(); if (targetNode.getConstructorArg() instanceof AndroidResourceDescription.Arg) { path = basePath; } else { path = simplifyPath(basePath, minimumPathDepth, blockedPathTree); } return path; }, targetNode -> targetNode)); ImmutableMap.Builder<BuildTarget, IjModule> moduleMapBuilder = new ImmutableMap.Builder<>(); for (Path baseTargetPath : baseTargetPathMultimap.keySet()) { ImmutableSet<TargetNode<?, ?>> targets = ImmutableSet .copyOf(baseTargetPathMultimap.get(baseTargetPath)); IjModule module = moduleFactory.createModule(baseTargetPath, targets); for (TargetNode<?, ?> target : targets) { moduleMapBuilder.put(target.getBuildTarget(), module); } } return moduleMapBuilder.build(); }
From source file:org.sonar.server.rule.DefaultRuleFinder.java
private Collection<org.sonar.api.rules.Rule> convertToRuleApi(DbSession dbSession, List<RuleDto> ruleDtos) { List<org.sonar.api.rules.Rule> rules = new ArrayList<>(); List<RuleKey> ruleKeys = FluentIterable.from(ruleDtos).transform(RuleDtoToKey.INSTANCE).toList(); List<RuleParamDto> ruleParamDtos = ruleDao.selectRuleParamsByRuleKeys(dbSession, ruleKeys); ImmutableListMultimap<Integer, RuleParamDto> ruleParamByRuleId = FluentIterable.from(ruleParamDtos) .index(RuleParamDtoToRuleId.INSTANCE); for (RuleDto rule : ruleDtos) { rules.add(toRule(rule, ruleParamByRuleId.get(rule.getId()))); }//from w ww .ja v a2s. c o m return rules; }
From source file:io.github.guaidaodl.pomodorotimer.ui.statistics.StatisticsFragment.java
@Override public void showLastSevenDaysTomatoStatistics(@NonNull ImmutableListMultimap<Long, Tomato> statistic) { checkNotNull(statistic);// w w w . j a v a 2 s.com int[] data = new int[7]; long time = DateUtils.getTodayStartCalendar().getTimeInMillis(); for (int i = 6; i >= 0; i--) { if (statistic.containsKey(time)) { data[i] = statistic.get(time).size(); } else { data[i] = 0; } time -= 24 * 60 * 60 * 1000; } mLineView.setData(data); }