List of usage examples for com.google.common.collect SetMultimap get
@Override Set<V> get(@Nullable K key);
Because a SetMultimap has unique values for a given key, this method returns a Set , instead of the java.util.Collection specified in the Multimap interface.
From source file:org.xbib.tools.merge.zdb.entities.Manifestation.java
public String build(XContentBuilder builder, String tag, Set<String> visited) throws IOException { if (visited != null) { if (visited.contains(externalID)) { return null; }/*from ww w . java2s.c om*/ visited.add(externalID); } String id = tag != null ? tag + "." + externalID : externalID; builder.startObject(); builder.field("@id", id).field("@type", "Manifestation").fieldIfNotNull("@tag", tag).field("key", getKey()) .field("title", title()); String s = corporateName(); if (s != null) { builder.field("corporateName", s); } s = meetingName(); if (s != null) { builder.field("meetingName", s); } builder.field("country", country()).field("language", language()).field("publishedat", publisherPlace()) .field("publishedby", publisher()).field("contenttype", contentType()) .field("mediatype", mediaType()).field("carriertype", carrierType()).field("firstdate", firstDate()) .field("lastdate", lastDate()); if (greenDates != null && !greenDates.isEmpty()) { builder.field("greendate", greenDates); } if (hasIdentifiers()) { builder.field("identifiers", getIdentifiers()); } if (isSubseries()) { builder.field("subseries", isSubseries()); } if (isSupplement()) { builder.field("supplement", isSupplement()); } // list external relations for linking synchronized (externalRelations) { SetMultimap<String, String> map = externalRelations; if (!map.isEmpty()) { builder.startArray("relations"); for (String rel : map.keySet()) { for (String relid : map.get(rel)) { builder.startObject().field("@id", relid).field("@type", "Manifestation") .field("@label", rel).endObject(); } } builder.endArray(); } } if (hasLinks()) { builder.array("links", getLinks()); } // list monographic volumes if (!volumeIDs.isEmpty()) { builder.array("volumeids", volumeIDs); } if (!volumes.isEmpty()) { synchronized (volumes) { builder.startArray("volumes"); int count = 0; for (Volume volume : volumes) { volume.build(builder, tag, null); count++; } builder.endArray(); builder.field("volumescount", count); } } builder.endObject(); return id; }
From source file:org.cytoscape.model.internal.CyTableImpl.java
@Override synchronized public int countMatchingRows(final String columnName, final Object value) { final String normalizedColName = normalizeColumnName(columnName); final VirtualColumn virtColumn = virtualColumnMap.get(normalizedColName); if (virtColumn != null) return virtColumn.countMatchingRows(value); final SetMultimap<Object, Object> valueToKeysMap = reverse.get(normalizedColName); if (valueToKeysMap == null) return 0; else//from ww w . j a v a 2 s.c o m return valueToKeysMap.get(value).size(); }
From source file:com.jivesoftware.os.amza.service.AmzaRingStoreWriter.java
private void buildRandomSubRing(byte[] ringName, int desiredRingSize) throws Exception { if (ringName == null) { throw new IllegalArgumentException("ringName cannot be null."); }/* w ww .j av a 2 s. c o m*/ RingTopology systemRing = ringStoreReader.getRing(AmzaRingReader.SYSTEM_RING, 0); if (systemRing.entries.size() < desiredRingSize) { throw new IllegalStateException( "Current 'system' ring is not large enough to support a ring of size:" + desiredRingSize); } SetMultimap<String, RingMemberAndHost> subRackMembers = HashMultimap.create(); RingTopology subRing = ringStoreReader.getRing(ringName, 0); for (RingMemberAndHost entry : subRing.entries) { String rack = rackDistributionEnabled ? entry.ringHost.getRack() : ""; subRackMembers.put(rack, entry); } Map<String, List<RingMemberAndHost>> systemRackMembers = new HashMap<>(); for (RingMemberAndHost entry : systemRing.entries) { String rack = rackDistributionEnabled ? entry.ringHost.getRack() : ""; systemRackMembers.computeIfAbsent(rack, (key) -> new ArrayList<>()).add(entry); } Random random = new Random(new Random(Arrays.hashCode(ringName)).nextLong()); for (List<RingMemberAndHost> rackMembers : systemRackMembers.values()) { Collections.shuffle(rackMembers, random); } List<String> racks = new ArrayList<>(systemRackMembers.keySet()); while (subRackMembers.size() < desiredRingSize) { Collections.sort(racks, (o1, o2) -> Integer.compare(subRackMembers.get(o1).size(), subRackMembers.get(o2).size())); boolean advanced = false; for (String cycleRack : racks) { List<RingMemberAndHost> rackMembers = systemRackMembers.get(cycleRack); if (!rackMembers.isEmpty()) { subRackMembers.put(cycleRack, rackMembers.remove(rackMembers.size() - 1)); advanced = true; break; } } if (!advanced) { break; } } setInternal(ringName, Iterables.transform(subRackMembers.values(), input -> input.ringMember)); }
From source file:org.cytoscape.model.internal.CyTableImpl.java
private void fireVirtualColumnRowSetEvent(CyTableImpl table, Object key, String columnName, Object newValue, Object newRawValue, Set<VirtualColumnInfo> seen) { // Fire an event for this table CyRow row = table.getRowNoCreate(key); if (row == null) { return;/*from w w w . j ava2s.co m*/ } eventHelper.addEventPayload((CyTable) table, new RowSetRecord(row, columnName, newValue, newRawValue), RowsSetEvent.class); // ...then fire events for all dependents String normalizedColumnName = normalizeColumnName(columnName); Set<CyColumn> columnDependents = dependents.get(normalizedColumnName); if (columnDependents == null) { return; } for (CyColumn dependent : columnDependents) { VirtualColumnInfo info = dependent.getVirtualColumnInfo(); if (seen.contains(info)) { continue; } seen.add(info); CyTableImpl table2 = (CyTableImpl) dependent.getTable(); String targetJoinKey = info.getTargetJoinKey(); if (targetJoinKey.equals(table2.getPrimaryKey().getName())) { fireVirtualColumnRowSetEvent(table2, key, dependent.getName(), newValue, newRawValue, seen); } else { String normalizedTargetJoinKey = table2.normalizeColumnName(targetJoinKey); SetMultimap<Object, Object> reverseMap = table2.reverse.get(normalizedTargetJoinKey); if (reverseMap != null) { for (Object key2 : reverseMap.get(key)) { fireVirtualColumnRowSetEvent(table2, key2, dependent.getName(), newValue, newRawValue, seen); } } } } }
From source file:org.cytoscape.model.internal.CyTableImpl.java
@Override public boolean deleteRows(final Collection<?> primaryKeys) { boolean changed = false; synchronized (this) { for (Object key : primaryKeys) { checkKey(key);/* w w w . j a v a2s . co m*/ CyRow row = rows.remove(key); if (row != null) { rowList.remove(row); changed = true; } for (CyColumn col : getColumns()) { final String normalizedColName = normalizeColumnName(col.getName()); final Map<Object, Object> keyToValueMap = attributes.get(normalizedColName); if (keyToValueMap != null) { Object val = keyToValueMap.remove(key); SetMultimap<Object, Object> valueToKeysMap = reverse.get(normalizedColName); if (valueToKeysMap != null) { Set<Object> keys = valueToKeysMap.get(val); if (keys != null) { keys.remove(key); } } } } } } if (changed) eventHelper.fireEvent(new RowsDeletedEvent(this, (Collection<Object>) primaryKeys)); return changed; }
From source file:org.gradle.composite.internal.DefaultIncludedBuildRegistry.java
private void validateIncludedBuilds(SettingsInternal settings) { SetMultimap<String, IncludedBuildState> names = LinkedHashMultimap.create(); while (!pendingIncludedBuilds.isEmpty()) { IncludedBuildState build = pendingIncludedBuilds.remove(0); // This implicitly loads the settings, possibly discovering more included builds // Should make this an explicit step instead String buildName = build.getName(); names.put(buildName, build);//from w w w . j ava2s. com if (settings.getRootProject().getName().equals(buildName)) { throw new GradleException("Included build in " + build.getRootDirectory() + " has the same root project name '" + buildName + "' as the main build."); } if (settings.findProject(":" + buildName) != null) { throw new GradleException( "Included build in " + build.getRootDirectory() + " has a root project whose name '" + buildName + "' is the same as a project of the main build."); } } for (String buildNAme : names.keySet()) { Set<IncludedBuildState> buildsWithName = names.get(buildNAme); if (buildsWithName.size() > 1) { TreeFormatter visitor = new TreeFormatter(); visitor.node("Multiple included builds have the same root project name '" + buildNAme + "'"); visitor.startChildren(); for (IncludedBuildState build : buildsWithName) { visitor.node("Included build in " + build.getRootDirectory()); } visitor.endChildren(); throw new GradleException(visitor.toString()); } } }
From source file:org.killbill.billing.plugin.simpletax.SimpleTaxPlugin.java
/** * Creates an lists the tax codes that are missing to the new invoice being * created.// w w w . j av a2s . co m * * @param newInvoice * The new invoice that is being created. * @param resolver * The tax resolver to use. * @param taxCtx * The context data to use when computing taxes. * @param callCtx * The context in which this code is running. * @return A new immutable map of the tax codes to add, mapped from their * related invoice item identifier. Never {@code null}, and * guaranteed not having any {@code null} elements. */ private Map<UUID, TaxCode> addMissingTaxCodes(Invoice newInvoice, TaxResolver resolver, final TaxComputationContext taxCtx, CallContext callCtx) { // Obtain tax codes from products of invoice items TaxCodeService taxCodesService = taxCtx.getTaxCodeService(); SetMultimap<UUID, TaxCode> configuredTaxCodesForInvoiceItems = taxCodesService .resolveTaxCodesFromConfig(newInvoice); SetMultimap<UUID, TaxCode> existingTaxCodesForInvoiceItems = taxCodesService .findExistingTaxCodes(newInvoice); ImmutableMap.Builder<UUID, TaxCode> newTaxCodes = ImmutableMap.builder(); // Add product tax codes to custom field if null or empty for (InvoiceItem item : newInvoice.getInvoiceItems()) { if (!isTaxableItem(item)) { continue; } Set<TaxCode> expectedTaxCodes = configuredTaxCodesForInvoiceItems.get(item.getId()); // Note: expectedTaxCodes != null as per the Multimap contract if (expectedTaxCodes.isEmpty()) { continue; } Set<TaxCode> existingTaxCodes = existingTaxCodesForInvoiceItems.get(item.getId()); // Note: existingTaxCodes != null as per the Multimap contract if (!existingTaxCodes.isEmpty()) { // Don't override existing tax codes continue; } final String accountTaxCountry = taxCtx.getAccountTaxCountry() == null ? null : taxCtx.getAccountTaxCountry().getCode(); Iterable<TaxCode> expectedInAccountCountry = filter(expectedTaxCodes, new Predicate<TaxCode>() { @Override public boolean apply(TaxCode taxCode) { Country restrict = taxCode.getCountry(); return (restrict == null) || restrict.getCode().equals(accountTaxCountry); } }); // resolve tax codes using regulation-specific logic TaxCode applicableCode = resolver.applicableCodeForItem(expectedInAccountCountry, item); if (applicableCode == null) { continue; } newTaxCodes.put(item.getId(), applicableCode); } return newTaxCodes.build(); }
From source file:dagger.internal.codegen.BindingFactory.java
private boolean shouldBeInjected(Element injectionSite, SetMultimap<String, ExecutableElement> overriddenMethodMap) { if (!isAnnotationPresent(injectionSite, Inject.class) || injectionSite.getModifiers().contains(PRIVATE) || injectionSite.getModifiers().contains(STATIC)) { return false; }// w w w. j ava 2 s . c o m if (injectionSite.getKind().isField()) { // Inject all fields (self and ancestors) return true; } // For each method with the same name belonging to any descendant class, return false if any // method has already overridden the injectionSite method. To decrease the number of methods // that are checked, we store the already injected methods in a SetMultimap and only // check the methods with the same name. ExecutableElement injectionSiteMethod = MoreElements.asExecutable(injectionSite); TypeElement injectionSiteType = MoreElements.asType(injectionSite.getEnclosingElement()); for (ExecutableElement method : overriddenMethodMap.get(injectionSiteMethod.getSimpleName().toString())) { if (elements.overrides(method, injectionSiteMethod, injectionSiteType)) { return false; } } return true; }
From source file:de.bund.bfr.knime.gis.views.canvas.LocationCanvasUtils.java
public static Polygon placeNodes(Collection<LocationNode> nodes, Collection<Edge<LocationNode>> edges, Layout<LocationNode, Edge<LocationNode>> layout) { Polygon invalidArea = null;/*www .j a va 2s.c o m*/ Set<LocationNode> invalidNodes = new LinkedHashSet<>(); SetMultimap<LocationNode, LocationNode> invalidToValid = LinkedHashMultimap.create(); SetMultimap<LocationNode, LocationNode> invalidToInvalid = LinkedHashMultimap.create(); List<Point2D> positions = new ArrayList<>(); for (LocationNode node : nodes) { if (node.getCenter() != null) { layout.setLocation(node, node.getCenter()); positions.add(node.getCenter()); } else { invalidNodes.add(node); } } for (Edge<LocationNode> edge : edges) { if (edge.getFrom() == edge.getTo()) { continue; } if (invalidNodes.contains(edge.getFrom())) { if (invalidNodes.contains(edge.getTo())) { invalidToInvalid.put(edge.getFrom(), edge.getTo()); } else { invalidToValid.put(edge.getFrom(), edge.getTo()); } } if (invalidNodes.contains(edge.getTo())) { if (invalidNodes.contains(edge.getFrom())) { invalidToInvalid.put(edge.getTo(), edge.getFrom()); } else { invalidToValid.put(edge.getTo(), edge.getFrom()); } } } if (!invalidNodes.isEmpty()) { Rectangle2D bounds = PointUtils.getBounds(positions); double size = Math.max(bounds.getWidth(), bounds.getHeight()); if (size == 0.0) { size = 1.0; } double d = 0.2 * size; double r = 0.02 * size; invalidArea = GisUtils.createBorderPolygon(new Rectangle2D.Double(bounds.getX() - d, bounds.getY() - d, bounds.getWidth() + 2 * d, bounds.getHeight() + 2 * d), 2 * r); Rectangle2D rect = new Rectangle2D.Double(bounds.getX() - d - r, bounds.getY() - d - r, bounds.getWidth() + 2 * (d + r), bounds.getHeight() + 2 * (d + r)); for (LocationNode node : new LinkedHashSet<>(invalidNodes)) { Set<LocationNode> validConnections = invalidToValid.get(node); if (!validConnections.isEmpty()) { List<Point2D> points = new ArrayList<>(); for (LocationNode n : validConnections) { points.add(n.getCenter()); } Point2D p = getClosestPointOnRect(PointUtils.getCenter(points), rect); node.updateCenter(p); layout.setLocation(node, p); invalidNodes.remove(node); } } while (true) { boolean nothingChanged = true; for (LocationNode node : new LinkedHashSet<>(invalidNodes)) { Set<LocationNode> invalidConnections = invalidToInvalid.get(node); List<Point2D> points = new ArrayList<>(); for (LocationNode n : invalidConnections) { if (n.getCenter() != null) { points.add(n.getCenter()); } } if (!points.isEmpty()) { Point2D p = getClosestPointOnRect(PointUtils.getCenter(points), rect); node.updateCenter(p); layout.setLocation(node, p); invalidNodes.remove(node); nothingChanged = false; } } if (nothingChanged) { break; } } for (LocationNode node : invalidNodes) { Point2D p = new Point2D.Double(bounds.getMinX() - d - r, bounds.getMaxY() - d - r); node.updateCenter(p); layout.setLocation(node, p); } } return invalidArea; }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CQLKeyValueService.java
@Override public Map<Cell, Value> get(String tableName, Map<Cell, Long> timestampByCell) { try {//from w ww.j a v a 2 s . co m long firstTs = timestampByCell.values().iterator().next(); if (Iterables.all(timestampByCell.values(), Predicates.equalTo(firstTs))) { StartTsResultsCollector collector = new StartTsResultsCollector(firstTs); loadWithTs(tableName, timestampByCell.keySet(), firstTs, false, collector, readConsistency); return collector.collectedResults; } SetMultimap<Long, Cell> cellsByTs = HashMultimap.create(); Multimaps.invertFrom(Multimaps.forMap(timestampByCell), cellsByTs); Builder<Cell, Value> builder = ImmutableMap.builder(); for (long ts : cellsByTs.keySet()) { StartTsResultsCollector collector = new StartTsResultsCollector(ts); loadWithTs(tableName, cellsByTs.get(ts), ts, false, collector, readConsistency); builder.putAll(collector.collectedResults); } return builder.build(); } catch (Throwable t) { throw Throwables.throwUncheckedException(t); } }