List of usage examples for com.google.common.collect ListMultimap get
@Override List<V> get(@Nullable K key);
Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a List , instead of the java.util.Collection specified in the Multimap interface.
From source file:eu.esdihumboldt.cst.functions.core.join.IndexJoinHandler.java
/** * @see eu.esdihumboldt.hale.common.align.transformation.function.InstanceHandler#partitionInstances(eu.esdihumboldt.hale.common.instance.model.InstanceCollection, * java.lang.String,/*from ww w . j a v a2 s . c om*/ * eu.esdihumboldt.hale.common.align.transformation.engine.TransformationEngine, * com.google.common.collect.ListMultimap, java.util.Map, * eu.esdihumboldt.hale.common.align.transformation.report.TransformationLog) */ @Override public ResourceIterator<FamilyInstance> partitionInstances(InstanceCollection instances, String transformationIdentifier, TransformationEngine engine, ListMultimap<String, ParameterValue> transformationParameters, Map<String, String> executionParameters, TransformationLog log) throws TransformationException { if (transformationParameters == null || !transformationParameters.containsKey(PARAMETER_JOIN) || transformationParameters.get(PARAMETER_JOIN).isEmpty()) { throw new TransformationException("No join parameter defined"); } JoinHandler fallbackHandler = new JoinHandler(); InstanceIndexService indexService = serviceProvider.getService(InstanceIndexService.class); if (indexService == null) { log.info(MessageFormat.format("Index service not available, falling back to join handler {0}", fallbackHandler.getClass().getCanonicalName())); return fallbackHandler.partitionInstances(instances, transformationIdentifier, engine, transformationParameters, executionParameters, log); } JoinParameter joinParameter = transformationParameters.get(PARAMETER_JOIN).get(0).as(JoinParameter.class); String validation = joinParameter.validate(); if (validation != null) { throw new TransformationException("Join parameter invalid: " + validation); } List<TypeEntityDefinition> types = joinParameter.getTypes(); JoinDefinition joinDefinition = JoinUtil.getJoinDefinition(joinParameter); // remember instances of first type to start join afterwards Collection<ResolvableInstanceReference> startInstances = new LinkedList<ResolvableInstanceReference>(); List<Object> inputInstanceIds = new ArrayList<>(); try (ResourceIterator<Instance> it = instances.iterator()) { while (it.hasNext()) { Instance i = InstanceDecorator.getRoot(it.next()); // remember instances of first type if (i.getDefinition().equals(types.get(0).getDefinition())) { startInstances.add(new ResolvableInstanceReference(instances.getReference(i), instances)); } if (!Identifiable.is(i)) { log.info(MessageFormat.format( "At least one instance does not have an ID, falling back to join handler {0}", fallbackHandler.getClass().getCanonicalName())); return fallbackHandler.partitionInstances(instances, transformationIdentifier, engine, transformationParameters, executionParameters, log); } inputInstanceIds.add(Identifiable.getId(i)); } } return new IndexJoinIterator(startInstances, joinDefinition, indexService); }
From source file:com.google.gerrit.sshd.commands.ShowQueue.java
@Override protected void run() throws UnloggedFailure { maxCommandWidth = wide ? Integer.MAX_VALUE : columns - 8 - 12 - 12 - 4 - 4; stdout.print(String.format("%-8s %-12s %-12s %-4s %s\n", // "Task", "State", "StartTime", "", "Command")); stdout.print("------------------------------------------------------------------------------\n"); List<TaskInfo> tasks;//from w w w. ja v a2 s . c o m try { tasks = listTasks.apply(new ConfigResource()); } catch (AuthException e) { throw die(e); } boolean viewAll = currentUser.getCapabilities().canViewQueue(); long now = TimeUtil.nowMs(); if (groupByQueue) { ListMultimap<String, TaskInfo> byQueue = byQueue(tasks); for (String queueName : byQueue.keySet()) { WorkQueue.Executor e = workQueue.getExecutor(queueName); stdout.print(String.format("Queue: %s\n", queueName)); print(byQueue.get(queueName), now, viewAll, e.getCorePoolSize()); } } else { print(tasks, now, viewAll, 0); } }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericRaceLapsData.java
protected List<Pilot> getPilotOrder(ListMultimap<Integer, Pilot> raceOrder) { List<Pilot> pilotOrder = new ArrayList<Pilot>(scores.getPilots().size()); for (Integer lap : Ordering.natural().reverse().immutableSortedCopy(raceOrder.keySet())) { pilotOrder.addAll(raceOrder.get(lap)); }//from w ww . ja v a 2 s . co m return pilotOrder; }
From source file:org.apache.cassandra.service.BatchlogEndpointSelector.java
/** * @param endpoints nodes in the local datacenter, grouped by rack name * @return list of candidates for batchlog hosting. if possible these will be two nodes from different racks. */// w w w . ja va 2 s .c o m public Collection<InetAddress> chooseEndpoints(Multimap<String, InetAddress> endpoints) { // strip out dead endpoints and localhost ListMultimap<String, InetAddress> validated = ArrayListMultimap.create(); for (Map.Entry<String, InetAddress> entry : endpoints.entries()) { if (isValid(entry.getValue())) validated.put(entry.getKey(), entry.getValue()); } if (validated.size() <= 2) return validated.values(); if ((validated.size() - validated.get(localRack).size()) >= 2) { // we have enough endpoints in other racks validated.removeAll(localRack); } if (validated.keySet().size() == 1) { // we have only 1 `other` rack Collection<InetAddress> otherRack = Iterables.getOnlyElement(validated.asMap().values()); return Lists.newArrayList(Iterables.limit(otherRack, 2)); } // randomize which racks we pick from if more than 2 remaining Collection<String> racks; if (validated.keySet().size() == 2) { racks = validated.keySet(); } else { racks = Lists.newArrayList(validated.keySet()); Collections.shuffle((List) racks); } // grab a random member of up to two racks List<InetAddress> result = new ArrayList<>(2); for (String rack : Iterables.limit(racks, 2)) { List<InetAddress> rackMembers = validated.get(rack); result.add(rackMembers.get(getRandomInt(rackMembers.size()))); } return result; }
From source file:eu.esdihumboldt.hale.ui.functions.core.RegexAnalysisParameterPage.java
/** * @see eu.esdihumboldt.hale.ui.function.generic.pages.ParameterPage#setParameter(java.util.Set, * com.google.common.collect.ListMultimap) *//* ww w . j a v a 2 s . co m*/ @Override public void setParameter(Set<FunctionParameterDefinition> params, ListMultimap<String, ParameterValue> initialValues) { // this page is only for parameter value, ignore params if (initialValues == null) return; List<ParameterValue> regexValues = initialValues.get(PARAMETER_REGEX_PATTERN); List<ParameterValue> formatValues = initialValues.get(PARAMETER_OUTPUT_FORMAT); if (!regexValues.isEmpty() && !formatValues.isEmpty()) { initialRegexValue = regexValues.get(0); initialOutformatValue = formatValues.get(0); setPageComplete(true); } }
From source file:com.google.gerrit.server.git.GroupCollector.java
@VisibleForTesting GroupCollector(ListMultimap<ObjectId, PatchSet.Id> patchSetsBySha, ListMultimap<PatchSet.Id, String> groupLookup) { this(patchSetsBySha, new Lookup() { @Override// ww w .j a va 2s . co m public List<String> lookup(PatchSet.Id psId) { List<String> groups = groupLookup.get(psId); return !groups.isEmpty() ? groups : null; } }); }
From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PerfMonReportPreparationStrategy.java
private void createPlots(final File sourceDir, final File destDir, final ListMultimap<String, PerfAlyzerFile> byTypeAndHostMultimap) throws IOException { Map<String, NumberDataSet> globalDataSets = newHashMap(); for (String key : byTypeAndHostMultimap.keySet()) { List<PerfAlyzerFile> filesByType = byTypeAndHostMultimap.get(key); File destFile = new File(destDir, key); String[] split = split(key, SystemUtils.FILE_SEPARATOR, 2); String host = split[0];/*from w w w .j a va2 s . c om*/ String keyWithoutHost = split[1]; NumberDataSet dataSet = new NumberDataSet(); for (PerfAlyzerFile f : filesByType) { String type = f.getFileNameParts().get(1); List<SeriesPoint> dataList = readDataFile(new File(sourceDir, f.getFile().getPath()), Charsets.UTF_8, intNumberFormat); dataSet.addSeries(type, dataList); NumberDataSet globalDataSet = globalDataSets.get(keyWithoutHost); if (globalDataSet == null) { globalDataSet = new NumberDataSet(); globalDataSets.put(keyWithoutHost, globalDataSet); } globalDataSet.addSeries(host + ":" + type, dataList); } plotCreator.writePlotFile(destFile, AxisType.LINEAR, AxisType.LINEAR, RendererType.LINES, ChartDimensions.DEFAULT, dataRange, false, dataSet); } for (Entry<String, NumberDataSet> entry : globalDataSets.entrySet()) { NumberDataSet dataSet = entry.getValue(); File destFile = new File(destDir, "global" + SystemUtils.FILE_SEPARATOR + entry.getKey()); plotCreator.writePlotFile(destFile, AxisType.LINEAR, AxisType.LINEAR, RendererType.LINES, ChartDimensions.DEFAULT, dataRange, false, dataSet); } }
From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.InstructionHighlighter.CCallsDescription.java
@Override public Collection<CSpecialInstruction> visit(final ReilFunction reilCode, final ListMultimap<IAddress, INaviInstruction> instructionMap) { final Collection<CSpecialInstruction> instructions = new ArrayList<CSpecialInstruction>(); for (final ReilBlock block : reilCode.getGraph()) { for (final ReilInstruction reilInstruction : block) { if (ReilHelpers.isFunctionCall(reilInstruction)) { final List<INaviInstruction> nativeInstructions = instructionMap .get(ReilHelpers.toNativeAddress(reilInstruction.getAddress())); if (nativeInstructions != null) { for (final INaviInstruction naviInstruction : nativeInstructions) { instructions.add(new CSpecialInstruction(this, naviInstruction)); }/*from w ww . jav a 2 s . co m*/ } } } } return instructions; }
From source file:eu.esdihumboldt.cst.functions.inspire.Identifier.java
@Override protected Object evaluate(String transformationIdentifier, TransformationEngine engine, ListMultimap<String, PropertyValue> variables, String resultName, PropertyEntityDefinition resultProperty, Map<String, String> executionParameters, TransformationLog log) throws TransformationException, NoResultException { // get input//from w ww. jav a 2 s.c om PropertyValue input = variables.get(null).get(0); // source value as string (will be written into localid) String source = input.getValueAs(String.class); // get all values for the parameters set by the parameter page String countryName = getParameterChecked(COUNTRY_PARAMETER_NAME).as(String.class); String providerName = getParameterChecked(DATA_PROVIDER_PARAMETER_NAME).as(String.class); String productName = getParameterChecked(PRODUCT_PARAMETER_NAME).as(String.class); String version = getParameterChecked(VERSION).as(String.class); String versionNilReason = getParameterChecked(VERSION_NIL_REASON).as(String.class); // definition of the target property (inspireId in this case) TypeDefinition targetType = resultProperty.getDefinition().getPropertyType(); // instance that can be changed (add property/instance as child) DefaultInstance inspireInstance = new DefaultInstance(targetType, null); // search for the child named "Identifier" PropertyDefinition inspireChildPropDef = Util.getChild("Identifier", targetType); // get type definition to create the "Identifier" instance TypeDefinition identType = inspireChildPropDef.getPropertyType(); DefaultInstance identInstance = new DefaultInstance(identType, null); PropertyDefinition identChildLocal = Util.getChild("localId", identType); PropertyDefinition identChildNamespace = Util.getChild("namespace", identType); PropertyDefinition identChildVersion = Util.getChild("versionId", identType); TypeDefinition versionType = identChildVersion.getPropertyType(); // 1.) // add the "localId" and "namespace" properties to the identifier // instance identInstance.addProperty(identChildLocal.getName(), source); identInstance.addProperty(identChildNamespace.getName(), getNamespace(countryName, providerName, productName, getTargetType())); DefaultInstance versionInstance = null; // 2.) // add the "nilReason" property to the version instance if (version == null || version.isEmpty()) { if (!versionNilReason.isEmpty()) { versionInstance = new DefaultInstance(versionType, null); PropertyDefinition versionIdChildVersion = Util.getChild("nilReason", versionType); versionInstance.addProperty(versionIdChildVersion.getName(), versionNilReason); } } else { versionInstance = new DefaultInstance(versionType, null); versionInstance.setValue(version); } // 3.) // add the "versionId" instance to the identifier instance if (versionInstance != null) { identInstance.addProperty(identChildVersion.getName(), versionInstance); } // 4.) // add the "identifier" instance to the inspireId instance inspireInstance.addProperty(inspireChildPropDef.getName(), identInstance); return inspireInstance; }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory.java
/** * The value is a sorted list with most recent version of index at the start */// w ww . j a va 2s. co m private Map<String, List<LocalIndexDir>> getIndexesPerPath() throws IOException { File[] dirs = indexRootDir.listFiles(LOCAL_DIR_FILTER); ListMultimap<String, LocalIndexDir> pathToDirMap = ArrayListMultimap.create(); for (File indexDir : dirs) { LocalIndexDir localIndexDir = new LocalIndexDir(indexDir); pathToDirMap.get(localIndexDir.getJcrPath()).add(localIndexDir); } Map<String, List<LocalIndexDir>> result = Maps.newHashMap(); for (Map.Entry<String, Collection<LocalIndexDir>> e : pathToDirMap.asMap().entrySet()) { List<LocalIndexDir> sortedDirs = new ArrayList<>(e.getValue()); Collections.sort(sortedDirs, Collections.<LocalIndexDir>reverseOrder()); result.put(e.getKey(), sortedDirs); } return result; }