List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.sonar.batch.issue.tracking.FileHashes.java
public static FileHashes create(DefaultInputFile f) { final byte[][] hashes = new byte[f.lines()][]; FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() { @Override/* w w w .ja va 2s. c o m*/ public void consume(int lineIdx, @Nullable byte[] hash) { hashes[lineIdx - 1] = hash; } }); int size = hashes.length; Multimap<String, Integer> linesByHash = LinkedHashMultimap.create(); String[] hexHashes = new String[size]; for (int i = 0; i < size; i++) { String hash = hashes[i] != null ? Hex.encodeHexString(hashes[i]) : ""; hexHashes[i] = hash; // indices in array are shifted one line before linesByHash.put(hash, i + 1); } return new FileHashes(hexHashes, linesByHash); }
From source file:org.opendaylight.protocol.bgp.linkstate.attribute.LinkstateAttributeParser.java
private static Multimap<Integer, ByteBuf> getAttributesMap(final ByteBuf buffer) { /*/*from w ww .jav a 2 s. c o m*/ * e.g. IS-IS Area Identifier TLV can occur multiple times */ final Multimap<Integer, ByteBuf> map = HashMultimap.create(); while (buffer.isReadable()) { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); final ByteBuf value = buffer.readSlice(length); map.put(type, value); } return map; }
From source file:eu.tomylobo.routes.util.Ini.java
public static void saveLocation(Multimap<String, String> section, String format, Location location, boolean withYawPitch) { saveWorld(section, format, location.getWorld()); saveVector(section, format, location.getPosition()); if (withYawPitch) { section.put(String.format(format, "yaw"), String.valueOf(location.getYaw())); section.put(String.format(format, "pitch"), String.valueOf(location.getPitch())); }/*from w ww . j ava 2 s. co m*/ }
From source file:eu.esdihumboldt.util.resource.Resources.java
private static synchronized void init() { if (resolvers == null) { resolvers = new HashMap<String, Multimap<String, ResourceResolver>>(); // register resolvers for (ResolverConfiguration resolverConf : ResolverExtension.getInstance().getElements()) { String resourceType = resolverConf.getResourceTypeId(); Multimap<String, ResourceResolver> typeResolvers = resolvers.get(resourceType); if (typeResolvers == null) { typeResolvers = HashMultimap.create(); resolvers.put(resourceType, typeResolvers); }/*from ww w.ja v a 2 s . c o m*/ for (String host : resolverConf.getHosts()) { typeResolvers.put(host, resolverConf.getResourceResolver()); } } } }
From source file:org.apache.cassandra.metrics.ThreadPoolMetrics.java
public static Multimap<String, String> getJmxThreadPools(MBeanServerConnection mbeanServerConn) { try {//from w ww . j a v a 2s .c o m Multimap<String, String> threadPools = HashMultimap.create(); Set<ObjectName> threadPoolObjectNames = mbeanServerConn .queryNames(new ObjectName("org.apache.cassandra.metrics:type=ThreadPools,*"), null); for (ObjectName oName : threadPoolObjectNames) { threadPools.put(oName.getKeyProperty("path"), oName.getKeyProperty("scope")); } return threadPools; } catch (MalformedObjectNameException e) { throw new RuntimeException("Bad query to JMX server: ", e); } catch (IOException e) { throw new RuntimeException("Error getting threadpool names from JMX", e); } }
From source file:de.dennishoersch.web.css.parser.Parser.java
private static List<Style> parseStyles(String styles) { Multimap<String, Style> reduced = LinkedHashMultimap.create(); for (String style_ : _STYLE_SPLITTER.split(styles)) { Style style = new Style(style_); reduced.put(style.getName(), style); }/*from w ww. jav a2 s . com*/ // Wenn keiner der Werte zu einem Style ein Vendor-Prefix enthlt, dann // kann der letzte alle anderen berschreiben List<Style> result = Lists.newArrayList(); for (Map.Entry<String, Collection<Style>> entry : reduced.asMap().entrySet()) { Collection<Style> values = entry.getValue(); if (Iterables.any(values, HasVendorPrefixValue.INSTANCE)) { result.addAll(values); } else { result.add(Iterables.getLast(values)); } } return result; }
From source file:org.rf.ide.core.testdata.model.table.variables.names.VariableNamesSupport.java
public static Multimap<String, RobotToken> extractUnifiedVariables(final List<RobotToken> assignments, final VariableExtractor extractor, final String fileName) { final Multimap<String, RobotToken> vars = ArrayListMultimap.create(); for (final RobotToken token : assignments) { final MappingResult mappingResult = extractor.extract(token, fileName); for (final VariableDeclaration variableDeclaration : mappingResult.getCorrectVariables()) { vars.put(extractUnifiedVariableName(variableDeclaration.asToken().getText()), variableDeclaration.asToken()); }// w w w . j a v a 2 s.co m } return vars; }
From source file:org.apache.crunch.lib.Quantiles.java
private static <V> Collection<Pair<Double, V>> findQuantiles(Iterator<V> sortedCollectionIterator, long collectionSize, List<Double> quantiles) { Collection<Pair<Double, V>> output = Lists.newArrayList(); Multimap<Long, Double> quantileIndices = ArrayListMultimap.create(); for (double quantile : quantiles) { long idx = Math.max((int) Math.ceil(quantile * collectionSize) - 1, 0); quantileIndices.put(idx, quantile); }//from w ww . j a va2 s .c om long index = 0; while (sortedCollectionIterator.hasNext()) { V value = sortedCollectionIterator.next(); if (quantileIndices.containsKey(index)) { for (double quantile : quantileIndices.get(index)) { output.add(Pair.of(quantile, value)); } } index++; } return output; }
From source file:dmg.util.command.AnnotatedCommandUtils.java
/** * Returns the option fields grouped by category of a given command class. *//*from w ww.java 2 s .c o m*/ public static Multimap<String, Field> getOptionsByCategory(Class<?> clazz) { Multimap<String, Field> options = TreeMultimap.create(Ordering.natural(), Ordering.natural().onResultOf(GET_NAME)); for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { for (Field field : c.getDeclaredFields()) { Option option = field.getAnnotation(Option.class); if (option != null) { options.put(option.category(), field); } CommandLine cmd = field.getAnnotation(CommandLine.class); if (cmd != null) { options.put(cmd.category(), field); } } } return options; }
From source file:org.fenixedu.academic.ui.struts.action.resourceAllocationManager.SearchOccupationsDA.java
private static Multimap<Occupation, Interval> getEventSpaceOccupations(Space space, Interval searchInterval) { Multimap<Occupation, Interval> result = HashMultimap.create(); for (Occupation occupation : space.getOccupationSet()) { for (Interval occupationInterval : occupation.getIntervals()) { if (occupationInterval.overlaps(searchInterval)) { result.put(occupation, occupationInterval); }// ww w .j av a2 s. c o m } } return result; }