Example usage for com.google.common.collect Multimap put

List of usage examples for com.google.common.collect Multimap put

Introduction

In this page you can find the example usage for com.google.common.collect Multimap put.

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:org.sonar.plugins.pitest.SourceFileReport.java

public String toJSON() {
    if (mutants.isEmpty()) {
        return null;
    }/*from w  w  w.ja va 2s.co m*/

    Multimap<Integer, String> mutantsByLine = ArrayListMultimap.create();

    for (Mutant mutant : mutants) {
        mutantsByLine.put(mutant.lineNumber, mutant.toString());
    }

    StringBuilder builder = new StringBuilder();
    builder.append("{");
    boolean first = true;
    for (int line : mutantsByLine.keySet()) {
        if (!first) {
            builder.append(",");
        }
        first = false;
        builder.append("\"");
        builder.append(line);
        builder.append("\":[");
        builder.append(Joiner.on(",").join(mutantsByLine.get(line)));
        builder.append("]");
    }
    builder.append("}");

    return builder.toString();
}

From source file:de.anycook.db.mysql.DBRecommend.java

public Map<String, Collection<String>> getRecipesByTags(int userId) throws SQLException {
    CallableStatement call = connection.prepareCall("{call recipes_from_schmeckttags(?)}");
    call.setInt(1, userId);//from  w  w  w. j  a  v a 2 s .co m

    ResultSet data = call.executeQuery();
    Multimap<String, String> recipes = HashMultimap.create();

    while (data.next()) {
        String recipe = data.getString("gerichte_name");
        String tag = data.getString("tags_name");
        recipes.put(recipe, tag);
    }
    return recipes.asMap();
}

From source file:io.soliton.shapeshifter.ProtoDescriptorGraph.java

@Override
public String toString() {
    Multimap<String, String> namedGraph = HashMultimap.create();
    for (Map.Entry<Descriptor, Descriptor> entry : graph.entries()) {
        namedGraph.put(entry.getKey().getName(), entry.getValue().getName());
    }/*from www.j a  v  a 2 s.  com*/
    return namedGraph.toString();
}

From source file:org.sonar.server.permission.ws.TemplateUsersAction.java

private WsPermissions.UsersWsResponse buildResponse(List<UserDto> users,
        List<PermissionTemplateUserDto> permissionTemplateUsers, Paging paging) {
    Multimap<Long, String> permissionsByUserId = TreeMultimap.create();
    permissionTemplateUsers.forEach(userPermission -> permissionsByUserId.put(userPermission.getUserId(),
            userPermission.getPermission()));

    UsersWsResponse.Builder responseBuilder = UsersWsResponse.newBuilder();
    users.forEach(user -> {//from  w w  w . ja v a2 s  . co m
        WsPermissions.User.Builder userResponse = responseBuilder.addUsersBuilder().setLogin(user.getLogin())
                .addAllPermissions(permissionsByUserId.get(user.getId()));
        if (user.getEmail() != null) {
            userResponse.setEmail(user.getEmail());
        }
        if (user.getName() != null) {
            userResponse.setName(user.getName());
        }
    });
    responseBuilder.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize())
            .setTotal(paging.total()).build();
    return responseBuilder.build();
}

From source file:com.yahoo.yqlplus.engine.internal.source.IndexedSourceAdapter.java

@Override
protected void indexQuery(List<StreamValue> out, Location location, ContextPlanner planner,
        List<IndexQuery> queries, List<OperatorNode<PhysicalExprOperator>> args) {
    // split IndexQuery by index and then invoke each index exactly once
    OperatorNode<PhysicalExprOperator> sourceAdapter = createSource(location, planner, args);
    Multimap<IndexKey, IndexQuery> split = ArrayListMultimap.create();
    for (IndexQuery query : queries) {
        split.put(query.index, query);
    }//from   w  w  w .  j av a 2s . c o  m
    for (IndexKey idx : split.keySet()) {
        Collection<IndexQuery> todo = split.get(idx);
        selectMap.get(idx).index(out, location, sourceAdapter, planner, Lists.newArrayList(todo));
    }
}

From source file:com.yahoo.yqlplus.engine.internal.source.IndexedSourceAdapter.java

@Override
protected void deleteQuery(List<StreamValue> out, Location location, ContextPlanner planner,
        List<IndexQuery> queries, List<OperatorNode<PhysicalExprOperator>> args) {
    // split IndexQuery by index and then invoke each index exactly once
    OperatorNode<PhysicalExprOperator> sourceAdapter = createSource(location, planner, args);
    Multimap<IndexKey, IndexQuery> split = ArrayListMultimap.create();
    for (IndexQuery query : queries) {
        split.put(query.index, query);
    }/*from   ww  w. ja va  2s .c o m*/
    for (IndexKey idx : split.keySet()) {
        Collection<IndexQuery> todo = split.get(idx);
        deleteMap.get(idx).index(out, location, sourceAdapter, planner, Lists.newArrayList(todo));
    }
}

From source file:com.yahoo.yqlplus.engine.internal.source.IndexedSourceAdapter.java

@Override
protected void updateQuery(List<StreamValue> out, Location location, ContextPlanner planner,
        List<IndexQuery> queries, List<OperatorNode<PhysicalExprOperator>> args,
        OperatorNode<PhysicalExprOperator> record) {
    OperatorNode<PhysicalExprOperator> sourceAdapter = createSource(location, planner, args);
    Multimap<IndexKey, IndexQuery> split = ArrayListMultimap.create();
    for (IndexQuery query : queries) {
        split.put(query.index, query);
    }// w ww  .  ja  va2 s. c  o m
    for (IndexKey idx : split.keySet()) {
        Collection<IndexQuery> todo = split.get(idx);
        updateMap.get(idx).index(out, location, sourceAdapter, planner, Lists.newArrayList(todo), record);
    }
}

From source file:ch.ethz.bsse.quasirecomb.informationholder.ModelSelectionStorage.java

public Multimap<Integer, Double> getMaxBICs() {
    Multimap<Integer, Double> bics = ArrayListMultimap.create();
    for (Map.Entry<Integer, SelectionResult> entry : srMap.entrySet()) {
        SelectionResult srTmp = entry.getValue();
        bics.put(entry.getKey(), srTmp.max);
    }/*  ww  w  . ja v a 2 s  . c o m*/
    return bics;
}

From source file:com.isotrol.impe3.web20.client.counter.CounterComponent.java

/**
 * Generates img likes uri for action./* w  ww. j a va 2 s .  c  o  m*/
 * @param context
 * @return Returns action uri.
 */
String getURI(final RenderContext context) {
    if (idr == null) {
        return null;
    }

    if (idc == null) {
        idc = new UUID(0L, 0L).toString();
    }

    if (cgr == null) {
        cgr = Lists.newArrayList();
    }

    if (ct == null) {
        if (config != null && config.counterType() != null) {
            ct = config.counterType();
        } else {
            ct = moduleConfig.counterType();
        }
    }

    Multimap<String, Object> parameters = ArrayListMultimap.create();
    parameters.put("idr", idr);
    parameters.put("idc", idc);
    parameters.putAll("cgr", cgr);
    parameters.put("ct", ct);
    if (sm != null) {
        parameters.put("sm", sm);
    }
    if (so != null) {
        parameters.put("so", so);
    }

    return context.getActionURI("counter", parameters).toASCIIString();
}

From source file:com.github.jcustenborder.kafka.connect.utils.templates.model.Configuration.java

private Configuration(Collection<Item> configs) {
    this.requiredConfigs = configs.stream().filter(Item::isRequired).collect(Collectors.toList());

    Multimap<String, Item> groupToItem = LinkedListMultimap.create();
    for (Item item : configs) {
        groupToItem.put(item.group, item);
    }//from w  ww  .  j  ava  2 s.c o m
    List<Group> groups = new ArrayList<>();
    for (String group : groupToItem.keySet()) {
        Collection<Item> items = groupToItem.get(group);
        groups.add(new Group(group, new ArrayList<>(items)));
    }
    Collections.sort(groups);

    this.groups = ImmutableList.copyOf(groups);
}