List of usage examples for com.google.common.collect Maps newLinkedHashMap
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap()
From source file:org.jclouds.json.internal.IgnoreNullMapTypeAdapterFactory.java
private <K, V> TypeAdapter<Map<K, V>> newMapAdapter(final TypeAdapter<K> keyAdapter, final TypeAdapter<V> valueAdapter) { return new TypeAdapter<Map<K, V>>() { public void write(JsonWriter out, Map<K, V> value) throws IOException { out.beginObject();// w ww . j av a2s . c o m for (Map.Entry<K, V> element : value.entrySet()) { out.name(String.valueOf(element.getKey())); valueAdapter.write(out, element.getValue()); } out.endObject(); } public Map<K, V> read(JsonReader in) throws IOException { Map<K, V> result = Maps.newLinkedHashMap(); in.beginObject(); while (in.hasNext()) { JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); K name = keyAdapter.read(in); V value = valueAdapter.read(in); if (value != null) result.put(name, value); } in.endObject(); return result; } }.nullSafe(); }
From source file:org.apache.brooklyn.rest.resources.PolicyConfigResource.java
@Override public Map<String, Object> batchConfigRead(String application, String entityToken, String policyToken) { // TODO: add test Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); Map<String, Object> source = ((BrooklynObjectInternal) policy).config().getBag().getAllConfig(); Map<String, Object> result = Maps.newLinkedHashMap(); for (Map.Entry<String, Object> ek : source.entrySet()) { result.put(ek.getKey(), getStringValueForDisplay(brooklyn(), policy, ek.getValue())); }/*from w w w . ja v a 2 s. com*/ return result; }
From source file:eu.project.ttc.utils.TermSuiteUtils.java
public static <T> LinkedHashMap<T, Integer> getCounters(Iterable<T> list) { Comparator<Entry<T, MutableInt>> comparator = new Comparator<Entry<T, MutableInt>>() { public int compare(Entry<T, MutableInt> o1, Entry<T, MutableInt> o2) { return ComparisonChain.start().compare(o2.getValue(), o1.getValue()).result(); };/*from ww w . j av a 2 s . c o m*/ }; Map<T, MutableInt> map = Maps.newHashMap(); for (T e : list) { MutableInt counter = map.get(e); if (counter == null) { counter = new MutableInt(0); map.put(e, counter); } counter.increment(); } List<Entry<T, MutableInt>> entries = Lists.newArrayList(map.entrySet()); Collections.sort(entries, comparator); LinkedHashMap<T, Integer> counters = Maps.newLinkedHashMap(); for (Entry<T, MutableInt> e : entries) counters.put(e.getKey(), e.getValue().intValue()); return counters; }
From source file:org.apache.brooklyn.rest.resources.PolicyResource.java
@Override public Map<String, Boolean> batchConfigRead(String application, String entityToken) { // TODO: add test Entity entity = brooklyn().getEntity(application, entityToken); Map<String, Boolean> result = Maps.newLinkedHashMap(); for (Policy p : entity.policies()) { result.put(p.getId(), !p.isSuspended()); }// ww w . j a v a 2 s.c o m return result; }
From source file:cn.pay.ebank.common.beans.enums.CertTypeEnum.java
public static Map<String, String> mapping() { Map<String, String> map = Maps.newLinkedHashMap(); for (CertTypeEnum type : values()) { map.put(type.getCode(), type.getMessage()); }//from w ww .j av a2 s .c om return map; }
From source file:brooklyn.entity.rebind.Dumpers.java
public static void logUnserializableChains(Object root, final ObjectReplacer replacer) throws IllegalArgumentException, IllegalAccessException { final Map<List<Object>, Class<?>> unserializablePaths = Maps.newLinkedHashMap(); Visitor visitor = new Visitor() { @Override/*from w ww . ja v a2 s . co m*/ public boolean visit(Object o, Iterable<Object> refChain) { try { Serializers.reconstitute(o, replacer); return true; } catch (Throwable e) { Exceptions.propagateIfFatal(e); // not serializable in some way: report ImmutableList<Object> refChainList = ImmutableList.copyOf(refChain); // for debugging it can be useful to turn this on // LOG.warn("Unreconstitutable object detected ("+o+"): "+e); // First strip out any less specific paths for (Iterator<List<Object>> iter = unserializablePaths.keySet().iterator(); iter.hasNext();) { List<Object> existing = iter.next(); if (refChainList.size() >= existing.size() && refChainList.subList(0, existing.size()).equals(existing)) { iter.remove(); } } // Then add this list unserializablePaths.put(ImmutableList.copyOf(refChainList), o.getClass()); return false; } } }; deepVisitInternal(root, SERIALIZED_FIELD_PREDICATE, Lists.newArrayList(), new LinkedList<Object>(), visitor); LOG.warn("Not serializable (" + root + "):"); for (Map.Entry<List<Object>, Class<?>> entry : unserializablePaths.entrySet()) { StringBuilder msg = new StringBuilder("\t" + "type=" + entry.getValue() + "; chain=" + "\n"); for (Object chainElement : entry.getKey()) { // try-catch motivated by NPE in org.jclouds.domain.LoginCredentials.toString String chainElementStr; try { chainElementStr = chainElement.toString(); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.error("Error calling toString on instance of " + chainElement.getClass(), e); chainElementStr = "<error " + e.getClass().getSimpleName() + " in toString>"; } msg.append("\t\t" + "type=").append(chainElement.getClass()).append("; val=") .append(chainElementStr).append("\n"); } LOG.warn(msg.toString()); } }
From source file:exec.csharp.evaluation.impl.F1Details.java
private void storeResult(QueryMode queryMode, String key, double f1) { Map<String, BoxplotData> keys = res.get(queryMode); if (keys == null) { keys = Maps.newLinkedHashMap(); res.put(queryMode, keys);//from w w w.java 2 s . c om } BoxplotData f1s = keys.get(key); if (f1s == null) { f1s = new BoxplotData(); keys.put(key, f1s); } f1s.add(f1); }
From source file:ch.puzzle.itc.mobiliar.business.generator.control.extracted.templates.GenerationPackage.java
/** * @return all Application GenerationUnit Sets *//*from w w w . j a v a2s . c o m*/ public Map<ResourceEntity, Set<GenerationUnit>> getAppGenerationBatches() { List<GenerationSubPackage> result = new ArrayList<GenerationSubPackage>(); // Applications with consumed Resources are Added as generationSubPackage for (GenerationSubPackage generationPackage : generationSubPackages) { if (generationPackage.getPackageGenerationUnit().getSlaveResource().getResourceType() .isApplicationResourceType()) { result.add(generationPackage); } } Map<ResourceEntity, Set<GenerationUnit>> map = Maps.newLinkedHashMap(); for (GenerationSubPackage generationSubPackage : result) { ResourceEntity resource = generationSubPackage.getPackageGenerationUnit().getSlaveResource(); map.put(resource, Sets.newLinkedHashSet(generationSubPackage.getSubGenerationUnitsAsList())); } List<GenerationSubPackage> applicationServerSubPackages = getApplicationServerSubPackages(); // also add empty Applications attached on the ApplicationServer, but without a SubPackage for (GenerationSubPackage generationSubPackage : applicationServerSubPackages) { for (GenerationUnit gu : generationSubPackage.getGenerationUnits()) { if (gu.getSlaveResource().getResourceType().isApplicationResourceType()) { if (!map.containsKey(gu.getSlaveResource())) { Set<GenerationUnit> units = Sets.newLinkedHashSet(); units.add(gu); map.put(gu.getSlaveResource(), units); } } } } return map; }
From source file:org.gradle.api.internal.attributes.DefaultImmutableAttributes.java
DefaultImmutableAttributes(DefaultImmutableAttributes parent, Attribute<?> key, Isolatable<?> value) { this.attribute = key; this.value = value; Map<Attribute<?>, DefaultImmutableAttributes> hierarchy = Maps.newLinkedHashMap(); hierarchy.putAll(parent.hierarchy);//w w w .jav a 2 s . co m hierarchy.put(attribute, this); this.hierarchy = ImmutableMap.copyOf(hierarchy); Map<String, DefaultImmutableAttributes> hierarchyByName = Maps.newLinkedHashMap(); hierarchyByName.putAll(parent.hierarchyByName); hierarchyByName.put(attribute.getName(), this); this.hierarchyByName = ImmutableMap.copyOf(hierarchyByName); int hashCode = parent.hashCode(); hashCode = 31 * hashCode + attribute.hashCode(); hashCode = 31 * hashCode + value.hashCode(); this.hashCode = hashCode; if (hierarchyByName.size() == 1) { Map.Entry<String, DefaultImmutableAttributes> entry = hierarchyByName.entrySet().iterator().next(); singleEntryName = entry.getKey(); singleEntryValue = entry.getValue(); } else { singleEntryName = null; singleEntryValue = null; } }
From source file:cc.recommenders.evaluation.distribution.calc.DefinitionSitesProvider.java
@Override protected Map<String, String> getOptions() { Map<String, String> options = Maps.newLinkedHashMap(); options.put("BMN", bmn().c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN0", pbn(0).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN15", pbn(15).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN25", pbn(25).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN30", pbn(30).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN40", pbn(40).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN60", pbn(60).c(false).d(false).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("BMN+DEF", bmn().c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN0+DEF", pbn(0).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN15+DEF", pbn(15).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN25+DEF", pbn(25).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN30+DEF", pbn(30).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN40+DEF", pbn(40).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN60+DEF", pbn(60).c(false).d(true).p(false).useFloat().qNM().ignore(false).min(30).get()); options.put("BMN+ALL", bmn().c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN0+ALL", pbn(0).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN15+ALL", pbn(15).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN25+ALL", pbn(25).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN30+ALL", pbn(30).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN40+ALL", pbn(40).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); options.put("PBN60+ALL", pbn(60).c(true).d(true).p(true).useFloat().qNM().ignore(false).min(30).get()); return options; }