List of usage examples for com.google.common.collect ImmutableSortedMap naturalOrder
public static <K extends Comparable<?>, V> Builder<K, V> naturalOrder()
From source file:com.fatboyindustrial.omnium.Maps.java
/** * Transforms the given map by applying a function to each of the keys. * @param input The input map.//from w w w. java 2 s. com * @param transform The transformation function to apply to the key. * @param <K1> The original key type. * @param <V> The map value type. * @param <K2> The transformed key type. * @return The new map. */ public static <K1 extends Comparable<K1>, V, K2 extends Comparable<K2>> ImmutableSortedMap<K2, V> keyTransform( final ImmutableSortedMap<K1, V> input, final Function<K1, K2> transform) { final ImmutableSortedMap.Builder<K2, V> builder = ImmutableSortedMap.naturalOrder(); input.forEach((key, value) -> builder.put(transform.apply(key), value)); return builder.build(); }
From source file:com.google.devtools.build.android.resources.FieldInitializers.java
public Iterable<Entry<ResourceType, Map<String, FieldInitializer>>> filter(FieldInitializers fieldsToWrite) { Map<ResourceType, Map<String, FieldInitializer>> initializersToWrite = new EnumMap<>(ResourceType.class); for (Entry<ResourceType, Map<String, FieldInitializer>> entry : fieldsToWrite.initializers.entrySet()) { if (initializers.containsKey(entry.getKey())) { final Map<String, FieldInitializer> valueFields = initializers.get(entry.getKey()); final ImmutableMap.Builder<String, FieldInitializer> fields = ImmutableSortedMap.naturalOrder(); // Resource type may be missing if resource overriding eliminates resources at the binary // level, which were originally present at the library level. for (String fieldName : Sets.intersection(entry.getValue().keySet(), valueFields.keySet())) { fields.put(fieldName, valueFields.get(fieldName)); }//from w w w . j a v a2s . c o m initializersToWrite.put(entry.getKey(), fields.build()); } } return initializersToWrite.entrySet(); }
From source file:org.voltdb.ElasticHashinator.java
/** * Initialize the hashinator from a binary description of the ring. * The serialization format is big-endian and the first value is the number of tokens * followed by the token values where each token value consists of the 8-byte position on the ring * and and the 4-byte partition id. All values are signed. *//*from w w w . ja v a 2s. c o m*/ public ElasticHashinator(byte configureBytes[]) { m_configBytes = Arrays.copyOf(configureBytes, configureBytes.length); ByteBuffer buf = ByteBuffer.wrap(configureBytes); int numEntries = buf.getInt(); TreeMap<Long, Integer> buildMap = new TreeMap<Long, Integer>(); for (int ii = 0; ii < numEntries; ii++) { final long token = buf.getLong(); final int partitionId = buf.getInt(); if (buildMap.containsKey(token)) { throw new RuntimeException( "Duplicate token " + token + " partition " + partitionId + " and " + buildMap.get(token)); } buildMap.put(token, partitionId); } ImmutableSortedMap.Builder<Long, Integer> builder = ImmutableSortedMap.naturalOrder(); for (Map.Entry<Long, Integer> e : buildMap.entrySet()) { builder.put(e.getKey(), e.getValue()); } tokens = builder.build(); }
From source file:ru.org.linux.search.SearchController.java
@ModelAttribute("ranges") public static Map<SearchViewer.SearchRange, String> getRanges() { ImmutableMap.Builder<SearchViewer.SearchRange, String> builder = ImmutableSortedMap.naturalOrder(); for (SearchViewer.SearchRange value : SearchViewer.SearchRange.values()) { builder.put(value, value.getTitle()); }/*from w w w . j av a 2s . c o m*/ return builder.build(); }
From source file:org.gradle.api.internal.changedetection.changes.Util.java
public static ImmutableSortedMap<String, CurrentFileCollectionFingerprint> fingerprintTaskFiles( TaskInternal task, SortedSet<? extends TaskFilePropertySpec> fileProperties, FileCollectionFingerprinterRegistry fingerprinterRegistry) { ImmutableSortedMap.Builder<String, CurrentFileCollectionFingerprint> builder = ImmutableSortedMap .naturalOrder();/*from w ww . j ava 2 s . c om*/ for (TaskFilePropertySpec propertySpec : fileProperties) { CurrentFileCollectionFingerprint result; FileCollectionFingerprinter fingerprinter = fingerprinterRegistry .getFingerprinter(propertySpec.getNormalizer()); LOGGER.debug("Fingerprinting property {} for {}", propertySpec, task); result = fingerprinter.fingerprint(propertySpec.getPropertyFiles()); builder.put(propertySpec.getPropertyName(), result); } return builder.build(); }
From source file:com.google.idea.blaze.android.sync.importer.problems.GeneratedResourceClassifier.java
private static ImmutableSortedMap.Builder<ArtifactLocation, Integer> considerAllInteresting( Collection<ArtifactLocation> generatedResourceLocations) { ImmutableSortedMap.Builder<ArtifactLocation, Integer> builder = ImmutableSortedMap.naturalOrder(); for (ArtifactLocation location : generatedResourceLocations) { builder.put(location, -1);//from ww w .j av a 2 s .co m } return builder; }
From source file:com.facebook.presto.block.BlockCursorAssertions.java
public static SortedMap<Integer, Tuple> toTuplesMap(BlockCursor cursor) { ImmutableSortedMap.Builder<Integer, Tuple> tuples = ImmutableSortedMap.naturalOrder(); while (cursor.advanceNextPosition()) { tuples.put(cursor.getPosition(), cursor.getTuple()); }//from w ww.ja va2 s . com return tuples.build(); }
From source file:org.kiji.schema.impl.hbase.HBaseMaterializedKijiResult.java
/** * Create a {@code KijiResult} backed by an HBase {@link Result}. * * @param entityId The entity ID of the row to which the {@code Result} belongs. * @param dataRequest The data request which defines the columns in this {@code KijiResult}. * @param result The backing HBase result. * @param layout The Kiji table layout of the table. * @param columnTranslator The Kiji column name translator of the table. * @param decoderProvider The Kiji cell decoder provider of the table. * @param <T> The type of {@code KijiCell} values in the view. * @return A {@code KijiResult} backed by an HBase {@code Result}. */// w ww. j av a2 s . c o m public static <T> HBaseMaterializedKijiResult<T> create(final EntityId entityId, final KijiDataRequest dataRequest, final Result result, final KijiTableLayout layout, final HBaseColumnNameTranslator columnTranslator, final CellDecoderProvider decoderProvider) { final ImmutableSortedMap.Builder<KijiColumnName, List<KeyValue>> columnResults = ImmutableSortedMap .naturalOrder(); for (Column columnRequest : dataRequest.getColumns()) { // TODO: determine via benchmarks whether it would be faster to make a copy of the // columnResult list so that the underlying Result may be garbage collected. List<KeyValue> columnResult = getColumnKeyValues(columnRequest, columnTranslator, result); columnResults.put(columnRequest.getColumnName(), columnResult); } return new HBaseMaterializedKijiResult<T>(entityId, dataRequest, layout, columnTranslator, decoderProvider, columnResults.build()); }
From source file:com.moz.fiji.schema.impl.hbase.HBaseMaterializedFijiResult.java
/** * Create a {@code FijiResult} backed by an HBase {@link Result}. * * @param entityId The entity ID of the row to which the {@code Result} belongs. * @param dataRequest The data request which defines the columns in this {@code FijiResult}. * @param result The backing HBase result. * @param layout The Fiji table layout of the table. * @param columnTranslator The Fiji column name translator of the table. * @param decoderProvider The Fiji cell decoder provider of the table. * @param <T> The type of {@code FijiCell} values in the view. * @return A {@code FijiResult} backed by an HBase {@code Result}. *///from w w w . j av a 2 s . c o m public static <T> HBaseMaterializedFijiResult<T> create(final EntityId entityId, final FijiDataRequest dataRequest, final Result result, final FijiTableLayout layout, final HBaseColumnNameTranslator columnTranslator, final CellDecoderProvider decoderProvider) { final ImmutableSortedMap.Builder<FijiColumnName, List<KeyValue>> columnResults = ImmutableSortedMap .naturalOrder(); for (Column columnRequest : dataRequest.getColumns()) { // TODO: determine via benchmarks whether it would be faster to make a copy of the // columnResult list so that the underlying Result may be garbage collected. List<KeyValue> columnResult = getColumnKeyValues(columnRequest, columnTranslator, result); columnResults.put(columnRequest.getColumnName(), columnResult); } return new HBaseMaterializedFijiResult<T>(entityId, dataRequest, layout, columnTranslator, decoderProvider, columnResults.build()); }
From source file:com.b2international.index.mapping.DocumentMapping.java
DocumentMapping(DocumentMapping parent, Class<?> type) { this.parent = parent; this.type = type; final String typeAsString = getType(type); this.typeAsString = parent == null ? typeAsString : parent.typeAsString() + DELIMITER + typeAsString; this.fieldMap = FluentIterable.from(Reflections.getFields(type)).filter(new Predicate<Field>() { @Override//from w w w . j a v a 2 s.c o m public boolean apply(Field field) { return !Modifier.isStatic(field.getModifiers()); } }).uniqueIndex(GET_NAME); final Builder<String, Text> textFields = ImmutableSortedMap.naturalOrder(); final Builder<String, Keyword> keywordFields = ImmutableSortedMap.naturalOrder(); for (Field field : getFields()) { for (Text analyzer : field.getAnnotationsByType(Text.class)) { if (Strings.isNullOrEmpty(analyzer.alias())) { textFields.put(field.getName(), analyzer); } else { textFields.put(DELIMITER_JOINER.join(field.getName(), analyzer.alias()), analyzer); } } for (Keyword analyzer : field.getAnnotationsByType(Keyword.class)) { if (Strings.isNullOrEmpty(analyzer.alias())) { keywordFields.put(field.getName(), analyzer); } else { keywordFields.put(DELIMITER_JOINER.join(field.getName(), analyzer.alias()), analyzer); } } } this.textFields = new TreeMap<>(textFields.build()); this.keywordFields = new TreeMap<>(keywordFields.build()); // @RevisionHash should be directly present, not inherited final RevisionHash revisionHash = type.getDeclaredAnnotation(RevisionHash.class); if (revisionHash != null) { this.hashedFields = ImmutableSortedSet.copyOf(revisionHash.value()); } else { this.hashedFields = ImmutableSortedSet.of(); } this.nestedTypes = FluentIterable.from(getFields()).transform(new Function<Field, Class<?>>() { @Override public Class<?> apply(Field field) { if (Reflections.isMapType(field)) { return Map.class; } else { return Reflections.getType(field); } } }).filter(new Predicate<Class<?>>() { @Override public boolean apply(Class<?> fieldType) { return isNestedDoc(fieldType); } }).toMap(new Function<Class<?>, DocumentMapping>() { @Override public DocumentMapping apply(Class<?> input) { return new DocumentMapping( DocumentMapping.this.parent == null ? DocumentMapping.this : DocumentMapping.this.parent, input); } }); this.scripts = Maps.uniqueIndex(getScripts(type), Script::name); }