List of usage examples for com.google.common.collect ImmutableSortedMap.Builder put
V put(K key, V value);
From source file:org.ambraproject.wombat.model.TaxonomyGraph.java
/** * @param categoryPaths a list of all slash-delimited category paths in the taxonomy * @return a parsed graph representation of the taxonomy *///w w w .j a va 2 s . com public static TaxonomyGraph create(Collection<String> categoryPaths) { Set<String> names = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); SortedSetMultimap<String, String> parentsToChildren = caseInsensitiveSetMultimap(); SortedSetMultimap<String, String> childrenToParents = caseInsensitiveSetMultimap(); for (String categoryPath : categoryPaths) { List<String> categories = parseTerms(categoryPath); for (int i = 0; i < categories.size(); i++) { String node = categories.get(i); names.add(node); if (i > 0) { String parent = categories.get(i - 1); parentsToChildren.put(parent, node); childrenToParents.put(node, parent); } } } ImmutableSortedMap.Builder<String, CategoryInfo> categoryMap = ImmutableSortedMap .orderedBy(String.CASE_INSENSITIVE_ORDER); for (String name : names) { categoryMap.put(name, new CategoryInfo(name, childrenToParents.get(name), parentsToChildren.get(name))); } return new TaxonomyGraph(categoryMap.build()); }
From source file:org.gradle.api.internal.changedetection.state.TaskExecutionSnapshotSerializer.java
private static ImmutableSortedMap<String, Long> readSnapshotIds(Decoder decoder) throws IOException { int count = decoder.readSmallInt(); ImmutableSortedMap.Builder<String, Long> builder = ImmutableSortedMap.naturalOrder(); for (int snapshotIdx = 0; snapshotIdx < count; snapshotIdx++) { String property = decoder.readString(); long id = decoder.readLong(); builder.put(property, id); }/*from w w w. jav a 2 s .c o m*/ return builder.build(); }
From source file:org.apache.calcite.rel.core.Match.java
/** Creates an immutable copy of a map of sorted sets. */ private static <K extends Comparable<K>, V> ImmutableSortedMap<K, SortedSet<V>> copy(Map<K, SortedSet<V>> map) { final ImmutableSortedMap.Builder<K, SortedSet<V>> b = ImmutableSortedMap.naturalOrder(); for (Map.Entry<K, SortedSet<V>> e : map.entrySet()) { b.put(e.getKey(), ImmutableSortedSet.copyOf(e.getValue())); }/*from ww w . j a v a 2s . com*/ return b.build(); }
From source file:edu.mit.streamjit.util.bytecode.methodhandles.Combinators.java
/** * Returns a method handle with a leading int argument that selects one of * the method handles in the given array, which is invoked with the * remaining arguments. Modifications to the array after this method returns * do not affect the behavior of the returned handle. * @param cases the switch cases/*from w w w . ja v a2 s. c o m*/ * @return a method handle approximating the switch statement * @see #tableswitch(java.lang.invoke.MethodHandle[]) */ public static MethodHandle lookupswitch(MethodHandle[] cases) { ImmutableSortedMap.Builder<Integer, MethodHandle> casesMap = ImmutableSortedMap.naturalOrder(); for (int i = 0; i < cases.length; ++i) casesMap.put(i, cases[i]); return lookupswitch(casesMap.build()); }
From source file:com.facebook.buck.java.AccumulateClassNamesStep.java
/** * @param lines that were written in the same format output by {@link #execute(ExecutionContext)}. *///from w w w . j a va 2s. c om public static ImmutableSortedMap<String, HashCode> parseClassHashes(List<String> lines) { ImmutableSortedMap.Builder<String, HashCode> classNamesBuilder = ImmutableSortedMap.naturalOrder(); for (String line : lines) { List<String> parts = CLASS_NAME_AND_HASH_SPLITTER.splitToList(line); Preconditions.checkState(parts.size() == 2); String key = parts.get(0); HashCode value = HashCode.fromString(parts.get(1)); classNamesBuilder.put(key, value); } return classNamesBuilder.build(); }
From source file:org.jclouds.s3.filters.Aws4SignerBase.java
/** * change the keys but keep the values in-tact. * * @param in input map to transform/*from w w w . java 2 s . co m*/ * @return immutableSortedMap with the new lowercase keys. */ protected static Map<String, String> lowerCaseNaturalOrderKeys(Map<String, String> in) { checkNotNull(in, "input map"); ImmutableSortedMap.Builder<String, String> returnVal = ImmutableSortedMap.<String, String>naturalOrder(); for (Map.Entry<String, String> entry : in.entrySet()) returnVal.put(entry.getKey().toLowerCase(Locale.US), entry.getValue()); return returnVal.build(); }
From source file:eu.eidas.auth.commons.attribute.AttributeSetPropertiesConverter.java
/** * Converts the given Iterable of <code>AttributeDefinition</code>s to an immutable sorted Map of Strings. * * @param properties the Iterable of <code>AttributeDefinition</code>s * @return an immutable sorted Map of Strings. *//* ww w .j a va 2 s. co m*/ @Nonnull public static ImmutableSortedMap<String, String> toMap(@Nonnull Iterable<AttributeDefinition<?>> attributes) { ImmutableSortedMap.Builder<String, String> builder = new ImmutableSortedMap.Builder<String, String>( Ordering.natural()); int i = 0; for (AttributeDefinition<?> attributeDefinition : attributes) { String id = String.valueOf(++i); builder.put(Suffix.NAME_URI.computeEntry(id), attributeDefinition.getNameUri().toASCIIString()); builder.put(Suffix.FRIENDLY_NAME.computeEntry(id), attributeDefinition.getFriendlyName()); builder.put(Suffix.PERSON_TYPE.computeEntry(id), attributeDefinition.getPersonType().getValue()); builder.put(Suffix.REQUIRED.computeEntry(id), String.valueOf(attributeDefinition.isRequired())); if (attributeDefinition.isTransliterationMandatory()) { builder.put(Suffix.TRANSLITERATION_MANDATORY.computeEntry(id), Boolean.TRUE.toString()); } if (attributeDefinition.isUniqueIdentifier()) { builder.put(Suffix.UNIQUE_IDENTIFIER.computeEntry(id), Boolean.TRUE.toString()); } QName xmlType = attributeDefinition.getXmlType(); builder.put(Suffix.XML_TYPE_NAMESPACE_URI.computeEntry(id), String.valueOf(xmlType.getNamespaceURI())); builder.put(Suffix.XML_TYPE_LOCAL_PART.computeEntry(id), String.valueOf(xmlType.getLocalPart())); builder.put(Suffix.XML_TYPE_NAMESPACE_PREFIX.computeEntry(id), String.valueOf(xmlType.getPrefix())); builder.put(Suffix.ATTRIBUTE_VALUE_MARSHALLER.computeEntry(id), attributeDefinition.getAttributeValueMarshaller().getClass().getName()); } return builder.build(); }
From source file:net.morimekta.idltool.IdlUtils.java
public static Map<String, String> buildSha1Sums(Path dir) throws IOException { ImmutableSortedMap.Builder<String, String> sha1sums = ImmutableSortedMap.naturalOrder(); // TODO: Support nested directories. Files.list(dir).forEach(file -> { try {//from w w w .ja v a 2s . co m if (Files.isRegularFile(file)) { String sha = DigestUtils.sha1Hex(Files.readAllBytes(file)); sha1sums.put(file.getFileName().toString(), sha); } } catch (IOException e) { throw new UncheckedIOException(e.getMessage(), e); } }); return sha1sums.build(); }
From source file:com.palantir.atlasdb.keyvalue.impl.Cells.java
/** * The Collection provided to this function has to be sorted and strictly increasing. *//*ww w . j a va 2s. c o m*/ public static <T> Iterator<RowResult<T>> createRowView(final Collection<Map.Entry<Cell, T>> sortedIterator) { final PeekingIterator<Entry<Cell, T>> it = Iterators.peekingIterator(sortedIterator.iterator()); Iterator<Map.Entry<byte[], SortedMap<byte[], T>>> resultIt = new AbstractIterator<Map.Entry<byte[], SortedMap<byte[], T>>>() { byte[] row = null; SortedMap<byte[], T> map = null; @Override protected Entry<byte[], SortedMap<byte[], T>> computeNext() { if (!it.hasNext()) { return endOfData(); } row = it.peek().getKey().getRowName(); ImmutableSortedMap.Builder<byte[], T> mapBuilder = ImmutableSortedMap .orderedBy(UnsignedBytes.lexicographicalComparator()); while (it.hasNext()) { Entry<Cell, T> peek = it.peek(); if (!Arrays.equals(peek.getKey().getRowName(), row)) { break; } mapBuilder.put(peek.getKey().getColumnName(), peek.getValue()); it.next(); } map = mapBuilder.build(); return Maps.immutableEntry(row, map); } }; return RowResults.viewOfEntries(resultIt); }
From source file:com.google.template.soy.TemplateMetadataSerializer.java
private static SoyType fromProto(SoyTypeP proto, SoyTypeRegistry typeRegistry, String filePath, ErrorReporter errorReporter) {//from ww w . j av a 2s.c om switch (proto.getTypeKindCase()) { case PRIMITIVE: switch (proto.getPrimitive()) { case ANY: return AnyType.getInstance(); case UNKNOWN: return UnknownType.getInstance(); case INT: return IntType.getInstance(); case NULL: return NullType.getInstance(); case BOOL: return BoolType.getInstance(); case FLOAT: return FloatType.getInstance(); case STRING: return StringType.getInstance(); case HTML: return HtmlType.getInstance(); case ATTRIBUTES: return AttributesType.getInstance(); case JS: return JsType.getInstance(); case CSS: return StyleType.getInstance(); case URI: return UriType.getInstance(); case TRUSTED_RESOURCE_URI: return TrustedResourceUriType.getInstance(); case VE_DATA: return VeDataType.getInstance(); case UNRECOGNIZED: case UNKNOWN_PRIMITIVE_TYPE: // fall-through } throw new AssertionError("Unknown primitive: " + proto.getPrimitive()); case LIST_ELEMENT: return typeRegistry .getOrCreateListType(fromProto(proto.getListElement(), typeRegistry, filePath, errorReporter)); case LEGACY_OBJECT_MAP: return typeRegistry.getOrCreateLegacyObjectMapType( fromProto(proto.getLegacyObjectMap().getKey(), typeRegistry, filePath, errorReporter), fromProto(proto.getLegacyObjectMap().getValue(), typeRegistry, filePath, errorReporter)); case MAP: return typeRegistry.getOrCreateMapType( fromProto(proto.getMap().getKey(), typeRegistry, filePath, errorReporter), fromProto(proto.getMap().getValue(), typeRegistry, filePath, errorReporter)); case PROTO: { SoyType type = typeRegistry.getType(proto.getProto()); if (type == null) { errorReporter.report(new SourceLocation(filePath), UNABLE_TO_FIND_TYPE, "proto", proto.getProto()); return ErrorType.getInstance(); } // allow unknown to support message extraction which configures the DEFAULT_UNKNOWN type // registry if (type instanceof SoyProtoType || type == UnknownType.getInstance()) { return type; } errorReporter.report(new SourceLocation(filePath), UNEXPECTED_TYPE, proto.getProto(), "proto", type.getKind()); return ErrorType.getInstance(); } case PROTO_ENUM: { SoyType type = typeRegistry.getType(proto.getProtoEnum()); if (type == null) { errorReporter.report(new SourceLocation(filePath), UNABLE_TO_FIND_TYPE, "proto enum", proto.getProtoEnum()); return ErrorType.getInstance(); } // allow unknown to support message extraction which configures the DEFAULT_UNKNOWN type // registry if (type instanceof SoyProtoEnumType || type == UnknownType.getInstance()) { return type; } errorReporter.report(new SourceLocation(filePath), UNEXPECTED_TYPE, proto.getProtoEnum(), "proto enum", type.getKind()); return ErrorType.getInstance(); } case RECORD: { ImmutableSortedMap.Builder<String, SoyType> members = ImmutableSortedMap.naturalOrder(); for (Map.Entry<String, SoyTypeP> entry : proto.getRecord().getFieldMap().entrySet()) { members.put(entry.getKey(), fromProto(entry.getValue(), typeRegistry, filePath, errorReporter)); } return typeRegistry.getOrCreateRecordType(members.build()); } case UNION: { List<SoyType> members = new ArrayList<>(proto.getUnion().getMemberCount()); for (SoyTypeP member : proto.getUnion().getMemberList()) { members.add(fromProto(member, typeRegistry, filePath, errorReporter)); } return typeRegistry.getOrCreateUnionType(members); } case VE: return typeRegistry.getOrCreateVeType(proto.getVe()); case TYPEKIND_NOT_SET: // fall-through } throw new AssertionError("unhandled typeKind: " + proto.getTypeKindCase()); }