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.jclouds.aws.binders.BindMapToIndexedFormParams.java
@SuppressWarnings("unchecked") @Override/* w w w .j av a2s . c o m*/ public <R extends HttpRequest> R bindToRequest(R request, Object input) { if (checkNotNull(input, "input") instanceof Iterable) input = Maps.uniqueIndex((Iterable<String>) input, new Function<String, String>() { int index = 1; @Override public String apply(String input) { return index++ + ""; } }); checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map"); Map<String, String> mapping = (Map<String, String>) input; ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); int amazonOneBasedIndex = 1; // according to docs, counters must start // with 1 for (Entry<String, String> entry : mapping.entrySet()) { // not null by contract builder.put(format(keyPattern, amazonOneBasedIndex), entry.getKey()); builder.put(format(valuePattern, amazonOneBasedIndex), entry.getValue()); amazonOneBasedIndex++; } Multimap<String, String> forms = Multimaps.forMap(builder.build()); return forms.size() == 0 ? request : (R) request.toBuilder().replaceFormParams(forms).build(); }
From source file:eu.clarin.cmdi.curation.facets.postprocessor.utils.FieldValueDescriptor.java
/** * Creates a map value => descriptor/*from w ww. ja v a2 s . co m*/ * * @param descriptor * @return {@link FieldValueDescriptor} map with keys taken from {@link FieldValueDescriptor#getValue() * } */ public static Map<String, FieldValueDescriptor> toMap(Collection<FieldValueDescriptor> descriptor) { return Maps.uniqueIndex(descriptor, new Function<FieldValueDescriptor, String>() { public String apply(FieldValueDescriptor f) { return f.getValue(); } }); }
From source file:org.graylog2.lookup.DtoLoader.java
@Inject DtoLoader(@Assisted Collection<LookupTableDto> lookupTableDtos, MongoLutCacheService cacheService, MongoLutDataAdapterService dataAdapterService) { final ImmutableSet.Builder<String> cacheIds = ImmutableSet.builder(); final ImmutableSet.Builder<String> adapterIds = ImmutableSet.builder(); lookupTableDtos.forEach(dto -> {//from w ww .j av a 2 s .c om cacheIds.add(dto.cacheId()); adapterIds.add(dto.dataAdapterId()); }); this.caches = Maps.uniqueIndex(cacheService.findByIds(cacheIds.build()), CacheDto::id); this.dataAdapters = Maps.uniqueIndex(dataAdapterService.findByIds(adapterIds.build()), DataAdapterDto::id); }
From source file:org.eclipse.sw360.moderation.db.LicenseModerationRequestGenerator.java
@Override public ModerationRequest setAdditionsAndDeletions(ModerationRequest request, License updateLicense, License actualLicense) {/* w w w .j a va 2s .c om*/ updateDocument = updateLicense; actualDocument = actualLicense; documentAdditions = new License(); documentDeletions = new License(); //required fields: documentAdditions.setFullname(updateLicense.getFullname()); documentAdditions.setId(actualLicense.getId()); documentDeletions.setFullname(actualLicense.getFullname()); documentDeletions.setId(actualLicense.getId()); Map<String, Todo> actualTodos = Maps.uniqueIndex(nullToEmptyList(actualLicense.getTodos()), Todo::getId); for (Todo updateTodo : updateLicense.getTodos()) { if (!actualTodos.containsKey(updateTodo.getId())) { if (!documentAdditions.isSetTodos()) { documentAdditions.setTodos(new ArrayList<>()); } documentAdditions.getTodos().add(updateTodo); } else { Todo actualTodo = actualTodos.get(updateTodo.getId()); Set<String> actualWhitelist = actualTodo.whitelist != null ? actualTodo.whitelist : new HashSet<String>(); Set<String> updateWhitelist = updateTodo.whitelist != null ? updateTodo.whitelist : new HashSet<String>(); String departement = request.getRequestingUserDepartment(); if (updateWhitelist.contains(departement) && !actualWhitelist.contains(departement)) { if (!documentAdditions.isSetTodos()) { documentAdditions.setTodos(new ArrayList<>()); } documentAdditions.getTodos().add(updateTodo); } else if (!updateWhitelist.contains(departement) && actualWhitelist.contains(departement)) { if (!documentDeletions.isSetTodos()) { documentDeletions.setTodos(new ArrayList<>()); } documentDeletions.getTodos().add(actualTodo); } } } request.setLicenseAdditions(documentAdditions); request.setLicenseDeletions(documentDeletions); return request; }
From source file:de.metas.ui.web.dashboard.UserDashboard.java
private UserDashboard(final Builder builder) { super();//w ww. j av a 2 s.c o m id = builder.id; adClientId = builder.adClientId; _targetIndicatorItemsById = Maps.uniqueIndex(builder.targetIndicatorItems, UserDashboardItem::getId); _kpiItemsById = Maps.uniqueIndex(builder.kpiItems, UserDashboardItem::getId); websocketEndpoint = WebSocketConfig.TOPIC_Dashboard + "/" + id; }
From source file:org.jclouds.cloudstack.suppliers.ProjectsForCurrentUser.java
@Override public Map<String, Project> get() { User currentUser = currentUserSupplier.get(); ProjectApi projectApi = api.getProjectApi(); return Maps.uniqueIndex( projectApi.listProjects(accountInDomain(currentUser.getAccount(), currentUser.getDomainId())), new Function<Project, String>() { @Override//from w ww . j a v a 2s . co m public String apply(Project arg0) { return arg0.getId(); } }); }
From source file:com.microsoft.azure.management.appservice.implementation.AppServiceDomainImpl.java
AppServiceDomainImpl(String name, DomainInner innerObject, AppServiceManager manager) { super(name, innerObject, manager); inner().withLocation("global"); if (inner().managedHostNames() != null) { this.hostNameMap = Maps.uniqueIndex(inner().managedHostNames(), new Function<HostName, String>() { @Override//from w ww . ja va 2 s. c om public String apply(HostName input) { return input.name(); } }); } }
From source file:org.trancecode.collection.TcMaps.java
public static <K, V> Map<K, V> fromEntries(final Iterable<Entry<K, V>> entries) { final Function<Entry<K, V>, K> keyFunction = MapFunctions.getKey(); final Function<Entry<K, V>, V> valueFunction = MapFunctions.getValue(); final Map<K, Entry<K, V>> intermediate = Maps.uniqueIndex(entries, keyFunction); return Maps.transformValues(intermediate, valueFunction); }
From source file:ext.deployit.community.cli.mustachify.collect.Maps2.java
public static @Nonnull <K1, K2, V> Map<K2, V> transformKeys(@Nonnull Map<K1, V> fromMap, Function<? super K1, K2> function) { // will catch dups Map<K2, K1> newKeys = Maps.uniqueIndex(fromMap.keySet(), function); // replace each old key with its value using a lookup in the input map return transformValues(newKeys, forMap(fromMap)); }
From source file:eu.europa.ec.fisheries.uvms.reporting.message.mapper.ExtMovementMessageMapper.java
public static Map<String, MovementMapResponseType> getMovementMap( List<MovementMapResponseType> movementMapResponseTypes) { return Maps.uniqueIndex(movementMapResponseTypes, new Function<MovementMapResponseType, String>() { public String apply(@NotNull MovementMapResponseType from) { return from.getKey(); }/* ww w . j av a2s. c o m*/ }); }