com.google.common.collect.Multimap#asMap ( )源码实例Demo

下面列出了com.google.common.collect.Multimap#asMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: datawave   文件: BooksDataManager.java
/**
 * Loads test data as grouping data from a multimap.
 * 
 * @param data
 *            list of multimap entries of field name to values
 */
public void loadTestData(final List<Map.Entry<Multimap<String,String>,UID>> data) {
    try {
        GroupingAccumuloWriter writer = new GroupingAccumuloWriter(this.datatype, this.accumuloConn, this.cfgData.getDateField(), this.fieldIndex,
                        this.cfgData);
        writer.addData(data);
        Set<RawData> testData = new HashSet<>();
        for (Map.Entry<Multimap<String,String>,UID> entry : data) {
            Multimap<String,String> mm = entry.getKey();
            Map<String,Collection<String>> val = mm.asMap();
            RawData rawEntry = new BooksRawData(this.datatype, this.getHeaders(), this.metadata, val);
            testData.add(rawEntry);
        }
        this.rawData.put(this.datatype, testData);
    } catch (MutationsRejectedException | TableNotFoundException me) {
        throw new AssertionError(me);
    }
}
 
源代码2 项目: Baragon   文件: ServiceContext.java
@JsonCreator
public ServiceContext(@JsonProperty("service") BaragonService service,
                      @JsonProperty("upstreams") Collection<UpstreamInfo> upstreams,
                      @JsonProperty("timestamp") Long timestamp,
                      @JsonProperty("present") boolean present) {
  this.service = service;
  this.timestamp = timestamp;
  this.upstreams = MoreObjects.firstNonNull(upstreams, Collections.<UpstreamInfo>emptyList());
  this.present = present;
  this.rootPath = service.getServiceBasePath().equals("/");

  if (!this.upstreams.isEmpty()) {
    final Multimap<String, UpstreamInfo> upstreamGroupsMultimap = ArrayListMultimap.create();
    for (UpstreamInfo upstream : this.upstreams) {
      upstreamGroupsMultimap.put(upstream.getGroup(), upstream);
    }
    this.upstreamGroups = upstreamGroupsMultimap.asMap();
  } else {
    this.upstreamGroups = Collections.emptyMap();
  }
}
 
源代码3 项目: xtext-core   文件: AssignmentQuantityAllocator.java
@Override
public Map<EStructuralFeature, Collection<ISyntaxConstraint>> groupByFeature() {
	Multimap<EStructuralFeature, ISyntaxConstraint> map = HashMultimap.create();
	for (ISyntaxConstraint e : assignmentQuants.keySet())
		map.put(e.getAssignmentFeature(delegate.eClass()), e);
	return map.asMap();
}
 
源代码4 项目: flashback   文件: MatchHeaders.java
private static Map<String,String> multimapToCommaSeparatedMap(Multimap<String, String> multimap) {
  Map<String, Collection<String>> mapOfCollections = multimap.asMap();
  HashMap<String, String> map = new HashMap<>();
  for (Map.Entry<String, Collection<String>> entry : mapOfCollections.entrySet()) {
    map.put(entry.getKey(), String.join(",", entry.getValue()));
  }
  return map;
}
 
源代码5 项目: brooklyn-server   文件: TypePlanTransformers.java
/** returns a list of {@link BrooklynTypePlanTransformer} instances for this {@link ManagementContext}
 * which may be able to handle the given plan; the list is sorted with highest-score transformer first */
@Beta
public static List<BrooklynTypePlanTransformer> forType(ManagementContext mgmt, RegisteredType type, RegisteredTypeLoadingContext constraint) {
    Multimap<Double,BrooklynTypePlanTransformer> byScoreMulti = ArrayListMultimap.create(); 
    Collection<BrooklynTypePlanTransformer> transformers = all(mgmt);
    for (BrooklynTypePlanTransformer transformer : transformers) {
        double score = transformer.scoreForType(type, constraint);
        if (score>0) byScoreMulti.put(score, transformer);
    }
    Map<Double, Collection<BrooklynTypePlanTransformer>> tree = new TreeMap<Double, Collection<BrooklynTypePlanTransformer>>(byScoreMulti.asMap());
    List<Collection<BrooklynTypePlanTransformer>> highestFirst = new ArrayList<Collection<BrooklynTypePlanTransformer>>(tree.values());
    Collections.reverse(highestFirst);
    return ImmutableList.copyOf(Iterables.concat(highestFirst));
}
 
源代码6 项目: codenjoy   文件: AbstractPlayerGamesTest.java
public Map<Integer, Collection<String>> getRooms() {
    Multimap<Integer, String> result = TreeMultimap.create();

    for (PlayerGame playerGame : playerGames) {
        int index = fields.indexOf(playerGame.getField());
        String name = playerGame.getPlayer().getId();

        result.get(index).add(name);
    }
    return result.asMap();
}
 
源代码7 项目: codenjoy   文件: AbstractPlayerGamesTest.java
public Map<String, Collection<List<String>>> getRoomNames() {
    Multimap<String, List<String>> result = HashMultimap.create();

    playerGames.rooms().forEach(
            (key, value) -> result.get(key).add(players(value)));

    return result.asMap();
}
 
源代码8 项目: onos   文件: DistributedLabelResourceStore.java
@Override
public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
    Map<DeviceId, Collection<LabelResource>> maps = release.asMap();
    Set<DeviceId> deviceIdSet = maps.keySet();
    LabelResourceRequest request = null;
    for (Iterator<DeviceId> it = deviceIdSet.iterator(); it.hasNext();) {
        DeviceId deviceId = it.next();
        Device device = deviceService.getDevice(deviceId);
        if (device == null) {
            continue;
        }
        ImmutableSet<LabelResource> collection = ImmutableSet.copyOf(maps
                .get(deviceId));
        request = new LabelResourceRequest(deviceId,
                                           LabelResourceRequest.Type.RELEASE,
                                           0, collection);
        NodeId master = mastershipService.getMasterFor(deviceId);

        if (master == null) {
            log.warn("Failed to releaseToDevicePool: No master for {}", deviceId);
            return false;
        }

        if (master.equals(clusterService.getLocalNode().id())) {
            return internalRelease(request);
        }

        log.trace("Forwarding request to {}, which is the primary (master) for device {}",
                  master, deviceId);

        return complete(clusterCommunicator
                .sendAndReceive(request,
                                LabelResourceMessageSubjects.LABEL_POOL_RELEASE,
                                SERIALIZER::encode, SERIALIZER::decode,
                                master));
    }
    return false;
}
 
源代码9 项目: hurraa   文件: CejugErrorMap.java
public CejugErrorMap(List<Message> messages) {
	Multimap<String, String> out = ArrayListMultimap.create();
	for (Message message : messages) {
		out.put(message.getCategory(), message.getMessage());
	}
	this.delegate = out.asMap();
	this.messages = messages;
	
}
 
源代码10 项目: selenium   文件: NodeOptions.java
private Map<WebDriverInfo, Collection<SessionFactory>> discoverDrivers(
  int maxSessions,
  Function<WebDriverInfo, Collection<SessionFactory>> factoryFactory) {

  if (!config.getBool("node", "detect-drivers").orElse(false)) {
    return ImmutableMap.of();
  }

  // We don't expect duplicates, but they're fine
  List<WebDriverInfo> infos =
    StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false)
      .filter(WebDriverInfo::isAvailable)
      .sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase()))
      .collect(Collectors.toList());

  // Same
  List<DriverService.Builder<?, ?>> builders = new ArrayList<>();
  ServiceLoader.load(DriverService.Builder.class).forEach(builders::add);

  Multimap<WebDriverInfo, SessionFactory> toReturn = HashMultimap.create();
  infos.forEach(info -> {
    Capabilities caps = info.getCanonicalCapabilities();
    builders.stream()
      .filter(builder -> builder.score(caps) > 0)
      .forEach(builder -> {
        for (int i = 0; i < Math.min(info.getMaximumSimultaneousSessions(), maxSessions); i++) {
          toReturn.putAll(info, factoryFactory.apply(info));
        }
      });
  });

  return toReturn.asMap();
}
 
源代码11 项目: ribbon   文件: CaseInsensitiveMultiMap.java
Map<String, Collection<String>> asMap() {
    Multimap<String, String> result = ArrayListMultimap.create();
    Collection<Entry<String, String>> all = map.values();
    for (Entry<String, String> entry: all) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result.asMap();
}
 
源代码12 项目: hbase-indexer   文件: Indexer.java
/**
 * groups a list of ids by shard
 * (consider moving this to a BaseSharder class)
 */
private Map<Integer, Collection<String>> shardByValue(List<String> idsToDelete) {
    Multimap<Integer, String> map = Multimaps.index(idsToDelete, new Function<String, Integer>() {
        @Override
        public Integer apply(@Nullable String id) {
            try {
                return sharder.getShard(id);
            } catch (SharderException e) {
                throw new RuntimeException("error calculating hash", e);
            }
        }
    });
    return map.asMap();
}
 
源代码13 项目: incubator-pinot   文件: ThirdEyeUtils.java
public static String convertMultiMapToJson(Multimap<String, String> multimap)
    throws JsonProcessingException {
  Map<String, Collection<String>> map = multimap.asMap();
  return OBJECT_MAPPER.writeValueAsString(map);
}
 
源代码14 项目: ignite   文件: HadoopHashMapSelfTest.java
private void check(HadoopHashMultimap m, Multimap<Integer, Integer> mm, HadoopTaskContext taskCtx) throws Exception {
    final HadoopTaskInput in = m.input(taskCtx);

    Map<Integer, Collection<Integer>> mmm = mm.asMap();

    int keys = 0;

    while (in.next()) {
        keys++;

        IntWritable k = (IntWritable)in.key();

        assertNotNull(k);

        ArrayList<Integer> vs = new ArrayList<>();

        Iterator<?> it = in.values();

        while (it.hasNext())
            vs.add(((IntWritable) it.next()).get());

        Collection<Integer> exp = mmm.get(k.get());

        assertEquals(sorted(exp), sorted(vs));
    }

    X.println("keys: " + keys + " cap: " + m.capacity());

    assertEquals(mmm.size(), keys);

    assertEquals(m.keys(), keys);

    in.close();
}