List of usage examples for com.google.common.collect ImmutableMap entrySet
public final ImmutableSet<Entry<K, V>> entrySet()
From source file:net.oneandone.troilus.Java7DaoImpl.java
@Override public SingleReadWithUnit<Record, Record> readWithKey(ImmutableMap<String, Object> composedkey) { Map<String, ImmutableList<Object>> keys = Maps.newHashMap(); for (Entry<String, Object> entry : composedkey.entrySet()) { keys.put(entry.getKey(), ImmutableList.of(entry.getValue())); }/*from w w w . j av a 2 s .c o m*/ return new SingleReadQuery(ctx, new ReadQueryDataImpl(tablename).keys(ImmutableMap.copyOf(keys))); }
From source file:com.google.cloud.dataflow.sdk.util.KeyedStateCache.java
public Map<CodedTupleTag<?>, Iterable<?>> readTagLists(Iterable<CodedTupleTag<?>> tags) throws IOException { try {//from w w w .ja va 2 s . co m ImmutableMap.Builder<CodedTupleTag<?>, Iterable<?>> outputBuilder = ImmutableMap.builder(); // Figure out which tags can be fully satisfied with local data, and add them to the output. // Other tags, will need to be looked up. List<CodedTupleTag<?>> nonDeletedTags = new ArrayList<>(); for (CodedTupleTag<?> tag : tags) { TagListUpdates<?> localUpdates = localTagListUpdates.get(tag); if (localUpdates != null && localUpdates.isDelete) { // For locally deleted items, we don't need to do a lookup at all outputBuilder.put(tag, localUpdates.getAddedItems()); } else { nonDeletedTags.add(tag); } } // For any non-deleted tag, look it up in the tagListCache, and build output by combining ImmutableMap<CodedTupleTag<?>, List<?>> cachedContents = tagListCache.getAll(nonDeletedTags); for (Map.Entry<CodedTupleTag<?>, List<?>> lookedUp : cachedContents.entrySet()) { CodedTupleTag<?> tag = lookedUp.getKey(); TagListUpdates<?> localUpdates = localTagListUpdates.get(tag); outputBuilder.put(tag, localUpdates == null ? lookedUp.getValue() : localUpdates.mergeWith(lookedUp.getValue())); } return outputBuilder.build(); } catch (ExecutionException e) { Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); throw Throwables.propagate(e.getCause()); } }
From source file:org.elasticsearch.search.query.sortbydoc.SortByDocQueryParser.java
@Override public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException { XContentParser parser = parseContext.parser(); String currentFieldName = null; String lookupIndex = parseContext.index().name(); String lookupType = null;/*w w w . j a v a 2 s. c o m*/ String lookupId = null; String rootPath = null; String idField = null; String scoreField = null; String lookupRouting = null; SortOrder sortOrder = SortOrder.DESC; Query subQuery = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { if ("query".equals(parser.currentName())) { subQuery = parseContext.parseInnerQuery(); continue; } } else if (token.isValue()) { if (false) { } else if ("index".equals(currentFieldName)) { lookupIndex = parser.text(); } else if ("type".equals(currentFieldName)) { lookupType = parser.text(); } else if ("doc_id".equals(currentFieldName)) { lookupId = parser.text(); } else if ("root".equals(currentFieldName)) { rootPath = parser.text(); } else if ("id".equals(currentFieldName)) { idField = parser.text(); } else if ("score".equals(currentFieldName)) { scoreField = parser.text(); } else if ("routing".equals(currentFieldName)) { lookupRouting = parser.textOrNull(); } else if ("sort_order".equals(currentFieldName)) { try { sortOrder = SortOrder.valueOf(parser.text()); } catch (IllegalArgumentException e) { throw new QueryParsingException(parseContext, "[sort_by_doc] sort_order should be one of " + Arrays.toString(SortOrder.values())); } } else { throw new QueryParsingException(parseContext, "[sort_by_doc] query does not support [" + currentFieldName + "] within lookup element"); } } } if (lookupType == null) { throw new QueryParsingException(parseContext, "[sort_by_doc] query lookup element requires specifying the type"); } if (lookupId == null) { throw new QueryParsingException(parseContext, "[sort_by_doc] query lookup element requires specifying the doc_id"); } if (rootPath == null) { throw new QueryParsingException(parseContext, "[sort_by_doc] query lookup element requires specifying the path"); } if (idField == null) { throw new QueryParsingException(parseContext, "[sort_by_doc] query lookup element requires specifying the id"); } if (scoreField == null) { throw new QueryParsingException(parseContext, "[sort_by_doc] query lookup element requires specifying the score"); } if (subQuery == null) { throw new QueryParsingException(parseContext, "[sort_by_doc] query requires a subquery"); } String fieldName = "_id"; MappedFieldType _idType = parseContext.mapperService().smartNameFieldType(fieldName); /* FieldMapper fieldMapper = null; smartNameFieldMappers = parseContext.mapperService().smartFieldMappers(fieldName); if (smartNameFieldMappers != null) { if (smartNameFieldMappers.hasMapper()) { fieldMapper = smartNameFieldMappers.mapper(); fieldName = fieldMapper.names().indexName(); } } */ /* if (fieldMapper == null || !(fieldMapper instanceof IdFieldMapper)) throw new QueryParsingException(parseContext.index(), "[sort_by_doc] the _id field must be a defaultly indexed UID field"); */ if (_idType == null) throw new QueryParsingException(parseContext, "[sort_by_doc] the _id field must be a defaultly indexed UID field"); // external lookup, use it ScoresLookup scoresLookup = new ScoresLookup(lookupIndex, lookupType, lookupId, lookupRouting, rootPath, idField, scoreField, parseContext, SearchContext.current()); ImmutableMap<String, Float> scores = scoringDocumentCache.getScores(scoresLookup); Map<Term, Float> termsScores = new HashMap<>(); for (Map.Entry<String, Float> score : scores.entrySet()) { Uid.createUidsForTypesAndId(parseContext.queryTypes(), score.getKey()); BytesRef[] keyUids = Uid.createUidsForTypesAndId(parseContext.queryTypes(), score.getKey()); for (BytesRef keyUid : keyUids) { Term t = new Term(UidFieldMapper.NAME, keyUid); termsScores.put(t, sortOrder.equals(SortOrder.DESC) ? score.getValue() : -score.getValue()); } } if (scores.isEmpty()) { return subQuery; } Query filter = _idType.termsQuery(scores.keySet().asList(), parseContext); return new SortByDocQuery(fieldName, subQuery, filter, termsScores); }
From source file:com.google.devtools.build.lib.analysis.TransitiveInfoProviderMapOffsetBased.java
TransitiveInfoProviderMapOffsetBased( ImmutableMap<Class<? extends TransitiveInfoProvider>, TransitiveInfoProvider> map) { int count = map.size(); Class<? extends TransitiveInfoProvider>[] providerClasses = new Class[count]; this.providers = new TransitiveInfoProvider[count]; int i = 0;// w w w .j a v a 2 s. com for (Entry<Class<? extends TransitiveInfoProvider>, TransitiveInfoProvider> entry : map.entrySet()) { providerClasses[i] = entry.getKey(); providers[i] = entry.getValue(); ++i; } OffsetTable offsetTable = new OffsetTable(providerClasses); this.offsetTable = offsetTables.intern(offsetTable); }
From source file:com.facebook.buck.step.fs.ZipDirectoryWithMaxDeflateStep.java
@Override public int execute(ExecutionContext context) { File inputDirectory = new File(inputDirectoryPath); Preconditions.checkState(inputDirectory.exists() && inputDirectory.isDirectory()); Closer closer = Closer.create();//from w ww . j a va 2 s.c o m try { ImmutableMap.Builder<File, ZipEntry> zipEntriesBuilder = ImmutableMap.builder(); addDirectoryToZipEntryList(inputDirectory, "", zipEntriesBuilder); ImmutableMap<File, ZipEntry> zipEntries = zipEntriesBuilder.build(); if (!zipEntries.isEmpty()) { ZipOutputStream outputStream = closer.register( new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputZipPath)))); for (Map.Entry<File, ZipEntry> zipEntry : zipEntries.entrySet()) { outputStream.putNextEntry(zipEntry.getValue()); ByteStreams.copy(Files.newInputStreamSupplier(zipEntry.getKey()), outputStream); outputStream.closeEntry(); } } } catch (IOException e) { e.printStackTrace(context.getStdErr()); return 1; } finally { try { closer.close(); } catch (IOException e) { Throwables.propagate(e); } } return 0; }
From source file:org.onos.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.java
private QNameToStatementDefinition stmtDef() { //regular YANG statements added ImmutableMap<QName, StatementSupport<?, ?, ?>> definitions = currentContext .getSupportsForPhase(inProgressPhase).getDefinitions(); for (Map.Entry<QName, StatementSupport<?, ?, ?>> entry : definitions.entrySet()) { qNameToStmtDefMap.put(entry.getKey(), entry.getValue()); }// w w w . j a va 2s . c o m //extensions added if (inProgressPhase.equals(ModelProcessingPhase.FULL_DECLARATION)) { Map<QName, SubstatementContext<?, ?, ?>> extensions = (Map<QName, SubstatementContext<?, ?, ?>>) currentContext .getAllFromNamespace(ExtensionNamespace.class); if (extensions != null) { for (Map.Entry<QName, SubstatementContext<?, ?, ?>> extension : extensions.entrySet()) { qNameToStmtDefMap.put( new QName(YangConstants.RFC6020_YIN_NAMESPACE, extension.getKey().getLocalName()), (StatementDefinition) extension.getValue().definition().getFactory()); } } } return qNameToStmtDefMap; }
From source file:com.facebook.buck.rules.modern.builders.MultiThreadedBlobUploader.java
private ListenableFuture<Void> enqueue( ImmutableMap<Protocol.Digest, ThrowingSupplier<InputStream, IOException>> data) { ImmutableList.Builder<ListenableFuture<Void>> futures = ImmutableList.builder(); for (Entry<Protocol.Digest, ThrowingSupplier<InputStream, IOException>> entry : data.entrySet()) { Protocol.Digest digest = entry.getKey(); ListenableFuture<Void> resultFuture = pendingUploads.computeIfAbsent(digest.getHash(), hash -> { if (containedHashes.contains(hash)) { return Futures.immediateFuture(null); }// ww w. j av a 2s.co m SettableFuture<Void> future = SettableFuture.create(); waitingMissingCheck.add(new PendingUpload(new UploadData(digest, entry.getValue()), future)); return future; }); Futures.addCallback(resultFuture, MoreFutures.finallyCallback(() -> { containedHashes.add(digest.getHash()); pendingUploads.remove(digest.getHash()); })); futures.add(resultFuture); uploadService.submit(this::processUploads); } return Futures.whenAllSucceed(futures.build()).call(() -> null); }
From source file:com.facebook.buck.android.AndroidNativeLibsPackageableGraphEnhancer.java
private boolean populateMapWithLinkables(Iterable<NativeLinkable> linkables, ImmutableMap.Builder<Pair<NdkCxxPlatforms.TargetCpuType, String>, SourcePath> builder, NdkCxxPlatforms.TargetCpuType targetCpuType, NdkCxxPlatform platform) throws NoSuchBuildTargetException { boolean hasNativeLibs = false; for (NativeLinkable nativeLinkable : linkables) { if (nativeLinkable.getPreferredLinkage(platform.getCxxPlatform()) != NativeLinkable.Linkage.STATIC) { ImmutableMap<String, SourcePath> solibs = nativeLinkable .getSharedLibraries(platform.getCxxPlatform()); for (Map.Entry<String, SourcePath> entry : solibs.entrySet()) { builder.put(new Pair<>(targetCpuType, entry.getKey()), entry.getValue()); hasNativeLibs = true;//w w w . j ava 2s . co m } } } return hasNativeLibs; }
From source file:org.onos.yangtools.yang.parser.impl.util.URLSchemaContextResolver.java
/** * Try to parse all currently available yang files and build new schema context. * @return new schema context iif there is at least 1 yang file registered and new schema context was successfully built. *//* w w w. ja va 2 s . co m*/ public synchronized Optional<SchemaContext> tryToUpdateSchemaContext() { if (availableSources.isEmpty()) { return Optional.absent(); } ImmutableMap<SourceIdentifier, SourceContext> actualSources = ImmutableMap.copyOf(availableSources); Builder<SourceIdentifier, YangModelDependencyInfo> builder = ImmutableMap .<SourceIdentifier, YangModelDependencyInfo>builder(); for (Entry<SourceIdentifier, SourceContext> entry : actualSources.entrySet()) { builder.put(entry.getKey(), entry.getValue().getDependencyInfo()); } ImmutableMap<SourceIdentifier, YangModelDependencyInfo> sourcesMap = builder.build(); YangSourceContext yangSourceContext = YangSourceContext.createFrom(sourcesMap, this); LOG.debug("Trying to create schema context from {}", sourcesMap.keySet()); if (!yangSourceContext.getMissingDependencies().isEmpty()) { LOG.debug("Omitting {} because of unresolved dependencies", yangSourceContext.getMissingDependencies().keySet()); LOG.debug("Missing model sources for {}", yangSourceContext.getMissingSources()); } if (currentSourceContext == null || !yangSourceContext.getValidSources().equals(currentSourceContext.getValidSources())) { try { Collection<ByteSource> byteSources = yangSourceContext.getValidByteSources(); YangParserImpl parser = YangParserImpl.getInstance(); SchemaContext schemaContext = parser.parseSources(byteSources); currentSchemaContext = Optional.of(schemaContext); currentSourceContext = yangSourceContext; return Optional.of(schemaContext); } catch (Exception e) { LOG.error("Could not create schema context for {} ", yangSourceContext.getValidSources(), e); return Optional.absent(); } } else { currentSourceContext = yangSourceContext; return Optional.absent(); } }
From source file:org.opendaylight.yangtools.yang.parser.impl.util.URLSchemaContextResolver.java
/** * Try to parse all currently available yang files and build new schema context. * @return new schema context iif there is at least 1 yang file registered and new schema context was successfully built. *///from www . ja v a 2 s .com public synchronized Optional<SchemaContext> tryToUpdateSchemaContext() { if (availableSources.isEmpty()) { return Optional.absent(); } ImmutableMap<SourceIdentifier, SourceContext> actualSources = ImmutableMap.copyOf(availableSources); Builder<SourceIdentifier, YangModelDependencyInfo> builder = ImmutableMap .<SourceIdentifier, YangModelDependencyInfo>builder(); for (Entry<SourceIdentifier, SourceContext> entry : actualSources.entrySet()) { builder.put(entry.getKey(), entry.getValue().getDependencyInfo()); } ImmutableMap<SourceIdentifier, YangModelDependencyInfo> sourcesMap = builder.build(); YangSourceContext yangSourceContext = YangSourceContext.createFrom(sourcesMap, this); LOG.debug("Trying to create schema context from {}", sourcesMap.keySet()); if (yangSourceContext.getMissingDependencies().size() != 0) { LOG.debug("Omitting {} because of unresolved dependencies", yangSourceContext.getMissingDependencies().keySet()); LOG.debug("Missing model sources for {}", yangSourceContext.getMissingSources()); } if (currentSourceContext == null || !yangSourceContext.getValidSources().equals(currentSourceContext.getValidSources())) { try { Collection<ByteSource> byteSources = yangSourceContext.getValidByteSources(); YangParserImpl parser = YangParserImpl.getInstance(); SchemaContext schemaContext = parser.parseSources(byteSources); currentSchemaContext = Optional.of(schemaContext); currentSourceContext = yangSourceContext; return Optional.of(schemaContext); } catch (Exception e) { LOG.error("Could not create schema context for {} ", yangSourceContext.getValidSources(), e); return Optional.absent(); } } else { currentSourceContext = yangSourceContext; return Optional.absent(); } }