List of usage examples for com.google.common.collect Maps uniqueIndex
public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction)
From source file:com.twitter.common.stats.NumericStatExporter.java
/** * Starts the stat exporter./*w ww . ja va 2 s .c om*/ * * @param shutdownRegistry Shutdown hook registry to allow the exporter to cleanly halt. */ public void start(ShutdownRegistry shutdownRegistry) { long intervalSecs = exportInterval.as(Time.SECONDS); executor.scheduleAtFixedRate(exporter, intervalSecs, intervalSecs, TimeUnit.SECONDS); shutdownRegistry.addAction(new Command() { @Override public void execute() { stop(); exportSink.execute(Maps.transformValues(Maps.uniqueIndex(Stats.getNumericVariables(), GET_NAME), SAMPLE_AND_READ_STAT)); } }); }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Stores.java
/** * @return the stores identified by related name *//*from w ww .j ava 2 s . co m*/ public ImmutableMap<String, Store> bynames() { return Maps.uniqueIndex(this.all, Store.NAME); }
From source file:com.isotrol.impe3.pms.core.obj.DevicesObject.java
/** * Constructor.//from w w w . j a va2s .c o m * @param entities Device entities. */ private DevicesObject(Iterable<DeviceEntity> entities) { final Iterable<DeviceEntity> ordered = BY_ORDER.sortedCopy(entities); ImmutableHierarchy.Builder<UUID, Device> b = ImmutableHierarchy.builder(); ImmutableHierarchy.Builder<UUID, DeviceObject> bo = ImmutableHierarchy.builder(); for (DeviceEntity entity : ordered) { final UUID id = entity.getId(); final UUID parentId = entity.getParentId(); final DeviceObject device = new DeviceObject(entity); bo.add(id, device, parentId); b.add(id, device.getDevice(), parentId); } this.hierarchy = bo.get(); this.devices = DevicesFactory.of(b.get()); this.byName = ImmutableMap.copyOf(Maps.uniqueIndex(this.hierarchy.values(), DeviceObject.NAME)); }
From source file:org.sonar.ide.wsclient.RemoteSonarIndex.java
public Map<String, Metric> getMetrics() { // TODO Godin: This is not optimal. Would be better to load metrics only once. List<Metric> metrics = getSonar().findAll(MetricQuery.all()); return Maps.uniqueIndex(metrics, new Function<Metric, String>() { public String apply(Metric metric) { return metric.getKey(); }/*from w ww.java2 s .co m*/ }); }
From source file:org.polarsys.reqcycle.traceability.types.ExtensionPointReader.java
public Map<String, TType> readTTypes() { // get all the configuration elements, filter the IConfigurationElement, // transform them in TType and create the associated map Iterable<IConfigurationElement> allConf = filter(Arrays.asList( Platform.getExtensionRegistry().getConfigurationElementsFor(Activator.PLUGIN_ID, EXT_ID_TTYPES)), IConfigurationElement.class); Iterable<TTypeProvider> allProviders = transform(allConf, new Conf2Provider()); Iterable<Iterable<TType>> allTTypes = transform(allProviders, new Provider2TType()); Iterable<TType> allTTypesFlattened = concat(allTTypes); return Maps.uniqueIndex(allTTypesFlattened, new Function<TType, String>() { @Override//from w w w . j a va2 s.c o m public String apply(TType arg0) { return arg0.getId(); } }); }
From source file:org.locationtech.geogig.remotes.pack.DiffRemoteRefsOp.java
@Override protected List<RefDiff> _call() { checkState(remote != null, "no remote provided"); // list of refs/remotes/<remote>/<refname> or refs/heads according to formatAsRemoteRefs Map<String, Ref> remotes; Map<String, Ref> locals; {//w w w . ja v a2 s. c o m // current live remote refs in the remote's local namespace (e.g. refs/heads/<branch>) Iterable<Ref> remoteRefs = getRemoteRefs(); if (formatAsRemoteRefs) { // format refs returned by the remote in its local namespaces to our repository's // remotes namespace remoteRefs = command(MapRef.class)// .setRemote(remote.getInfo())// .convertToRemote()// .addAll(remoteRefs)// .call(); } // current local local copy of the remote refs (e.g. refs/remotes/<remote>/<branch> List<Ref> remoteLocalRefs = Lists.newArrayList(getRemoteLocalRefs()); if (!formatAsRemoteRefs) { // format local repository copies of the remote refs to the remote's local namespace remoteLocalRefs = command(MapRef.class)// .setRemote(remote.getInfo())// .convertToLocal()// .addAll(remoteLocalRefs)// .call(); } if (this.getTags) { Map<String, RevTag> tags = Maps.uniqueIndex(command(TagListOp.class).call(), (t) -> t.getName()); for (Ref rf : remoteRefs) { if (rf.getName().startsWith(Ref.TAGS_PREFIX) && tags.containsKey(rf.localName())) { RevTag tag = tags.get(rf.localName()); remoteLocalRefs.add(new Ref(Ref.TAGS_PREFIX + tag.getName(), tag.getId())); } } } remotes = Maps.uniqueIndex(remoteRefs, (r) -> r.getName()); locals = Maps.uniqueIndex(remoteLocalRefs, (r) -> r.getName()); } final boolean mapped = remote.getInfo().getMapped(); if (mapped) { // for a mapped remote, we are only interested in the branch we are mapped to final String mappedBranch = remote.getInfo().getMappedBranch(); checkNotNull(mappedBranch); final String mappedBranchName = Ref.localName(mappedBranch); remotes = Maps.filterKeys(remotes, (name) -> Ref.localName(name).equals(mappedBranchName)); locals = Maps.filterKeys(locals, (name) -> Ref.localName(name).equals(mappedBranchName)); } MapDifference<String, Ref> difference = Maps.difference(remotes, locals); // refs existing on the remote and not on the local repo Collection<Ref> newRemoteRefs = difference.entriesOnlyOnLeft().values(); // remote refs existing on the local repo and not existing on the remote anymore Collection<Ref> removedRemoteRefs = difference.entriesOnlyOnRight().values(); // refs existing both in local and remote with different objectIds Collection<ValueDifference<Ref>> changes = difference.entriesDiffering().values(); List<RefDiff> diffs = new ArrayList<>(); newRemoteRefs.forEach((r) -> diffs.add(RefDiff.added(r))); removedRemoteRefs.forEach((r) -> diffs.add(RefDiff.removed(r))); // v.leftValue() == new (remote copy), v.rightValue() == old (local copy) changes.forEach((v) -> diffs.add(RefDiff.updated(v.rightValue(), v.leftValue()))); return diffs; }
From source file:com.b2international.snowowl.snomed.core.domain.constraint.SnomedCompositeDefinition.java
@Override public CompositeConceptSetDefinition applyChangesTo(final ConceptModelComponent existingModel) { final CompositeConceptSetDefinition updatedModel = (existingModel instanceof CompositeConceptSetDefinition) ? (CompositeConceptSetDefinition) existingModel : createModel();/* w w w. java2 s. c o m*/ updatedModel.setActive(isActive()); updatedModel.setAuthor(getAuthor()); /* * We will update this list in place; on an existing instance, it will be already populated by some definitions, * on a new instance, it is completely empty. */ final List<ConceptSetDefinition> updatedModelChildren = updatedModel.getChildren(); // Index concept set definition keys by list position final Map<String, Integer> existingDefinitionsByIdx = newHashMap(); for (int i = 0; i < updatedModelChildren.size(); i++) { final ConceptSetDefinition existingDefinition = updatedModelChildren.get(i); existingDefinitionsByIdx.put(existingDefinition.getUuid(), i); } // Index new definitions by key final Map<String, SnomedConceptSetDefinition> updatedDefinitions = newHashMap( Maps.uniqueIndex(children, SnomedConceptSetDefinition::getId)); // Iterate backwards over the list so that removals don't mess up the the list index map for (int j = updatedModelChildren.size() - 1; j >= 0; j--) { final ConceptSetDefinition existingDefinition = updatedModelChildren.get(j); final String uuid = existingDefinition.getUuid(); // Consume entries from "updatedDefinitions" by using remove(Object key) final SnomedConceptSetDefinition updatedDefinition = updatedDefinitions.remove(uuid); // Was there a child with the same key? If not, remove the original from the list, if it is still there, update in place if (updatedDefinition == null) { updatedModelChildren.remove(j); } else { updatedModelChildren.set(j, updatedDefinition.applyChangesTo(existingDefinition)); } } // Remaining entries in "updatedDefinitions" are new; add them to the end of the list for (final SnomedConceptSetDefinition newChild : updatedDefinitions.values()) { updatedModelChildren.add(newChild.applyChangesTo(newChild.createModel())); } updatedModel.setEffectiveTime(EffectiveTimes.toDate(getEffectiveTime())); updatedModel.setUuid(getId()); return updatedModel; }
From source file:de.metas.ui.web.document.filter.ImmutableDocumentFilterDescriptorsProvider.java
private ImmutableDocumentFilterDescriptorsProvider(final List<DocumentFilterDescriptor> descriptors) { super();/*from w w w . ja v a 2 s.co m*/ descriptorsByFilterId = Maps.uniqueIndex(descriptors, descriptor -> descriptor.getFilterId()); }
From source file:org.locationtech.geogig.model.internal.DAG.java
DAG(final TreeId id, final ObjectId originalTreeId, long childCount, STATE state, Set<NodeId> children, Set<TreeId> buckets) { this.id = id; this.originalTreeId = originalTreeId; this.setChildCount(childCount); this.state = state; this.children = new HashMap<>(Maps.uniqueIndex(children, (n) -> n.name())); this.buckets = buckets; }
From source file:org.locationtech.geogig.plumbing.diff.MutableTree.java
public static MutableTree createFromRefs(final ObjectId rootId, final Iterator<NodeRef> treeRefs) { ImmutableMap<String, NodeRef> treesByPath = Maps.uniqueIndex(treeRefs, (n) -> n.path()); return createFromPaths(rootId, treesByPath); }