Example usage for com.google.common.collect ListMultimap get

List of usage examples for com.google.common.collect ListMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect ListMultimap get.

Prototype

@Override
List<V> get(@Nullable K key);

Source Link

Document

Because the values for a given key may have duplicates and follow the insertion ordering, this method returns a List , instead of the java.util.Collection specified in the Multimap interface.

Usage

From source file:com.tinspx.util.net.Cookies.java

/**
 * Fixes the Cookie and Cookie2 headers to ensure there is only one mapping
 * for each cookie header. Changes are made directly in the provided map.
 * <p>/*from w w  w  . j av  a  2 s  .co  m*/
 * If there are multiple mappings to either the Cookie or Cookie2 header,
 * they are combined into a single String delimited by the String "; "
 * (semicolon followed by space).
 *
 * @param headers the existing headers to fix
 * @return true if {@code headers} was modified
 */
public static boolean fixCookieHeaders(ListMultimap<String, String> headers) {
    boolean modified = false;
    List<String> h = headers.get(HttpHeaders.COOKIE);
    if (h.size() > 1) {
        headers.replaceValues(HttpHeaders.COOKIE, toSingleCookieList(h));
        modified = true;
    }
    h = headers.get(COOKIE2);
    if (h.size() > 1) {
        headers.replaceValues(COOKIE2, toSingleCookieList(h));
        modified = true;
    }
    return modified;
}

From source file:com.google.gerrit.server.change.WalkSorter.java

private static int emit(RevCommit c, ListMultimap<RevCommit, PatchSetData> byCommit, List<PatchSetData> result,
        RevFlag done) {//  ww w .  j  a v  a 2 s  .  co m
    if (c.has(done)) {
        return 0;
    }
    c.add(done);
    Collection<PatchSetData> psds = byCommit.get(c);
    if (!psds.isEmpty()) {
        result.addAll(psds);
        return 1;
    }
    return 0;
}

From source file:org.sonar.server.setting.ws.SetAction.java

private static void checkFieldType(SetRequest request, PropertyDefinition definition,
        ListMultimap<String, String> valuesByFieldKeys) {
    for (PropertyFieldDefinition fieldDefinition : definition.fields()) {
        for (String value : valuesByFieldKeys.get(fieldDefinition.key())) {
            PropertyDefinition.Result result = fieldDefinition.validate(value);
            checkRequest(result.isValid(),
                    "Error when validating setting with key '%s'. Field '%s' has incorrect value '%s'.",
                    request.getKey(), fieldDefinition.key(), value);
        }/*from w  ww  . ja v a  2 s.co m*/
    }
}

From source file:be.nbb.demetra.mediator.file.FileMediatorConnectionSupplier.java

private static MediatorConnection fromMultimap(final ListMultimap<String, MediatorAlias> data) {
    return new MediatorConnection() {
        @Override//from w  w  w  .java 2 s. com
        public List<String> getDataSourceNames() {
            return new ArrayList<>(data.keySet());
        }

        @Override
        public List<MediatorAlias> get(String dataSourceName) {
            return data.get(dataSourceName);
        }
    };
}

From source file:org.dishevelled.bio.alignment.sam.SamFields.java

/**
 * Parse the Type=B first letter f field value for the specified key into an immutable list of floats
 * of size equal to the specified length.
 *
 * @param key key, must not be null//from w w  w. j  a  v  a2s  . c o  m
 * @param length length, must be greater than zero
 * @param fields fields, must not be null
 * @return the Type=B first letter f field value for the specified key parsed into an immutable list of floats
 *    of size equal to the specified length
 */
static List<Float> parseFloats(final String key, final int length, final ListMultimap<String, String> fields) {
    checkNotNull(key);
    checkNotNull(fields);
    checkArgument(length > 0, "length must be at least one");

    List<String> values = fields.get(key);
    if (values.size() != length) {
        throw new IllegalArgumentException(
                "expected " + length + " Type=B first letter f values, found " + values.size());
    }
    return parseFloats(values);
}

From source file:org.dishevelled.bio.alignment.sam.SamFields.java

/**
 * Parse the Type=B first letter [cCsSiI] field value for the specified key into an immutable list of integers
 * of size equal to the specified length.
 *
 * @param key key, must not be null/*w w w.  ja v a 2s. c  om*/
 * @param length length, must be greater than zero
 * @param fields fields, must not be null
 * @return the Type=B first letter [cCsSiI] field value for the specified key parsed into an immutable list of integers
 *    of size equal to the specified length
 */
static List<Integer> parseIntegers(final String key, final int length,
        final ListMultimap<String, String> fields) {
    checkNotNull(key);
    checkNotNull(fields);
    checkArgument(length > 0, "length must be at least one");

    List<String> values = fields.get(key);
    if (values.size() != length) {
        throw new IllegalArgumentException(
                "expected " + length + " Type=B first letter [cCsSiI] values, found " + values.size());
    }
    return parseIntegers(values);
}

From source file:com.google.gerrit.server.schema.Schema_108.java

private static void updateGroups(ReviewDb db, GroupCollector collector,
        ListMultimap<ObjectId, PatchSet.Id> patchSetsBySha) throws OrmException {
    Map<PatchSet.Id, PatchSet> patchSets = db.patchSets().toMap(db.patchSets().get(patchSetsBySha.values()));
    for (Map.Entry<ObjectId, Collection<String>> e : collector.getGroups().asMap().entrySet()) {
        for (PatchSet.Id psId : patchSetsBySha.get(e.getKey())) {
            PatchSet ps = patchSets.get(psId);
            if (ps != null) {
                ps.setGroups(ImmutableList.copyOf(e.getValue()));
            }//from w  ww.j a  v  a  2  s . c  o  m
        }
    }

    db.patchSets().update(patchSets.values());
}

From source file:fr.obeo.releng.targetplatform.resolved.ResolvedTargetPlatform.java

public static ResolvedTargetPlatform create(TargetPlatform targetPlatform, LocationIndexBuilder indexBuilder)
        throws URISyntaxException {
    Preconditions.checkArgument(targetPlatform != null);
    LinkedList<ResolvedLocation> locations = Lists.newLinkedList();

    ListMultimap<String, Location> locationIndex = indexBuilder.getLocationIndex(targetPlatform);

    for (String locationUri : locationIndex.keySet()) {
        List<UnresolvedIU> ius = Lists.newArrayList();
        Set<String> ids = Sets.newHashSet();
        List<Location> list = locationIndex.get(locationUri);
        for (Location location : list) {
            EList<IU> iuList = location.getIus();
            for (IU iu : iuList) {
                if (!ids.contains(iu.getID())) {
                    ids.add(iu.getID());
                    ius.add(new UnresolvedIU(iu.getID(), Strings.emptyToNull(iu.getVersion())));
                }//from   w w  w . j  av a  2s .c o m
            }
        }
        Location firstLocation = locationIndex.get(locationUri).get(0);
        ResolvedLocation resolvedLocation = new ResolvedLocation(firstLocation.getID(), firstLocation.getUri(),
                ius, getOptionSet(firstLocation.getOptions()));
        locations.addFirst(resolvedLocation);
    }

    final EnumSet<Option> options = getOptionSet(targetPlatform.getOptions());
    return new ResolvedTargetPlatform(targetPlatform.getName(), locations, options,
            Environment.create(targetPlatform));
}

From source file:org.sonar.server.rule.CachingRuleFinder.java

private static Map<RuleDefinitionDto, Rule> buildRulesByRuleDefinitionDto(DbClient dbClient,
        DbSession dbSession) {// ww w. j  a va 2s .  c o  m
    List<RuleDefinitionDto> dtos = dbClient.ruleDao().selectAllDefinitions(dbSession);
    Set<RuleKey> ruleKeys = dtos.stream().map(RuleDefinitionDto::getKey).collect(toSet(dtos.size()));
    ListMultimap<Integer, RuleParamDto> ruleParamsByRuleId = retrieveRuleParameters(dbClient, dbSession,
            ruleKeys);
    Map<RuleDefinitionDto, Rule> rulesByDefinition = new HashMap<>(dtos.size());
    for (RuleDefinitionDto definition : dtos) {
        rulesByDefinition.put(definition, toRule(definition, ruleParamsByRuleId.get(definition.getId())));
    }
    return ImmutableMap.copyOf(rulesByDefinition);
}

From source file:no.ssb.vtl.script.operations.FoldOperation.java

/**
 * Checks that none of the given columns have the identifier role.
 *
 * @throws IllegalArgumentException if one or more columns have the identifier role.
 */// w  w  w.  ja  v  a 2 s  .  c  o m
private static void checkNoIdentifiers(DataStructure structure, ImmutableSet<String> columns) {
    ListMultimap<Role, String> roles = ArrayListMultimap.create();
    for (String elements : columns) {
        roles.put(structure.get(elements).getRole(), elements);
    }
    checkArgument(!roles.containsKey(Role.IDENTIFIER), "cannot fold identifier(s) [%s]",
            roles.get(Role.IDENTIFIER));
}