Java Code Examples for com.google.common.collect.Multimaps#transformValues()

The following examples show how to use com.google.common.collect.Multimaps#transformValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private String computeToString() {
  StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
  if (!parameters.isEmpty()) {
    builder.append("; ");
    Multimap<String, String> quotedParameters =
        Multimaps.transformValues(
            parameters,
            new Function<String, String>() {
              @Override
              public String apply(String value) {
                return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value);
              }
            });
    PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
  }
  return builder.toString();
}
 
Example 2
Source File: DomainFlowUtils.java    From nomulus with Apache License 2.0 6 votes vote down vote up
static void validateNoDuplicateContacts(Set<DesignatedContact> contacts)
    throws ParameterValuePolicyErrorException {
  ImmutableMultimap<Type, Key<ContactResource>> contactsByType =
      contacts.stream()
          .collect(
              toImmutableSetMultimap(
                  DesignatedContact::getType, contact -> contact.getContactKey().getOfyKey()));

  // If any contact type has multiple contacts:
  if (contactsByType.asMap().values().stream().anyMatch(v -> v.size() > 1)) {
    // Find the duplicates.
    Map<Type, Collection<Key<ContactResource>>> dupeKeysMap =
        Maps.filterEntries(contactsByType.asMap(), e -> e.getValue().size() > 1);
    ImmutableList<Key<ContactResource>> dupeKeys =
        dupeKeysMap.values().stream().flatMap(Collection::stream).collect(toImmutableList());
    // Load the duplicates in one batch.
    Map<Key<ContactResource>, ContactResource> dupeContacts = ofy().load().keys(dupeKeys);
    ImmutableMultimap.Builder<Type, Key<ContactResource>> typesMap =
        new ImmutableMultimap.Builder<>();
    dupeKeysMap.forEach(typesMap::putAll);
    // Create an error message showing the type and contact IDs of the duplicates.
    throw new DuplicateContactForRoleException(
        Multimaps.transformValues(typesMap.build(), key -> dupeContacts.get(key).getContactId()));
  }
}
 
Example 3
Source File: SchemaReferencesMetaData.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init(){
    aggregateForeignKeyReferences();

    refPaths =
    Multimaps.transformValues(refNodeLists, new Function<List<SchemaReferenceNode>, SchemaReferencePath>() {
        @Override
        public SchemaReferencePath apply(@Nullable List<SchemaReferenceNode> schemaReferenceNodes) {
            SchemaReferencePath path = new SchemaReferencePath(schemaReferenceNodes);
            String fullPath = path.getPath();
            String mappedPath = fieldMapping.get(fullPath);
            if(mappedPath != null) {
                path.setMappedPath(mappedPath);
            }
            return path;
        }
    });
}
 
Example 4
Source File: SetOperationNode.java    From presto with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the input to output symbol mapping for the given source channel.
 * A single input symbol can map to multiple output symbols, thus requiring a Multimap.
 */
public Multimap<Symbol, SymbolReference> outputSymbolMap(int sourceIndex)
{
    return Multimaps.transformValues(FluentIterable.from(getOutputSymbols())
            .toMap(outputToSourceSymbolFunction(sourceIndex))
            .asMultimap()
            .inverse(), Symbol::toSymbolReference);
}
 
Example 5
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String computeToString() {
  StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
  if (!parameters.isEmpty()) {
    builder.append("; ");
    Multimap<String, String> quotedParameters = Multimaps.transformValues(parameters, new Function<String, String>() {
                                                                                        @Override
                                                                                        public String apply(String value) {
                                                                                          return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value);
                                                                                        }
                                                                                      });
    PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
  }
  return builder.toString();
}
 
Example 6
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String computeToString() {
  StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
  if (!parameters.isEmpty()) {
    builder.append("; ");
    Multimap<String, String> quotedParameters = Multimaps.transformValues(parameters, new Function<String, String>() {
                                                                                        @Override
                                                                                        public String apply(String value) {
                                                                                          return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value);
                                                                                        }
                                                                                      });
    PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
  }
  return builder.toString();
}
 
Example 7
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String computeToString() {
  StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
  if (!parameters.isEmpty()) {
    builder.append("; ");
    Multimap<String, String> quotedParameters = Multimaps.transformValues(parameters, new Function<String, String>() {
                                                                                        @Override
                                                                                        public String apply(String value) {
                                                                                          return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value);
                                                                                        }
                                                                                      });
    PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
  }
  return builder.toString();
}
 
Example 8
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String computeToString() {
  StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
  if (!parameters.isEmpty()) {
    builder.append("; ");
    Multimap<String, String> quotedParameters = Multimaps.transformValues(parameters, new Function<String, String>() {
                                                                                        @Override
                                                                                        public String apply(String value) {
                                                                                          return TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value);
                                                                                        }
                                                                                      });
    PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
  }
  return builder.toString();
}
 
Example 9
Source File: MediaType.java    From armeria with Apache License 2.0 5 votes vote down vote up
private String computeToString() {
    StringBuilder builder = new StringBuilder().append(type).append('/').append(subtype);
    if (!parameters.isEmpty()) {
        builder.append("; ");
        Multimap<String, String> quotedParameters =
                Multimaps.transformValues(
                        parameters,
                        value -> TOKEN_MATCHER.matchesAllOf(value) ? value : escapeAndQuote(value));
        PARAMETER_JOINER.appendTo(builder, quotedParameters.entries());
    }
    return builder.toString();
}
 
Example 10
Source File: Maintenance.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private Multimap<String, String> getTasksByHosts(StoreProvider provider, Iterable<String> hosts) {
  if (Iterables.isEmpty(hosts)) {
    return ImmutableMultimap.of();
  }

  ImmutableSet.Builder<IScheduledTask> drainingTasks = ImmutableSet.builder();
  drainingTasks.addAll(provider.getTaskStore()
      .fetchTasks(Query.slaveScoped(hosts).byStatus(Tasks.SLAVE_ASSIGNED_STATES)));
  return Multimaps.transformValues(
      Multimaps.index(drainingTasks.build(), Tasks::scheduledToSlaveHost),
      Tasks::id);
}
 
Example 11
Source File: JobUpdaterIT.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private void assertStateUpdate(
    IJobUpdateKey key,
    JobUpdateStatus expected,
    Multimap<Integer, JobUpdateAction> expectedActions) {

  IJobUpdateDetails details = getDetails(key);
  Iterable<IJobInstanceUpdateEvent> orderedEvents =
      EVENT_ORDER.sortedCopy(details.getInstanceEvents());
  Multimap<Integer, IJobInstanceUpdateEvent> eventsByInstance =
      Multimaps.index(orderedEvents, EVENT_TO_INSTANCE);
  Multimap<Integer, JobUpdateAction> actionsByInstance =
      Multimaps.transformValues(eventsByInstance, JobUpdateControllerImpl.EVENT_TO_ACTION);
  assertEquals(expectedActions, actionsByInstance);
  assertEquals(expected, details.getUpdate().getSummary().getState().getStatus());
}
 
Example 12
Source File: CommandHelper.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Prints target and result map's json representation into printStream.
 *
 * @param targetsAndResults input to query result multi map
 * @param printStream print stream for output
 * @throws IOException in case of IO exception during json writing operation
 */
public static void printJsonOutput(
    Multimap<String, QueryTarget> targetsAndResults, PrintStream printStream) throws IOException {
  Multimap<String, String> targetsAndResultsNames =
      Multimaps.transformValues(
          targetsAndResults, input -> stringify(Objects.requireNonNull(input)));
  ObjectMappers.WRITER.writeValue(printStream, targetsAndResultsNames.asMap());
}
 
Example 13
Source File: RuleContext.java    From bazel with Apache License 2.0 4 votes vote down vote up
/**
 * Returns an immutable map from attribute name to list of configured targets for that attribute.
 */
public ListMultimap<String, ? extends TransitiveInfoCollection> getConfiguredTargetMap() {
  return Multimaps.transformValues(targetMap, ConfiguredTargetAndData::getConfiguredTarget);
}
 
Example 14
Source File: PendingTaskProcessorTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
private Multimap<String, PreemptionVictim> getVictims(IScheduledTask... tasks) {
  return Multimaps.transformValues(
      Multimaps.index(Arrays.asList(tasks), task -> task.getAssignedTask().getSlaveId()),
      task -> PreemptionVictim.fromTask(task.getAssignedTask())
  );
}