List of usage examples for com.google.common.collect Maps newLinkedHashMap
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap()
From source file:org.eclipse.xtext.parsetree.reconstr.impl.TreeConstState.java
protected void calculateDistances(TreeConstState root, int dist) { if (distances == null) distances = Maps.newLinkedHashMap(); else if (distances.containsKey(root) && distances.get(root) <= dist) return;/*from w w w . j a v a 2 s . c o m*/ distances.put(root, dist); if (isConsumingElement()) { root = this; dist = 0; } for (TreeConstTransition t : concat(getOutgoing(), getOutgoingAfterReturn())) if (!t.isRuleCall()) t.getTarget().calculateDistances(root, dist + 1); if (isEndState()) getEndDistances().put(root, dist + 1); }
From source file:co.cask.tigon.sql.ioserver.JsonInputServerSocket.java
@Override public LinkedHashMap<String, ChannelHandler> addTransformHandler() { LinkedHashMap<String, ChannelHandler> handlers = Maps.newLinkedHashMap(); handlers.put("jsonMapDelimiter", new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, false, ChannelBuffers.wrappedBuffer(new byte[] { '}' }))); handlers.put("stringDecoder", new StringDecoder()); handlers.put("jsonHandler", new JsonHandler(schema)); return handlers; }
From source file:com.google.caliper.runner.instrument.JarFinder.java
@VisibleForTesting static ImmutableMap<File, ClassLoader> getClassPathEntries(ClassLoader classloader) { Map<File, ClassLoader> entries = Maps.newLinkedHashMap(); // Search parent first, since it's the order ClassLoader#loadClass() uses. ClassLoader parent = classloader.getParent(); if (parent != null) { entries.putAll(getClassPathEntries(parent)); }/*from w ww . java 2s . c o m*/ for (URL url : getClassLoaderUrls(classloader)) { if (url.getProtocol().equals("file")) { File file = toFile(url); if (!entries.containsKey(file)) { entries.put(file, classloader); } } } return ImmutableMap.copyOf(entries); }
From source file:org.jpmml.postgresql.PMMLUtil.java
static private Map<FieldName, FieldValue> loadScalarList(Evaluator evaluator, List<?> request) { Map<FieldName, FieldValue> result = Maps.newLinkedHashMap(); List<FieldName> fields = evaluator.getActiveFields(); if (fields.size() != request.size()) { throw new IllegalArgumentException("Invalid number of arguments"); }/*from w w w .j av a2 s. c om*/ int i = 0; for (FieldName field : fields) { FieldValue value = EvaluatorUtil.prepare(evaluator, field, request.get(i)); result.put(field, value); i++; } return result; }
From source file:edu.udo.scaffoldhunter.model.clustering.evaluation.StatisticsMetaModule.java
/** * Return one new {@link EvaluationResult} with the statistics of the * {@link EvaluationResult}s with the same settings. * // ww w. j a v a2 s . c om * @param results * @return */ @Override protected EvaluationResult accumulateSingleGroup(Collection<EvaluationResult> results) { Preconditions.checkArgument(results.size() > 0); int collectionSize = results.size(); EvaluationResult arbitraryResult = results.iterator().next(); EvaluationResult retVal = EvaluationResult.copyEvaluationResultSettings(arbitraryResult); retVal.setMeasurement(retVal.getMeasurement() + "-statistics of " + collectionSize + " values"); LinkedHashMap<String, Double> statistics = Maps.newLinkedHashMap(); for (String key : arbitraryResult.getResults().keySet()) { int accumulationCount = 0; for (EvaluationResult result : results) { try { Double currentVal = Double.parseDouble(result.getResults().get(key)); /* * calculate min, max average */ accumulationCount++; Double oldVal = statistics.get(key + "__statistics_min"); statistics.put(key + "__statistics_min", Math.min(currentVal, oldVal == null ? currentVal : oldVal)); oldVal = statistics.get(key + "__statistics_max"); statistics.put(key + "__statistics_max", Math.max(currentVal, oldVal == null ? currentVal : oldVal)); oldVal = statistics.get(key + "__statistics_avg"); statistics.put(key + "__statistics_avg", ((accumulationCount - 1) * (oldVal == null ? 0 : oldVal) + currentVal) / accumulationCount); } catch (NumberFormatException ex) { logger.warn("Number format {} could not be parsed. Skipping value for key {} in accumulation.", result.getResults().get(key), key); } } if (accumulationCount == 0) { statistics.put(key + key + "__statistics_min", null); statistics.put(key + key + "__statistics_max", null); statistics.put(key + key + "__statistics_avg", null); statistics.put(key + key + "__statistics_dev", null); } else { // calculate standard deviation Double average = statistics.get(key + "__statistics_avg"); double standardDeviation = 0; for (EvaluationResult result : results) { try { double currentVal = Double.parseDouble(result.getResults().get(key)); standardDeviation += Math.pow(currentVal - average, 2); } catch (NumberFormatException ex) { /* * no warning here because we already warned about * number format above */ } } standardDeviation = Math.sqrt(1.0 / accumulationCount * standardDeviation); statistics.put(key + "__statistics_dev", standardDeviation); } } // add new accumulated results to retVal for (Entry<String, Double> singleResult : statistics.entrySet()) { Double value = singleResult.getValue(); retVal.addResult(singleResult.getKey(), value == null ? "NA" : value.toString()); } return retVal; }
From source file:org.jclouds.blobstore.strategy.internal.PutBlobsStrategyImpl.java
@Override public void execute(String containerName, Iterable<? extends Blob> blobs) { Map<Blob, ListenableFuture<?>> responses = Maps.newLinkedHashMap(); for (Blob blob : blobs) { responses.put(blob, ablobstore.putBlob(containerName, blob)); }//from ww w .ja va2 s.c o m Map<Blob, Exception> exceptions; try { exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, String.format("putting into containerName: %s", containerName)); } catch (TimeoutException te) { throw propagate(te); } if (exceptions.size() > 0) throw new BlobRuntimeException( String.format("error putting into container %s: %s", containerName, exceptions)); }
From source file:org.jclouds.elasticstack.functions.MapToStandardDrive.java
@Override public StandardDrive apply(Map<String, String> from) { if (from.isEmpty()) return null; StandardDrive.Builder builder = new StandardDrive.Builder(); builder.name(from.get("name")); builder.media(MediaType.fromValue(from.get("media"))); if (from.containsKey("tags")) builder.tags(Splitter.on(' ').split(from.get("tags"))); builder.uuid(from.get("drive")); if (from.containsKey("claim:type")) builder.claimType(ClaimType.fromValue(from.get("claim:type"))); if (from.containsKey("readers")) builder.readers(Splitter.on(' ').split(from.get("readers"))); if (from.containsKey("size")) builder.size(Long.parseLong(from.get("size"))); if (from.containsKey("rawsize")) builder.rawSize(Long.parseLong(from.get("rawsize"))); if (from.containsKey("format")) builder.format(ImageConversionType.fromValue(from.get("format"))); Map<String, String> metadata = Maps.newLinkedHashMap(); for (Entry<String, String> entry : from.entrySet()) { String key = entry.getKey(); if (key.startsWith("user:")) metadata.put(key.substring(key.indexOf(':') + 1), entry.getValue()); }/*from w ww .j a va 2 s. c o m*/ builder.userMetadata(metadata); try { return builder.build(); } catch (NullPointerException e) { logger.warn("entry missing data: %s; %s", e.getMessage(), from); return null; } }
From source file:org.ldp4j.tutorial.client.CachedRepresentationManager.java
private CachedRepresentationManager(File cacheDirectory) { this.cacheDirectory = cacheDirectory; this.loadedResources = Maps.newLinkedHashMap(); }
From source file:com.sk89q.guavabackport.cache.AbstractCache.java
/** * This implementation of {@code getAllPresent} lacks any insight into the internal cache data * structure, and is thus forced to return the query keys instead of the cached keys. This is only * possible with an unsafe cast which requires {@code keys} to actually be of type {@code K}. * * {@inheritDoc}//from w w w . ja v a 2 s. c o m * * @since 11.0 */ @Override public ImmutableMap<K, V> getAllPresent(Iterable<?> keys) { Map<K, V> result = Maps.newLinkedHashMap(); for (Object key : keys) { if (!result.containsKey(key)) { @SuppressWarnings("unchecked") K castKey = (K) key; result.put(castKey, getIfPresent(key)); } } return ImmutableMap.copyOf(result); }
From source file:org.jetbrains.jet.lang.resolve.calls.inference.DebugConstraintResolutionListener.java
@Override public void constraintsForKnownType(JetType type, BoundsOwner typeValue) { if (!ResolutionDebugInfo.isResolutionDebugEnabled()) return;/*w w w . j ava 2 s .co m*/ Map<JetType, BoundsOwner> map = debugInfo.getByKey(BOUNDS_FOR_KNOWNS, candidateCall); if (map == null) { map = Maps.newLinkedHashMap(); debugInfo.putByKey(BOUNDS_FOR_KNOWNS, candidateCall, map); } map.put(type, typeValue); }