List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:org.opendaylight.mdsal.dom.broker.ProducerLayout.java
private static BiMap<DOMDataTreeIdentifier, DOMDataTreeShardProducer> mapIdsToProducer( final Map<DOMDataTreeIdentifier, DOMDataTreeShard> shardMap) { final Multimap<DOMDataTreeShard, DOMDataTreeIdentifier> shardToId = ArrayListMultimap.create(); // map which identifier belongs to which shard for (final Entry<DOMDataTreeIdentifier, DOMDataTreeShard> entry : shardMap.entrySet()) { shardToId.put(entry.getValue(), entry.getKey()); }// w w w . j a va 2 s . co m final Builder<DOMDataTreeIdentifier, DOMDataTreeShardProducer> idToProducerBuilder = ImmutableBiMap .builder(); for (final Entry<DOMDataTreeShard, Collection<DOMDataTreeIdentifier>> entry : shardToId.asMap() .entrySet()) { if (entry.getKey() instanceof WriteableDOMDataTreeShard) { //create a single producer for all prefixes in a single shard final DOMDataTreeShardProducer producer = ((WriteableDOMDataTreeShard) entry.getKey()) .createProducer(entry.getValue()); // id mapped to producers for (final DOMDataTreeIdentifier id : entry.getValue()) { idToProducerBuilder.put(id, producer); } } else { LOG.error("Unable to create a producer for shard that's not a WriteableDOMDataTreeShard"); } } return idToProducerBuilder.build(); }
From source file:org.lanternpowered.server.world.chunk.LanternLoadingTicketIO.java
static void save(Path worldFolder, Set<LanternLoadingTicket> tickets) throws IOException { final Path file = worldFolder.resolve(TICKETS_FILE); if (!Files.exists(file)) { Files.createFile(file);//from www . j a va2 s . c o m } final Multimap<String, LanternLoadingTicket> sortedByPlugin = HashMultimap.create(); for (LanternLoadingTicket ticket : tickets) { sortedByPlugin.put(ticket.getPlugin(), ticket); } final List<DataView> ticketHolders = new ArrayList<>(); for (Entry<String, Collection<LanternLoadingTicket>> entry : sortedByPlugin.asMap().entrySet()) { final Collection<LanternLoadingTicket> tickets0 = entry.getValue(); final List<DataView> ticketEntries = new ArrayList<>(); for (LanternLoadingTicket ticket0 : tickets0) { final DataContainer ticketData = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED); ticketData.set(TICKET_TYPE, ticket0 instanceof EntityLoadingTicket ? TYPE_ENTITY : TYPE_NORMAL); final int numChunks = ticket0.getNumChunks(); // Store the list depth for backwards compatible or something, // the current forge version doesn't use it either ticketData.set(CHUNK_LIST_DEPTH, (byte) Math.min(numChunks, 127)); // Storing the chunks number, this number is added by us ticketData.set(CHUNK_NUMBER, numChunks); if (ticket0 instanceof PlayerLoadingTicket) { final PlayerLoadingTicket ticket1 = (PlayerLoadingTicket) ticket0; // This is a bit strange, since it already added, // but if forge uses it... ticketData.set(MOD_ID, entry.getKey()); ticketData.set(PLAYER_UUID, ticket1.getPlayerUniqueId().toString()); } if (ticket0.extraData != null) { ticketData.set(MOD_DATA, ticket0.extraData); } if (ticket0 instanceof EntityChunkLoadingTicket) { final EntityChunkLoadingTicket ticket1 = (EntityChunkLoadingTicket) ticket0; ticket1.getOrCreateEntityReference().ifPresent(ref -> { final Vector2i position = ref.getChunkCoords(); final UUID uniqueId = ref.getUniqueId(); ticketData.set(CHUNK_X, position.getX()); ticketData.set(CHUNK_Z, position.getY()); ticketData.set(ENTITY_UUID_MOST, uniqueId.getMostSignificantBits()); ticketData.set(ENTITY_UUID_LEAST, uniqueId.getLeastSignificantBits()); }); } ticketEntries.add(ticketData); } ticketHolders.add(DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED) .set(HOLDER_NAME, entry.getKey()).set(TICKETS, ticketEntries)); } final DataContainer dataContainer = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED) .set(HOLDER_LIST, ticketHolders); NbtStreamUtils.write(dataContainer, Files.newOutputStream(file), true); }
From source file:org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper.java
/** * Gets a map from event name to a collection of field names from a * collection of event types// w w w .jav a 2 s .co m * * @param eventTypes * an iterable collection of ITmfEventTypes * @return a set of the names of these events, if some event names are * clashing they will only appear once * @since 2.0 */ public static Multimap<@NonNull String, @NonNull String> getEventFieldNames( Iterable<@NonNull ? extends ITmfEventType> eventTypes) { Multimap<@NonNull String, @NonNull String> retMap = HashMultimap.create(); eventTypes.forEach(eventType -> { Collection<String> collection = eventType.getFieldNames(); if (collection != null) { collection.forEach(field -> { if (field != null) { retMap.put(eventType.getName(), field); } }); } }); return retMap; }
From source file:se.curity.examples.oauth.FilterHelper.java
static ImmutableMultimap<String, String> initParamsMapFrom(FilterConfig config) { Multimap<String, String> result = Multimaps.newListMultimap(new LinkedHashMap<>(), ArrayList::new); Enumeration<?> names = config.getInitParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement().toString(); if (config.getInitParameter(name) != null) { result.put(name, config.getInitParameter(name)); }//from w ww . j av a 2 s . c om } return ImmutableMultimap.copyOf(result); }
From source file:org.fenixedu.academic.domain.person.HumanName.java
public static String capitalize(final String str, Set<String> exceptions, final String... delimiters) { if (Strings.isNullOrEmpty(str)) { return str; }//ww w . j a v a2 s . c om Multimap<Integer, String> exceptionBySize = HashMultimap.create(); for (String exception : exceptions) { exceptionBySize.put(exception.length() + 1, " " + exception); } final char[] buffer = str.toCharArray(); boolean capitalizeNext = true; for (int i = 0; i < buffer.length; i++) { final char ch = buffer[i]; if (capitalizeNext) { buffer[i] = Character.toTitleCase(ch); capitalizeNext = false; } if (isDelimiterEnd(buffer, i, delimiters) && !isException(buffer, i, exceptionBySize)) { capitalizeNext = true; } } return new String(buffer); }
From source file:org.sonar.plugins.core.issue.tracking.FileHashes.java
public static FileHashes create(byte[][] hashes) { 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;/*from w w w.j a v a 2s .co m*/ // indices in array are shifted one line before linesByHash.put(hash, i + 1); } return new FileHashes(hexHashes, linesByHash); }
From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.junit.Junit4Util.java
private static Multimap<String, String> getMethodMap(String[] testMethods) { final Multimap<String, String> methods = HashMultimap.create(); for (String testMethod : testMethods) { if (!testMethod.trim().isEmpty()) { String testClass = getTestClass(testMethod); methods.put(testClass, testMethod); }/*from ww w . ja v a2s. com*/ } return methods; }
From source file:com.android.tools.idea.gradle.project.LibraryAttachments.java
public static void removeLibrariesAndStoreAttachments(@NotNull Project project) { LibraryTable libraryTable = ProjectLibraryTable.getInstance(project); LibraryTable.ModifiableModel model = libraryTable.getModifiableModel(); try {//from w ww . j a v a 2s . com Map<OrderRootType, Multimap<String, String>> attachmentsByType = Maps.newHashMap(); for (Library library : model.getLibraries()) { for (OrderRootType type : SUPPORTED_TYPES) { Multimap<String, String> attachments = ArrayListMultimap.create(); String name = library.getName(); if (name != null) { String[] urls = library.getUrls(type); for (String url : urls) { attachments.put(name, url); } } attachmentsByType.put(type, attachments); } model.removeLibrary(library); } project.putUserData(LIBRARY_ATTACHMENTS, new LibraryAttachments(project, attachmentsByType)); } finally { model.commit(); } }
From source file:de.unisb.cs.st.javalanche.rhino.coverage.FailureMatrix.java
public static FailureMatrix parseFile(File f) { Multimap<String, String> failureMatrix = new HashMultimap<String, String>(); List<String> linesFromFile = Io.getLinesFromFile(f); for (String line : linesFromFile) { String[] split = line.split(","); if (split.length > 0) { String failureId = split[0]; for (int i = 1; i < split.length; i++) { failureMatrix.put(split[i], failureId); logger.info("Put: " + failureId + " " + split[i]); }// w ww . jav a 2s . c om } } return new FailureMatrix(failureMatrix); }
From source file:cosmos.results.integration.CosmosIntegrationSetup.java
public static List<Record<?>> wikiToMultimap(MediaWikiType wiki) { Preconditions.checkNotNull(wiki);/*w ww. j av a 2 s . co m*/ List<PageType> pages = wiki.getPage(); List<Record<?>> mmap = Lists.newArrayList(); final String lang = wiki.getLang(); final ColumnVisibility viz = new ColumnVisibility(lang); long id = 0l; for (PageType page : pages) { Multimap<Column, RecordValue<?>> data = HashMultimap.create(); data.put(Column.create(PAGE_ID), RecordValue.create(page.getId().toString(), viz)); data.put(Column.create(PAGE_TITLE), RecordValue.create(page.getTitle(), viz)); if (!StringUtils.isBlank(page.getRestrictions())) { data.put(Column.create(PAGE_RESTRICTIONS), RecordValue.create(page.getRestrictions(), viz)); } List<Object> revisions = page.getRevisionOrUploadOrLogitem(); for (Object o : revisions) { if (o instanceof RevisionType) { RevisionType rev = (RevisionType) o; if (null != rev.getContributor()) { // If we have an IP, not a logged in user if (null != rev.getContributor().getIp()) { data.put(Column.create(CONTRIBUTOR_IP), RecordValue.create(rev.getContributor().getIp(), viz)); } else { // Assume username with ID data.put(Column.create(CONTRIBUTOR_USERNAME), RecordValue.create(rev.getContributor().getUsername(), viz)); data.put(Column.create(CONTRIBUTOR_ID), RecordValue.create(rev.getContributor().getId().toString(), viz)); } } data.put(Column.create(REVISION_ID), RecordValue.create(rev.getId().toString(), viz)); data.put(Column.create(REVISION_TIMESTAMP), RecordValue.create(rev.getTimestamp().toString(), viz)); if (null != rev.getComment() && !StringUtils.isBlank(rev.getComment().getValue())) { data.put(Column.create(REVISION_COMMENT), RecordValue.create(rev.getComment().getValue(), viz)); } } } mmap.add(new MultimapRecord(data, lang + id, viz)); id++; } return mmap; }