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:org.jboss.hal.client.configuration.subsystem.datasource.wizard.DriverStep.java
DriverStep(List<JdbcDriver> drivers, Metadata metadata, Resources resources) { super(resources.constants().jdbcDriver()); Map<String, JdbcDriver> driversByName = Maps.uniqueIndex(drivers, JdbcDriver::getName); this.form = new ModelNodeForm.Builder<JdbcDriver>(Ids.DATA_SOURCE_DRIVER_FORM, adjustMetadata(metadata)) .include(DRIVER_NAME, DRIVER_MODULE_NAME, DRIVER_CLASS_NAME).unsorted() .onSave((form, changedValues) -> wizard().getContext().driver = form.getModel()).build(); if (!driversByName.isEmpty()) { form.getFormItem(DRIVER_NAME)/*from w w w . j av a 2 s .c o m*/ .registerSuggestHandler(new StaticAutoComplete(new ArrayList<>(driversByName.keySet()))); form.getFormItem(DRIVER_NAME) .addValidationHandler(value -> driversByName.keySet().contains(value) ? ValidationResult.OK : ValidationResult.invalid("Invalid driver name")); } registerAttachable(form); }
From source file:org.elasticsearch.plugin.readonlyrest.utils.containers.MultiContainer.java
public MultiContainer(Map<String, Supplier<GenericContainer<?>>> containerCreators) { List<NamedContainer> namedContainers = containerCreators.entrySet().stream() .map(entry -> new NamedContainer(entry.getKey(), entry.getValue().get())) .collect(Collectors.toList()); this.containers = Maps.uniqueIndex(namedContainers, NamedContainer::getName); namedContainers.forEach(c -> c.getContainer().start()); }
From source file:org.jclouds.trmk.vcloud_0_8.functions.OrgURIToEndpoint.java
public URI apply(Object from) { Map<URI, ? extends Org> uriToOrg = Maps.uniqueIndex(orgMap.get().values(), new Function<Org, URI>() { @Override/*from w w w.j a v a 2 s. co m*/ public URI apply(Org from) { return from.getHref(); } }); try { Org org = uriToOrg.get(from == null ? defaultOrg.get().getHref() : from); return getUriFromOrg(org); } catch (NullPointerException e) { throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e); } }
From source file:org.jclouds.vcloud.terremark.functions.OrgURIToKeysListEndpoint.java
public URI apply(Object from) { Map<URI, ? extends Org> uriToOrg = Maps.uniqueIndex(orgMap.get().values(), new Function<Org, URI>() { @Override/* w w w . j a v a2 s.c o m*/ public URI apply(Org from) { return from.getHref(); } }); try { return TerremarkOrg.class.cast(uriToOrg.get(from == null ? defaultOrg : from)).getKeysList().getHref(); } catch (NullPointerException e) { throw new ResourceNotFoundException("org " + from + " not found in: " + uriToOrg, e); } }
From source file:org.jclouds.sqs.binders.BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.java
public Map<String, String> idReceiptHandle(Iterable<String> input) { return Maps.uniqueIndex(input, new Function<String, String>() { int index = 1; @Override/*from ww w.j a v a2 s .co m*/ public String apply(String input) { return index++ + ""; } }); }
From source file:org.gradle.model.internal.manage.schema.AbstractModelStructSchema.java
public AbstractModelStructSchema(ModelType<T> type, Iterable<ModelProperty<?>> properties, Iterable<ModelSchemaAspect> aspects) { super(type);//from w w w . jav a2 s. co m ImmutableSortedMap.Builder<String, ModelProperty<?>> builder = ImmutableSortedMap.naturalOrder(); for (ModelProperty<?> property : properties) { builder.put(property.getName(), property); } this.properties = builder.build(); this.aspects = Maps.uniqueIndex(aspects, new Function<ModelSchemaAspect, Class<? extends ModelSchemaAspect>>() { @Override public Class<? extends ModelSchemaAspect> apply(ModelSchemaAspect aspect) { return aspect.getClass(); } }); }
From source file:org.apache.eagle.security.enrich.DataEnrichJob.java
@Override public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap jobDataMap = context.getJobDetail().getJobDataMap(); DataEnrichLCM lcm = (DataEnrichLCM) jobDataMap.getOrDefault("dataEnrichLCM", null); if (lcm == null) throw new IllegalStateException("dataEnrichLCM implementation should be provided"); try {//from w w w.j av a 2s . c o m Collection externalEntities = lcm.loadExternal(); Map<Object, Object> map = Maps.uniqueIndex(externalEntities, entity -> lcm.getCacheKey(entity)); ExternalDataCache.getInstance().setJobResult(lcm.getClass(), map); } catch (Exception ex) { LOG.error("Fail to load sensitivity data", ex); } }
From source file:models.DeploymentDiff.java
/** * Computes the changes from one manifest to another. * * @param oldManifest the old manifest//from ww w. j av a 2 s .co m * @param newManifest the new manifest * @return a list of package changes */ List<PackageChange> getPackageChanges(final Manifest oldManifest, final Manifest newManifest) { final List<PackageVersion> oldPackages = oldManifest.getPackages(); final ImmutableMap<String, PackageVersion> oldMap = Maps.uniqueIndex(oldPackages, (v) -> v.getPkg().getName()); final ImmutableMap<String, PackageVersion> newMap = Maps.uniqueIndex(newManifest.getPackages(), (v) -> v.getPkg().getName()); final MapDifference<String, PackageVersion> mapDifference = Maps.difference(oldMap, newMap); final List<PackageChange> changes = Lists.newArrayList(); mapDifference.entriesOnlyOnLeft().forEach( (k, v) -> changes.add(new PackageChange(k, Optional.of(v.getVersion()), Optional.empty()))); mapDifference.entriesOnlyOnRight().forEach( (k, v) -> changes.add(new PackageChange(k, Optional.empty(), Optional.of(v.getVersion())))); mapDifference.entriesDiffering().forEach((k, v) -> changes.add(new PackageChange(k, Optional.of(v.leftValue().getVersion()), Optional.of(v.rightValue().getVersion())))); mapDifference.entriesInCommon().forEach((k, v) -> changes .add(new PackageChange(k, Optional.of(v.getVersion()), Optional.of(v.getVersion())))); changes.sort(Comparator.comparing(PackageChange::getName)); return changes; }
From source file:tech.beshu.ror.utils.containers.MultiContainer.java
public MultiContainer(Map<String, Supplier<GenericContainer<?>>> containerCreators) { List<NamedContainer> namedContainers = containerCreators.entrySet().stream() .map(entry -> new NamedContainer(entry.getKey(), entry.getValue().get())) .collect(Collectors.toList()); this.containers = Maps.uniqueIndex(namedContainers, NamedContainer::getName); }
From source file:gobblin.data.management.copy.hive.HiveUtils.java
/** * @param client an {@link IMetaStoreClient} for the correct metastore. * @param table the {@link Table} for which we should get partitions. * @param filter an optional filter for partitions as would be used in Hive. Can only filter on String columns. * (e.g. "part = \"part1\"" or "date > \"2015\"". * @return a map of values to {@link Partition} for input {@link Table}. *//*from w w w. j av a 2 s .co m*/ public static Map<List<String>, Partition> getPartitionsMap(IMetaStoreClient client, Table table, Optional<String> filter, Optional<? extends HivePartitionExtendedFilter> hivePartitionExtendedFilterOptional) throws IOException { return Maps.uniqueIndex(getPartitions(client, table, filter, hivePartitionExtendedFilterOptional), new Function<Partition, List<String>>() { @Override public List<String> apply(@Nullable Partition partition) { if (partition == null) { return null; } return partition.getValues(); } }); }