List of usage examples for com.google.common.collect Multimap entries
Collection<Map.Entry<K, V>> entries();
From source file:com.torodb.backend.AbstractReadInterface.java
@Override @SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION", "ODR_OPEN_DATABASE_RESOURCE" }, justification = "ResultSet is wrapped in a Cursor<Integer>. It's iterated and closed in caller code") public Cursor<Integer> getCollectionDidsWithFieldsIn(DSLContext dsl, MetaDatabase metaDatabase, MetaCollection metaCol, MetaDocPart metaDocPart, Multimap<MetaField, KvValue<?>> valuesMultimap) throws SQLException { assert metaDatabase.getMetaCollectionByIdentifier(metaCol.getIdentifier()) != null; assert metaCol.getMetaDocPartByIdentifier(metaDocPart.getIdentifier()) != null; assert valuesMultimap.keySet().stream() .allMatch(metafield -> metaDocPart.getMetaFieldByIdentifier(metafield.getIdentifier()) != null); if (valuesMultimap.size() > 500) { @SuppressWarnings("checkstyle:LineLength") Stream<Entry<Long, List<Tuple2<Entry<MetaField, KvValue<?>>, Long>>>> valuesEntriesBatchStream = Seq .seq(valuesMultimap.entries().stream()).zipWithIndex().groupBy(t -> t.v2 / 500).entrySet() .stream();//from w w w . j a va 2s . c o m Stream<Stream<Entry<MetaField, KvValue<?>>>> valuesEntryBatchStreamOfStream = valuesEntriesBatchStream .map(e -> e.getValue().stream().map(se -> se.v1)); Stream<Multimap<MetaField, KvValue<?>>> valuesMultimapBatchStream = valuesEntryBatchStreamOfStream .map(e -> toValuesMultimap(e)); Stream<Cursor<Integer>> didCursorStream = valuesMultimapBatchStream .map(Unchecked.function(valuesMultimapBatch -> getCollectionDidsWithFieldsInBatch(dsl, metaDatabase, metaCol, metaDocPart, valuesMultimapBatch))); Stream<Integer> didStream = didCursorStream.flatMap(cursor -> cursor.getRemaining().stream()); return new IteratorCursor<>(didStream.iterator()); } return getCollectionDidsWithFieldsInBatch(dsl, metaDatabase, metaCol, metaDocPart, valuesMultimap); }
From source file:com.proofpoint.http.client.MediaType.java
/** * Returns the string representation of this media type in the format described in <a * href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>. *//* w w w. j a va 2s . c o m*/ @Override public String toString() { StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype); if (!parameters.isEmpty()) { builder.append("; "); Multimap<String, String> quotedParameters = Multimaps.transformValues(parameters, new Function<String, String>() { @Override public String apply(String value) { return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value); } }); PARAMETER_JOINER.appendTo(builder, quotedParameters.entries()); } return builder.toString(); }
From source file:co.cask.cdap.data2.datafabric.dataset.DatasetServiceClient.java
private HttpResponse doRequest(HttpMethod method, String resource, @Nullable Multimap<String, String> headers, @Nullable InputSupplier<? extends InputStream> body) throws DatasetManagementException { String url = resolve(resource); try {// w w w . j a va 2s.c o m return HttpRequests.execute( processBuilder(HttpRequest.builder(method, new URL(url)).addHeaders(headers).withBody(body)) .build()); } catch (IOException e) { throw new DatasetManagementException(String.format( "Error during talking to Dataset Service at %s while doing %s with headers %s and body %s", url, method, headers == null ? "null" : Joiner.on(",").withKeyValueSeparator("=").join(headers.entries()), body == null ? "null" : body), e); } }
From source file:com.linecorp.armeria.common.MediaType.java
private String computeToString() { StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype); if (!parameters.isEmpty()) { builder.append("; "); Multimap<String, String> quotedParameters = Multimaps.transformValues(parameters, value -> TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value)); PARAMETER_JOINER.appendTo(builder, quotedParameters.entries()); }//from w w w.ja v a 2 s.c om return builder.toString(); }
From source file:io.janusproject.util.AbstractDMultiMapView.java
@Override public boolean putAll(Multimap<? extends K, ? extends V> multimap) { boolean changed = false; for (Entry<? extends K, ? extends V> entry : multimap.entries()) { if (getDelegatedObject().put(entry.getKey(), entry.getValue())) { changed = true;// www . ja va 2s.c om fireEntryAdded(entry.getKey(), entry.getValue()); } } return changed; }
From source file:com.palantir.atlasdb.keyvalue.rdbms.PostgresKeyValueService.java
@Override @NonIdempotent/*w w w. j av a2 s . c o m*/ public void putWithTimestamps(final String tableName, final Multimap<Cell, Value> cellValues) throws KeyAlreadyExistsException { // Validate the cellValues for (Entry<Cell, Value> e : cellValues.entries()) { for (Value val : cellValues.get(e.getKey())) { if (e.getValue() != val) { assert e.getValue().getTimestamp() != val.getTimestamp(); } } } batch(cellValues.entries(), new Function<Collection<Entry<Cell, Value>>, Void>() { @Override @Nullable public Void apply(@Nullable final Collection<Entry<Cell, Value>> input) { return getDbi().inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(Handle conn, TransactionStatus status) throws Exception { deleteInternalInTransaction(tableName, Collections2.transform(input, new Function<Entry<Cell, Value>, Entry<Cell, Long>>() { @Override public Entry<Cell, Long> apply(Entry<Cell, Value> input) { return new AbstractMap.SimpleEntry<Cell, Long>(input.getKey(), input.getValue().getTimestamp()); } }), conn); putWithTimestampsInternalInTransaction(tableName, input, conn); return null; } }); } }); }
From source file:com.torodb.torod.db.postgresql.query.QueryEvaluator.java
@Nonnull private Map<Integer, DatabaseQuery> createDatabaseQueryByStructure(@Nullable QueryCriteria criteria, DSLContext dsl) {/* w w w . j a va2 s. c om*/ Map<Integer, DatabaseQuery> result; if (criteria == null) { BiMap<Integer, DocStructure> allStructures = colSchema.getStructuresCache().getAllStructures(); result = Maps.newHashMapWithExpectedSize(allStructures.size()); for (Integer sid : colSchema.getStructuresCache().getAllStructures().keySet()) { result.put(sid, SelectAllDatabaseQuery.getInstance()); } } else { Multimap<Integer, QueryCriteria> candidateStructures = QueryStructureFilter.filterStructures(colSchema, criteria); if (candidateStructures.isEmpty()) { result = Collections.emptyMap(); } else { result = Maps.newHashMapWithExpectedSize(candidateStructures.size()); for (Map.Entry<Integer, QueryCriteria> entry : candidateStructures.entries()) { Integer sid = entry.getKey(); DocStructure rootStructure = colSchema.getStructuresCache().getStructure(sid); DatabaseQuery databaseQuery = createDatabaseQuery(entry.getValue(), sid, rootStructure, dsl); if (!(databaseQuery instanceof FalseDatabaseQuery)) { result.put(sid, databaseQuery); } } } } return result; }
From source file:com.facebook.presto.accumulo.index.IndexLookup.java
private boolean getRangesWithMetrics(ConnectorSession session, String schema, String table, Multimap<AccumuloColumnConstraint, Range> constraintRanges, Collection<Range> rowIdRanges, List<TabletSplitMetadata> tabletSplits, Authorizations auths) throws Exception { String metricsTable = getMetricsTableName(schema, table); long numRows = getNumRowsInTable(metricsTable, auths); // Get the cardinalities from the metrics table Multimap<Long, AccumuloColumnConstraint> cardinalities; if (isIndexShortCircuitEnabled(session)) { cardinalities = cardinalityCache.getCardinalities(schema, table, auths, constraintRanges, (long) (numRows * getIndexSmallCardThreshold(session)), getIndexCardinalityCachePollingDuration(session)); } else {//from w ww.ja v a2s.c o m // disable short circuit using 0 cardinalities = cardinalityCache.getCardinalities(schema, table, auths, constraintRanges, 0, new Duration(0, TimeUnit.MILLISECONDS)); } Optional<Entry<Long, AccumuloColumnConstraint>> entry = cardinalities.entries().stream().findFirst(); if (!entry.isPresent()) { return false; } Entry<Long, AccumuloColumnConstraint> lowestCardinality = entry.get(); String indexTable = getIndexTableName(schema, table); double threshold = getIndexThreshold(session); List<Range> indexRanges; // If the smallest cardinality in our list is above the lowest cardinality threshold, // we should look at intersecting the row ID ranges to try and get under the threshold. if (smallestCardAboveThreshold(session, numRows, lowestCardinality.getKey())) { // If we only have one column, we can skip the intersection process and just check the index threshold if (cardinalities.size() == 1) { long numEntries = lowestCardinality.getKey(); double ratio = ((double) numEntries / (double) numRows); LOG.debug("Use of index would scan %d of %d rows, ratio %s. Threshold %2f, Using for table? %b", numEntries, numRows, ratio, threshold, ratio < threshold); if (ratio >= threshold) { return false; } } // Else, get the intersection of all row IDs for all column constraints LOG.debug("%d indexed columns, intersecting ranges", constraintRanges.size()); indexRanges = getIndexRanges(indexTable, constraintRanges, rowIdRanges, auths); LOG.debug("Intersection results in %d ranges from secondary index", indexRanges.size()); } else { // Else, we don't need to intersect the columns and we can just use the column with the lowest cardinality, // so get all those row IDs in a set of ranges. LOG.debug("Not intersecting columns, using column with lowest cardinality "); ImmutableMultimap.Builder<AccumuloColumnConstraint, Range> lcBldr = ImmutableMultimap.builder(); lcBldr.putAll(lowestCardinality.getValue(), constraintRanges.get(lowestCardinality.getValue())); indexRanges = getIndexRanges(indexTable, lcBldr.build(), rowIdRanges, auths); } if (indexRanges.isEmpty()) { LOG.debug("Query would return no results, returning empty list of splits"); return true; } // Okay, we now check how many rows we would scan by using the index vs. the overall number // of rows long numEntries = indexRanges.size(); double ratio = (double) numEntries / (double) numRows; LOG.debug("Use of index would scan %d of %d rows, ratio %s. Threshold %2f, Using for table? %b", numEntries, numRows, ratio, threshold, ratio < threshold, table); // If the percentage of scanned rows, the ratio, less than the configured threshold if (ratio < threshold) { // Bin the ranges into TabletMetadataSplits and return true to use the tablet splits binRanges(getNumIndexRowsPerSplit(session), indexRanges, tabletSplits); LOG.debug("Number of splits for %s.%s is %d with %d ranges", schema, table, tabletSplits.size(), indexRanges.size()); return true; } else { // We are going to do too much work to use the secondary index, so return false return false; } }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
private void genAdminDocByUI(Element parent, Multimap<UI, Right> uiMap) { for (Map.Entry<UI, Right> entry : uiMap.entries()) { UI ui = entry.getKey();/*from ww w . j av a 2s .com*/ Right right = entry.getValue(); Element eUI = parent.addElement(E_UI); eUI.addAttribute(E_DESC, ui.getDesc()); eUI.addAttribute(E_RIGHT, right.getName()); } }
From source file:io.prestosql.plugin.accumulo.index.IndexLookup.java
private boolean getRangesWithMetrics(ConnectorSession session, String schema, String table, Multimap<AccumuloColumnConstraint, Range> constraintRanges, Collection<Range> rowIdRanges, List<TabletSplitMetadata> tabletSplits, Authorizations auths) throws Exception { String metricsTable = getMetricsTableName(schema, table); long numRows = getNumRowsInTable(metricsTable, auths); // Get the cardinalities from the metrics table Multimap<Long, AccumuloColumnConstraint> cardinalities; if (isIndexShortCircuitEnabled(session)) { cardinalities = cardinalityCache.getCardinalities(schema, table, auths, constraintRanges, (long) (numRows * getIndexSmallCardThreshold(session)), getIndexCardinalityCachePollingDuration(session)); } else {// w w w . ja v a 2 s. co m // disable short circuit using 0 cardinalities = cardinalityCache.getCardinalities(schema, table, auths, constraintRanges, 0, new Duration(0, TimeUnit.MILLISECONDS)); } Optional<Entry<Long, AccumuloColumnConstraint>> entry = cardinalities.entries().stream().findFirst(); if (!entry.isPresent()) { return false; } Entry<Long, AccumuloColumnConstraint> lowestCardinality = entry.get(); String indexTable = getIndexTableName(schema, table); double threshold = getIndexThreshold(session); List<Range> indexRanges; // If the smallest cardinality in our list is above the lowest cardinality threshold, // we should look at intersecting the row ID ranges to try and get under the threshold. if (smallestCardAboveThreshold(session, numRows, lowestCardinality.getKey())) { // If we only have one column, we can skip the intersection process and just check the index threshold if (cardinalities.size() == 1) { long numEntries = lowestCardinality.getKey(); double ratio = ((double) numEntries / (double) numRows); LOG.debug( "Use of index would scan %s of %s rows, ratio %s. Threshold %2f, Using for index table? %s", numEntries, numRows, ratio, threshold, ratio < threshold); if (ratio >= threshold) { return false; } } // Else, get the intersection of all row IDs for all column constraints LOG.debug("%d indexed columns, intersecting ranges", constraintRanges.size()); indexRanges = getIndexRanges(indexTable, constraintRanges, rowIdRanges, auths); LOG.debug("Intersection results in %d ranges from secondary index", indexRanges.size()); } else { // Else, we don't need to intersect the columns and we can just use the column with the lowest cardinality, // so get all those row IDs in a set of ranges. LOG.debug("Not intersecting columns, using column with lowest cardinality "); ImmutableMultimap.Builder<AccumuloColumnConstraint, Range> lcBldr = ImmutableMultimap.builder(); lcBldr.putAll(lowestCardinality.getValue(), constraintRanges.get(lowestCardinality.getValue())); indexRanges = getIndexRanges(indexTable, lcBldr.build(), rowIdRanges, auths); } if (indexRanges.isEmpty()) { LOG.debug("Query would return no results, returning empty list of splits"); return true; } // Okay, we now check how many rows we would scan by using the index vs. the overall number // of rows long numEntries = indexRanges.size(); double ratio = (double) numEntries / (double) numRows; LOG.debug("Use of index would scan %d of %d rows, ratio %s. Threshold %2f, Using for table? %b", numEntries, numRows, ratio, threshold, ratio < threshold, table); // If the percentage of scanned rows, the ratio, less than the configured threshold if (ratio < threshold) { // Bin the ranges into TabletMetadataSplits and return true to use the tablet splits binRanges(getNumIndexRowsPerSplit(session), indexRanges, tabletSplits); LOG.debug("Number of splits for %s.%s is %d with %d ranges", schema, table, tabletSplits.size(), indexRanges.size()); return true; } else { // We are going to do too much work to use the secondary index, so return false return false; } }