List of usage examples for com.google.common.collect ImmutableMap.Builder putAll
public final void putAll(Map<? extends K, ? extends V> map)
From source file:com.facebook.presto.event.query.QueryMonitor.java
public void completionEvent(QueryInfo queryInfo) { try {//from w ww.ja v a 2 s . com QueryStats queryStats = queryInfo.getQueryStats(); FailureInfo failureInfo = queryInfo.getFailureInfo(); String failureType = failureInfo == null ? null : failureInfo.getType(); String failureMessage = failureInfo == null ? null : failureInfo.getMessage(); ImmutableMap.Builder<String, String> mergedProperties = ImmutableMap.builder(); mergedProperties.putAll(queryInfo.getSession().getSystemProperties()); for (Map.Entry<String, Map<String, String>> catalogEntry : queryInfo.getSession().getCatalogProperties() .entrySet()) { for (Map.Entry<String, String> entry : catalogEntry.getValue().entrySet()) { mergedProperties.put(catalogEntry.getKey() + "." + entry.getKey(), entry.getValue()); } } TaskInfo task = null; StageInfo stageInfo = queryInfo.getOutputStage(); if (stageInfo != null) { task = stageInfo.getTasks().stream().filter(taskInfo -> taskInfo.getState() == TaskState.FAILED) .findFirst().orElse(null); } String failureHost = task == null ? null : task.getSelf().getHost(); String failureTask = task == null ? null : task.getTaskId().toString(); eventClient.post(new QueryCompletionEvent(queryInfo.getQueryId(), queryInfo.getSession().getUser(), queryInfo.getSession().getPrincipal().orElse(null), queryInfo.getSession().getSource().orElse(null), serverVersion, environment, queryInfo.getSession().getCatalog().orElse(null), queryInfo.getSession().getSchema().orElse(null), queryInfo.getSession().getRemoteUserAddress().orElse(null), queryInfo.getSession().getUserAgent().orElse(null), queryInfo.getState(), queryInfo.getSelf(), queryInfo.getFieldNames(), queryInfo.getQuery(), queryStats.getPeakMemoryReservation().toBytes(), queryStats.getCreateTime(), queryStats.getExecutionStartTime(), queryStats.getEndTime(), queryStats.getQueuedTime(), queryStats.getAnalysisTime(), queryStats.getDistributedPlanningTime(), queryStats.getTotalScheduledTime(), queryStats.getTotalCpuTime(), queryStats.getRawInputDataSize(), queryStats.getRawInputPositions(), queryStats.getTotalDrivers(), queryInfo.getErrorCode(), failureType, failureMessage, failureTask, failureHost, objectMapper.writeValueAsString(queryInfo.getOutputStage()), objectMapper.writeValueAsString(queryInfo.getFailureInfo()), objectMapper.writeValueAsString(queryInfo.getInputs()), objectMapper.writeValueAsString(mergedProperties.build()))); logQueryTimeline(queryInfo); } catch (JsonProcessingException e) { throw Throwables.propagate(e); } }
From source file:org.opendaylight.mdsal.dom.broker.ShardedDOMDataTreeProducer.java
@Override public synchronized DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) { Preconditions.checkState(!closed, "Producer is already closed"); Preconditions.checkState(openTx == null, "Transaction %s is still open", openTx); for (final DOMDataTreeIdentifier s : subtrees) { // Check if the subtree was visible at any time Preconditions.checkArgument(haveSubtree(s), "Subtree %s was never available in producer %s", s, this); // Check if the subtree has not been delegated to a child final DOMDataTreeProducer child = lookupChild(s); Preconditions.checkArgument(child == null, "Subtree %s is delegated to child producer %s", s, child); // Check if part of the requested subtree is not delegated to a child. for (final DOMDataTreeIdentifier c : children.keySet()) { if (s.contains(c)) { throw new IllegalArgumentException(String.format( "Subtree %s cannot be delegated as it is superset of already-delegated %s", s, c)); }// w w w. ja va 2 s . c o m } } final DOMDataTreeProducer ret = dataTree.createProducer(this, subtrees); final ImmutableMap.Builder<DOMDataTreeIdentifier, DOMDataTreeProducer> cb = ImmutableMap.builder(); cb.putAll(children); for (final DOMDataTreeIdentifier s : subtrees) { cb.put(s, ret); } children = cb.build(); return ret; }
From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystemView.java
@Override public DefaultProjectFilesystemView withView(Path newRelativeRoot, ImmutableSet<PathMatcher> additionalIgnores) { Path newRoot = projectRoot.resolve(newRelativeRoot); Path resolvedNewRoot = filesystemParent.resolve(newRoot); ImmutableMap.Builder<PathMatcher, Predicate<Path>> mapBuilder = ImmutableMap .builderWithExpectedSize(ignoredPaths.size() + additionalIgnores.size()); mapBuilder.putAll(ignoredPaths); for (PathMatcher p : additionalIgnores) { mapBuilder.put(p, path -> p.matches(resolvedNewRoot.relativize(path))); }// w w w.ja va 2s . c om return new DefaultProjectFilesystemView(filesystemParent, newRoot, resolvedNewRoot, mapBuilder.build()); }
From source file:io.prestosql.orc.writer.ListColumnWriter.java
@Override public Map<Integer, ColumnEncoding> getColumnEncodings() { ImmutableMap.Builder<Integer, ColumnEncoding> encodings = ImmutableMap.builder(); encodings.put(column, columnEncoding); encodings.putAll(elementWriter.getColumnEncodings()); return encodings.build(); }
From source file:com.microsoft.thrifty.schema.Service.java
Service(ServiceElement element, ThriftType type, Map<NamespaceScope, String> namespaces, FieldNamingPolicy fieldNamingPolicy) { super(element.name(), namespaces); this.element = element; this.type = type; ImmutableList.Builder<ServiceMethod> methods = ImmutableList.builder(); for (FunctionElement functionElement : element.functions()) { ServiceMethod method = new ServiceMethod(functionElement, fieldNamingPolicy); methods.add(method);/*from w ww . j a va 2s . c o m*/ } this.methods = methods.build(); ImmutableMap.Builder<String, String> annotationBuilder = ImmutableMap.builder(); AnnotationElement anno = element.annotations(); if (anno != null) { annotationBuilder.putAll(anno.values()); } this.annotations = annotationBuilder.build(); }
From source file:com.facebook.presto.orc.writer.MapColumnWriter.java
@Override public Map<Integer, ColumnEncoding> getColumnEncodings() { ImmutableMap.Builder<Integer, ColumnEncoding> encodings = ImmutableMap.builder(); encodings.put(column, columnEncoding); encodings.putAll(keyWriter.getColumnEncodings()); encodings.putAll(valueWriter.getColumnEncodings()); return encodings.build(); }
From source file:edu.berkeley.compbio.ml.cluster.bayesian.LabelDecomposingBayesianClustering.java
/** * {@inheritDoc}/*from w ww . j a v a 2 s. c o m*/ */ public void initializeWithSamples(final ClusterableIterator<T> trainingIterator, final int initSamples) //GenericFactory<T> prototypeFactory) // throws ClusterException { final Map<String, GrowableKmeansClustering<T>> theSubclusteringMap = new HashMap<String, GrowableKmeansClustering<T>>(); if (predictLabelSets.size() > 1) { throw new ClusterRuntimeException( "LabelDecomposingBayesianClustering can't yet handle more than one exclusive label set at a time: " + predictLabelSets.keySet()); } final Set<String> predictLabels = predictLabelSets.values().iterator().next(); try { // BAD consume the entire iterator, ignoring initsamples final Multinomial<Cluster<T>> priorsMult = new Multinomial<Cluster<T>>(); try { int i = 0; while (true) { final T point = trainingIterator.nextFullyLabelled(); final String bestLabel = point.getImmutableWeightedLabels().getDominantKeyInSet(predictLabels); //Cluster<T> cluster = theClusterMap.get(bestLabel); GrowableKmeansClustering<T> theIntraLabelClustering = theSubclusteringMap.get(bestLabel); if (theIntraLabelClustering == null) { theIntraLabelClustering = new GrowableKmeansClustering<T>(measure, potentialTrainingBins, predictLabelSets, prohibitionModel, testLabels); theSubclusteringMap.put(bestLabel, theIntraLabelClustering); } // naive online agglomerative clustering: // add points to clusters in the order they arrive, one pass only, create new clusters as needed // the resulting clustering may suck, but it should still more or less span the space of the inputs, // so it may work well enough for this purpose. // doing proper k-means would be nicer, but then we'd have to store all the training points, or re-iterate them somehow. final ClusterMove<T, CentroidCluster<T>> cm = theIntraLabelClustering.bestClusterMove(point); CentroidCluster<T> cluster = cm.bestCluster; if (cm.bestDistance > unknownDistanceThreshold) { logger.debug("Creating new subcluster (" + cm.bestDistance + " > " + unknownDistanceThreshold + ") for " + bestLabel); cluster = new AdditiveCentroidCluster<T>(i++, prototypeFactory.create()); //cluster.setId(i++); // add the new cluster to the local per-label clustering... theIntraLabelClustering.addCluster(cluster); // ... and also to the overall clustering addCluster(cluster); // REVIEW for now we make a uniform prior priorsMult.put(cluster, 1); } cluster.add(point); /* if(cluster.getLabelCounts().uniqueSet().size() != 1) { throw new Error(); }*/ } } catch (NoSuchElementException e) { // iterator exhausted } priorsMult.normalize(); // clusterPriors = priorsMult.getValueMap(); final ImmutableMap.Builder<Cluster<T>, Double> builder = ImmutableMap.builder(); clusterPriors = builder.putAll(priorsMult.getValueMap()).build(); //theClusters = theSubclusteringMap.values(); for (final Map.Entry<String, GrowableKmeansClustering<T>> entry : theSubclusteringMap.entrySet()) { final String label = entry.getKey(); final GrowableKmeansClustering<T> theIntraLabelClustering = entry.getValue(); if (logger.isInfoEnabled()) { logger.info("Created " + theIntraLabelClustering.getClusters().size() + " clusters from " + theIntraLabelClustering.getN() + " points for " + label); } } } catch (DistributionException e) { throw new ClusterRuntimeException(e); } catch (GenericFactoryException e) { throw new ClusterRuntimeException(e); } }
From source file:com.turbospaces.collections.OffHeapLinearProbingSet.java
@Override public ImmutableMap<?, ?> toImmutableMap() { com.google.common.collect.ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder(); for (OffHeapLinearProbingSegment entry : segments) builder.putAll(entry.toImmutableMap()); return builder.build(); }
From source file:io.prestosql.orc.writer.ListColumnWriter.java
@Override public Map<Integer, ColumnStatistics> finishRowGroup() { checkState(!closed);/*from ww w . j av a 2s . c o m*/ ColumnStatistics statistics = new ColumnStatistics((long) nonNullValueCount, 0, null, null, null, null, null, null, null, null); rowGroupColumnStatistics.add(statistics); nonNullValueCount = 0; ImmutableMap.Builder<Integer, ColumnStatistics> columnStatistics = ImmutableMap.builder(); columnStatistics.put(column, statistics); columnStatistics.putAll(elementWriter.finishRowGroup()); return columnStatistics.build(); }
From source file:org.auraframework.impl.util.json.AuraJsonSerializerFactory.java
@PostConstruct private void initSerializerMaps() { synchronized (lock) { if (SERIALIZERS_LOOKUP_MAP != null) { return; }/*from ww w . ja v a 2s .c o m*/ ImmutableMap.Builder<String, JsonSerializer<?>> b = ImmutableMap.builder(); ImmutableMap.Builder<Class<?>, JsonSerializer<?>> b2 = ImmutableMap.builder(); for (JsonSerializerAdapter a : jsonSerializerAdapters) { b.putAll(a.lookupSerializers()); b2.putAll(a.instanceofSerializers()); } SERIALIZERS_LOOKUP_MAP = b.build(); SERIALIZERS_INSTANCE_MAP = b2.build(); } }