List of usage examples for com.google.common.collect ImmutableSortedMap orderedBy
public static <K, V> Builder<K, V> orderedBy(Comparator<K> comparator)
From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainer.java
public static OmniBuildInvocationsContainer from(Map<String, BuildInvocations> buildInvocationsPerProject) { ImmutableSortedMap.Builder<Path, OmniBuildInvocations> buildInvocationsMap = ImmutableSortedMap .orderedBy(Path.Comparator.INSTANCE); for (String projectPath : buildInvocationsPerProject.keySet()) { buildInvocationsMap.put(Path.from(projectPath), DefaultOmniBuildInvocations .from(buildInvocationsPerProject.get(projectPath), Path.from(projectPath))); }//w ww . j av a2s. c o m return new DefaultOmniBuildInvocationsContainer(buildInvocationsMap.build()); }
From source file:com.facebook.buck.rules.keys.ReflectiveAlterKeyLoader.java
@Override public ImmutableCollection<AlterRuleKey> load(Class<? extends BuildRule> key) throws Exception { ImmutableList.Builder<AlterRuleKey> builder = ImmutableList.builder(); for (Class<?> current = key; !Object.class.equals(current); current = current.getSuperclass()) { ImmutableSortedMap.Builder<ValueExtractor, AlterRuleKey> sortedExtractors = ImmutableSortedMap .orderedBy(COMPARATOR);//from w w w .ja v a 2s.c o m for (final Field field : current.getDeclaredFields()) { field.setAccessible(true); final AddToRuleKey annotation = field.getAnnotation(AddToRuleKey.class); if (annotation != null) { ValueExtractor valueExtractor = new FieldValueExtractor(field); sortedExtractors.put(valueExtractor, createAlterRuleKey(valueExtractor, annotation)); } } builder.addAll(sortedExtractors.build().values()); } return builder.build(); }
From source file:me.yanaga.guava.stream.MoreCollectors.java
public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap( Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper, Comparator<K> comparator) { return toImmutableMap(() -> ImmutableSortedMap.orderedBy(comparator), keyMapper, valueMapper, CONCURRENT); }
From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainer.java
public static OmniBuildInvocationsContainer from(OmniGradleProject gradleProject) { ImmutableSortedMap.Builder<Path, OmniBuildInvocations> result = ImmutableSortedMap .orderedBy(Path.Comparator.INSTANCE); collectBuildInvocations(gradleProject, result); return new DefaultOmniBuildInvocationsContainer(result.build()); }
From source file:org.apache.phoenix.schema.PColumnFamilyImpl.java
public PColumnFamilyImpl(PName name, List<PColumn> columns) { Preconditions.checkNotNull(name);/*from ww w . j a v a2 s . c o m*/ // Include guidePosts also in estimating the size long estimatedSize = SizedUtil.OBJECT_SIZE + SizedUtil.POINTER_SIZE * 5 + SizedUtil.INT_SIZE + name.getEstimatedSize() + SizedUtil.sizeOfMap(columns.size()) * 2 + SizedUtil.sizeOfArrayList(columns.size()); this.name = name; this.columns = ImmutableList.copyOf(columns); ImmutableMap.Builder<String, PColumn> columnByStringBuilder = ImmutableMap.builder(); ImmutableSortedMap.Builder<byte[], PColumn> columnByBytesBuilder = ImmutableSortedMap .orderedBy(Bytes.BYTES_COMPARATOR); for (PColumn column : columns) { estimatedSize += column.getEstimatedSize(); columnByBytesBuilder.put(column.getName().getBytes(), column); columnByStringBuilder.put(column.getName().getString(), column); } this.columnByBytes = columnByBytesBuilder.build(); this.columnByString = columnByStringBuilder.build(); this.estimatedSize = (int) estimatedSize; }
From source file:com.palantir.atlasdb.keyvalue.rocksdb.impl.RangeIterator.java
@Override protected RowResult<T> computeNext() { while (it.isValid()) { Pair<Cell, Long> cellAndTs = RocksDbKeyValueServices.parseCellAndTs(it.key()); Cell cell = cellAndTs.lhSide;/*www . j a v a 2 s . c o m*/ if (!RocksDbKeyValueServices.isInRange(cell.getRowName(), request.getEndExclusive())) { break; } byte[] row = cell.getRowName(); ImmutableSortedMap.Builder<byte[], T> builder = ImmutableSortedMap .orderedBy(UnsignedBytes.lexicographicalComparator()); do { T value = processCell(cellAndTs); if (value != null && request.containsColumn(cell.getColumnName())) { builder.put(cell.getColumnName(), value); } if (!it.isValid()) { break; } cellAndTs = RocksDbKeyValueServices.parseCellAndTs(it.key()); cell = cellAndTs.lhSide; } while (Arrays.equals(row, cell.getRowName())); SortedMap<byte[], T> columns = builder.build(); if (!columns.isEmpty()) { return RowResult.create(row, columns); } } return endOfData(); }
From source file:com.palantir.atlasdb.jackson.TableRowResultDeserializer.java
@Override public TableRowResult deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode node = jp.readValueAsTree(); String tableName = node.get("table").textValue(); Collection<RowResult<byte[]>> rowResults = Lists.newArrayList(); TableMetadata metadata = metadataCache.getMetadata(tableName); for (JsonNode rowResult : node.get("data")) { byte[] row = AtlasDeserializers.deserializeRow(metadata.getRowMetadata(), rowResult.get("row")); ImmutableSortedMap.Builder<byte[], byte[]> cols = ImmutableSortedMap .orderedBy(UnsignedBytes.lexicographicalComparator()); if (metadata.getColumns().hasDynamicColumns()) { for (JsonNode colVal : rowResult.get("cols")) { byte[] col = AtlasDeserializers.deserializeCol(metadata.getColumns(), colVal.get("col")); byte[] val = AtlasDeserializers .deserializeVal(metadata.getColumns().getDynamicColumn().getValue(), colVal.get("val")); cols.put(col, val); }//from w ww . j av a2 s.co m } else { for (NamedColumnDescription namedCol : metadata.getColumns().getNamedColumns()) { JsonNode valNode = rowResult.get(namedCol.getLongName()); if (valNode != null) { byte[] col = namedCol.getShortName().getBytes(Charsets.UTF_8); byte[] val = AtlasDeserializers.deserializeVal(namedCol.getValue(), valNode); cols.put(col, val); } } } rowResults.add(RowResult.create(row, cols.build())); } return new TableRowResult(tableName, rowResults); }
From source file:me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData.java
private static <K, V> SortedMap<ContextSet, Map<K, V>> getRelevantEntries(ContextSet set, Map<ContextSet, Map<K, V>> map) { ImmutableSortedMap.Builder<ContextSet, Map<K, V>> perms = ImmutableSortedMap.orderedBy(CONTEXT_COMPARATOR); loop: for (Map.Entry<ContextSet, Map<K, V>> e : map.entrySet()) { for (Map.Entry<String, String> c : e.getKey().toSet()) { if (!set.has(c.getKey(), c.getValue())) { continue loop; }//from w w w . j a v a 2 s . c o m } perms.put(e.getKey().makeImmutable(), ImmutableMap.copyOf(e.getValue())); } return perms.build(); }
From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainerBuilder.java
private static ImmutableSortedMap<Path, OmniBuildInvocations> buildBuildInvocationsMapping( GradleProject project, Multimap<Path, OmniProjectTask> projectTasks, Multimap<Path, OmniTaskSelector> taskSelectors) { Preconditions.checkState(taskSelectors.keySet().containsAll(projectTasks.keySet()), "Task selectors are always configured for all projects"); // create mappings for all projects which contain tasks selectors (which covers at least those projects that contain project tasks) ImmutableSortedMap.Builder<Path, OmniBuildInvocations> mapping = ImmutableSortedMap .orderedBy(Path.Comparator.INSTANCE); for (Path projectPath : taskSelectors.keySet()) { ImmutableList<OmniProjectTask> projectTasksOfProject = ImmutableSortedSet .orderedBy(TaskComparator.INSTANCE).addAll(projectTasks.get(projectPath)).build().asList(); ImmutableList<OmniTaskSelector> taskSelectorsOfProject = ImmutableSortedSet .orderedBy(TaskSelectorComparator.INSTANCE).addAll(taskSelectors.get(projectPath)).build() .asList();/*w ww .j a v a 2 s.co m*/ mapping.put(projectPath, DefaultOmniBuildInvocations.from(projectTasksOfProject, taskSelectorsOfProject)); } // create additional mappings for all those projects which do not contain any task selectors // this is the case if a project does not contain any tasks nor does any of its child projects // these additional mappings ensure the caller never gets back null for any project in the hierarchy Set<Path> projectPaths = Sets.newLinkedHashSet(); collectProjectPathsRecursively(project, projectPaths); projectPaths.removeAll(taskSelectors.keySet()); for (Path projectPath : projectPaths) { mapping.put(projectPath, DefaultOmniBuildInvocations.from(ImmutableList.<OmniProjectTask>of(), ImmutableList.<OmniTaskSelector>of())); } return mapping.build(); }
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 *//*from w w w . ja v a 2 s.c o m*/ 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()); }