类com.google.common.collect.SetMultimap源码实例Demo

下面列出了怎么用com.google.common.collect.SetMultimap的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: presto   文件: UniformNodeSelector.java
/**
 * The method selects and removes a split from the fromNode and assigns it to the toNode. There is an attempt to
 * redistribute a Non-local split if possible. This case is possible when there are multiple queries running
 * simultaneously. If a Non-local split cannot be found in the maxNode, any split is selected randomly and reassigned.
 */
@VisibleForTesting
public static void redistributeSplit(Multimap<InternalNode, Split> assignment, InternalNode fromNode, InternalNode toNode, SetMultimap<InetAddress, InternalNode> nodesByHost)
{
    Iterator<Split> splitIterator = assignment.get(fromNode).iterator();
    Split splitToBeRedistributed = null;
    while (splitIterator.hasNext()) {
        Split split = splitIterator.next();
        // Try to select non-local split for redistribution
        if (!split.getAddresses().isEmpty() && !isSplitLocal(split.getAddresses(), fromNode.getHostAndPort(), nodesByHost)) {
            splitToBeRedistributed = split;
            break;
        }
    }
    // Select any split if maxNode has no non-local splits in the current batch of assignment
    if (splitToBeRedistributed == null) {
        splitIterator = assignment.get(fromNode).iterator();
        splitToBeRedistributed = splitIterator.next();
    }
    splitIterator.remove();
    assignment.put(toNode, splitToBeRedistributed);
}
 
源代码2 项目: bazel-buildfarm   文件: WorkerQueuesTest.java
@Test
public void gpuConfig_validProvisionsEnqueued() {

  // Arrange
  WorkerQueues queues = WorkerQueueConfigurations.gpu();

  // Act
  Operation operation = Operation.newBuilder().build();
  SetMultimap<String, String> provisions = HashMultimap.create();
  provisions.put("foo", "bar");
  provisions.put("gpu_required", "only key matters");
  provisions.put("another", "provision");
  boolean success = queues.enqueueOperation(operation, provisions);

  // Assert
  assertThat(success).isTrue();
  assertThat(queues.queueSize("GPU")).isEqualTo(1);
}
 
源代码3 项目: bazel   文件: ConditionalEdges.java
/** Builds ConditionalEdges from given graph. */
public ConditionalEdges(Digraph<Target> graph) {
  this.map = new HashMap<>();

  for (Node<Target> node : graph.getNodes()) {
    Rule rule = node.getLabel().getAssociatedRule();
    if (rule == null) {
      // rule is null for source files and package groups. Skip them.
      continue;
    }

    SetMultimap<Label, Label> conditions = getAllConditions(rule, RawAttributeMapper.of(rule));
    if (conditions.isEmpty()) {
      // bail early for most common case of no conditions in the rule.
      continue;
    }

    Label nodeLabel = node.getLabel().getLabel();
    for (Node<Target> succ : node.getSuccessors()) {
      Label successorLabel = succ.getLabel().getLabel();
      if (conditions.containsKey(successorLabel)) {
        insert(nodeLabel, successorLabel, conditions.get(successorLabel));
      }
    }
  }
}
 
private static ListenableFuture<EffectiveModelContext> createSchemaContext(
        final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources)
        throws Exception {
    final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
            "shared-schema-repo-with-deviations-test");

    final Collection<SourceIdentifier> requiredSources = new ArrayList<>();
    for (final String resource : resources) {
        final SettableSchemaProvider<ASTSchemaSource> yangSource = getImmediateYangSourceProviderFromResource(
                resource);
        yangSource.register(sharedSchemaRepository);
        yangSource.setResult();
        requiredSources.add(yangSource.getId());
    }

    final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.builder()
            .setModulesDeviatedByModules(modulesWithSupportedDeviations).build();
    return sharedSchemaRepository.createEffectiveModelContextFactory(config).createEffectiveModelContext(
        requiredSources);
}
 
源代码5 项目: pushfish-android   文件: TaskSelector.java
public TaskSelection getSelection(String path) {
    SetMultimap<String, TaskSelectionResult> tasksByName;
    ProjectInternal project = gradle.getDefaultProject();
    ResolvedTaskPath taskPath = taskPathResolver.resolvePath(path, project);

    if (taskPath.isQualified()) {
        tasksByName = taskNameResolver.select(taskPath.getTaskName(), taskPath.getProject());
    } else {
        tasksByName = taskNameResolver.selectAll(taskPath.getTaskName(), taskPath.getProject());
    }

    Set<TaskSelectionResult> tasks = tasksByName.get(taskPath.getTaskName());
    if (!tasks.isEmpty()) {
        // An exact match
        return new TaskSelection(path, tasks);
    }

    NameMatcher matcher = new NameMatcher();
    String actualName = matcher.find(taskPath.getTaskName(), tasksByName.keySet());
    if (actualName != null) {
        return new TaskSelection(taskPath.getPrefix() + actualName, tasksByName.get(actualName));
    }

    throw new TaskSelectionException(matcher.formatErrorMessage("task", taskPath.getProject()));
}
 
源代码6 项目: xtext-eclipse   文件: BuilderParticipant.java
/**
 * @since 2.12
 */
protected Map<OutputConfiguration, Iterable<IMarker>> buildGeneratorMarkersReverseLookupMap(Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers) {
	SetMultimap<String, IFile> reverseLookupMap = HashMultimap.create();
	for (java.util.Map.Entry<OutputConfiguration, Iterable<IMarker>> entry : generatorMarkers.entrySet()) {
		OutputConfiguration outputConfiguration = entry.getKey();
		if (outputConfiguration.isCleanUpDerivedResources()) {
			for (IMarker marker : entry.getValue()) {
				String source = derivedResourceMarkers.getSource(marker);
				if (source != null) {
					reverseLookupMap.put(source, (IFile) marker.getResource());
				}
			}
		}
	}
	return new DerivedResourcesLookupMap(generatorMarkers, reverseLookupMap);
}
 
源代码7 项目: sqlitemagic   文件: Environment.java
private static void getLocalAndInheritedMethods(PackageElement pkg,
                                                TypeElement type,
                                                SetMultimap<String, ExecutableElement> methods,
                                                ConditionCallback<ExecutableElement> includeMethodCallback) {
  for (TypeMirror superInterface : type.getInterfaces()) {
    final TypeElement superInterfaceElement = asTypeElement(superInterface);
    final String interfaceName = superInterfaceElement.getSimpleName().toString();
    if (interfaceName.startsWith("Parcelable")) continue;

    getLocalAndInheritedMethods(pkg, superInterfaceElement, methods, includeMethodCallback);
  }
  if (type.getSuperclass().getKind() != TypeKind.NONE) {
    // Visit the superclass after superinterfaces so we will always see the implementation of a
    // method after any interfaces that declared it.
    getLocalAndInheritedMethods(pkg, asTypeElement(type.getSuperclass()), methods, includeMethodCallback);
  }
  for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
    if (includeMethodCallback.call(method)
        && visibleFromPackage(method, pkg)) {
      methods.put(method.getSimpleName().toString(), method);
    }
  }
}
 
源代码8 项目: bioasq   文件: ChoiceCavGenerator.java
@Override
public List<CandidateAnswerVariant> generate(JCas jcas) throws AnalysisEngineProcessException {
  List<Token> tokens = TypeUtil.getOrderedTokens(jcas);
  SetMultimap<Token, Token> head2children = CavUtil.getHeadTokenMap(tokens);
  Token orToken;
  try {
    orToken = tokens.stream().filter(t -> OR_LEMMA.equals(t.getLemmaForm())).findAny().get();
  } catch (NoSuchElementException e) {
    return new ArrayList<>();
  }
  // identify head tokens for choices from the question
  Token mainToken = orToken.getHead();
  List<Token> alternativeTokens = head2children.get(mainToken).stream()
          .filter(t -> CONJ_DEP_LABEL.equals(t.getDepLabel())).collect(toList());
  List<CandidateAnswerVariant> cavs = Stream
          .concat(Stream.of(mainToken), alternativeTokens.stream())
          .map(token -> CavUtil.createCandidateAnswerVariant(jcas, token)).collect(toList());
  // find CAVs from evidence passages
  Stream.concat(Stream.of(mainToken), alternativeTokens.stream())
          .map(token -> JCasUtil.selectCovering(ConceptMention.class, token))
          .flatMap(Collection::stream).map(ConceptMention::getConcept)
          .map(concept -> CavUtil.createCandidateAnswerVariant(jcas, concept)).forEach(cavs::add);
  return cavs;
}
 
源代码9 项目: consultant   文件: Consultant.java
private Consultant(ScheduledExecutorService executor, ObjectMapper mapper, URI consulUri,
		ServiceIdentifier identifier, SetMultimap<String, SettingListener> settingListeners,
		Set<ConfigListener> configListeners, ConfigValidator validator, CloseableHttpClient http,
		boolean pullConfig, String healthEndpoint, String kvPrefix, long whenLocatingServicesCacheResultsFor) {

	this.registered = new AtomicBoolean();
	this.settingListeners = Multimaps.synchronizedSetMultimap(settingListeners);
	this.configListeners = Sets.newConcurrentHashSet(configListeners);
	this.serviceInstanceBackend = new ServiceInstanceBackend(identifier.getDatacenter(), consulUri, mapper, http,
			whenLocatingServicesCacheResultsFor);

	this.mapper = mapper;
	this.validator = validator;
	this.executor = executor;
	this.consulUri = consulUri;
	this.id = identifier;
	this.pullConfig = pullConfig;
	this.validated = new Properties();
	this.healthEndpoint = healthEndpoint;
	this.http = http;
	this.kvPrefix = kvPrefix;
}
 
源代码10 项目: batfish   文件: IpsecUtil.java
/**
 * Returns all {@link IpsecPeerConfigId}s whose local IP is equal to any of the IPs behind
 * destinationIp after NAT
 */
@Nonnull
private static Set<IpsecPeerConfigId> getCandidatePeersBehindNat(
    @Nonnull Ip destinationIp,
    @Nonnull SetMultimap<Ip, IpWildcardSetIpSpace> privateIpsByPublicIp,
    @Nonnull Map<Ip, Set<IpsecPeerConfigId>> localIpsAndIpsecPeers) {
  ImmutableSet.Builder<IpsecPeerConfigId> candidateNeighbors = ImmutableSet.builder();
  Set<IpWildcardSetIpSpace> privateIpsBehindDestIp = privateIpsByPublicIp.get(destinationIp);
  if (privateIpsBehindDestIp == null) {
    return candidateNeighbors.build();
  }
  for (IpWildcardSetIpSpace ipWildcardSetIpSpace : privateIpsBehindDestIp) {
    for (Entry<Ip, Set<IpsecPeerConfigId>> entry : localIpsAndIpsecPeers.entrySet()) {
      if (ipWildcardSetIpSpace.containsIp(entry.getKey(), ImmutableMap.of())) {
        candidateNeighbors.addAll(entry.getValue());
      }
    }
  }
  return candidateNeighbors.build();
}
 
源代码11 项目: FreeBuilder   文件: SetMultimapPropertyTest.java
@Test
public void testGet_returnsLiveView() {
  behaviorTester
      .with(new Processor(features))
      .with(dataType)
      .with(testBuilder()
          .addLine("DataType.Builder builder = new DataType.Builder();")
          .addLine("%s<%s, %s> itemsView = builder.%s;",
              SetMultimap.class, key.type(), value.type(), convention.get("items"))
          .addLine("assertThat(itemsView).isEmpty();")
          .addLine("builder.putItems(%s, %s);", key.example(0), value.example(1))
          .addLine("assertThat(itemsView).contains(%s, %s).andNothingElse();",
              key.example(0), value.example(1))
          .addLine("builder.clearItems();")
          .addLine("assertThat(itemsView).isEmpty();")
          .addLine("builder.putItems(%s, %s);", key.example(2), value.example(3))
          .addLine("assertThat(itemsView).contains(%s, %s).andNothingElse();",
              key.example(2), value.example(3))
          .build())
      .runTest();
}
 
源代码12 项目: ProjectAres   文件: DisableDamageModule.java
public static DisableDamageModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    SetMultimap<DamageCause, PlayerRelation> causes = HashMultimap.create();
    for(Element damageCauseElement : doc.getRootElement().getChildren("disabledamage")) {
        for(Element damageEl : damageCauseElement.getChildren("damage")) {
            DamageCause cause = XMLUtils.parseEnum(damageEl, DamageCause.class, "damage type");
            for(PlayerRelation damagerType : PlayerRelation.values()) {
                // Legacy syntax used "other" instead of "neutral"
                String attrName = damagerType.name().toLowerCase();
                Node attr = damagerType == PlayerRelation.NEUTRAL ? Node.fromAttr(damageEl, attrName, "other")
                                                                  : Node.fromAttr(damageEl, attrName);
                if(XMLUtils.parseBoolean(attr, true)) {
                    causes.put(cause, damagerType);

                    // Bukkit 1.7.10 changed TNT from BLOCK_EXPLOSION to ENTITY_EXPLOSION,
                    // so we include them both to keep old maps working.
                    if(cause == DamageCause.BLOCK_EXPLOSION) {
                        causes.put(DamageCause.ENTITY_EXPLOSION, damagerType);
                    }
                }
            }
        }
    }
    return new DisableDamageModule(causes);
}
 
源代码13 项目: ProjectAres   文件: TargetedEventBusImpl.java
@Inject TargetedEventBusImpl(ExceptionHandler exceptionHandler, EventRegistry eventRegistry, TargetedEventHandlerScanner eventHandlerScanner, TypeMap<Object, TargetedEventRouter<?>> routers) {
    this.exceptionHandler = exceptionHandler;
    this.eventRegistry = eventRegistry;
    this.routers = routers;

    // Cache of handler methods per listener type
    this.listenerCache = CacheUtils.newCache(listener -> {
        final SetMultimap<EventKey<? extends Event>, EventHandlerInfo<? extends Event>> handlers = eventHandlerScanner.findEventHandlers(listener);
        for(EventHandlerInfo<? extends Event> info : handlers.values()) {
            if(this.routers.allAssignableFrom(info.event()).isEmpty()) {
                throw new InvalidMemberException(
                    info.method(),
                    "No router registered for targeted event type " + info.event().getName()
                );
            }
        }
        return handlers;
    });
}
 
源代码14 项目: glowroot   文件: ClasspathCache.java
synchronized void updateCache() {
    Multimap<String, Location> newClassNameLocations = HashMultimap.create();
    for (ClassLoader loader : getKnownClassLoaders()) {
        updateCache(loader, newClassNameLocations);
    }
    updateCacheWithClasspathClasses(newClassNameLocations);
    updateCacheWithBootstrapClasses(newClassNameLocations);
    if (!newClassNameLocations.isEmpty()) {
        // multimap that sorts keys and de-dups values while maintains value ordering
        SetMultimap<String, Location> newMap =
                MultimapBuilder.treeKeys().linkedHashSetValues().build();
        newMap.putAll(classNameLocations);
        newMap.putAll(newClassNameLocations);
        classNameLocations = ImmutableMultimap.copyOf(newMap);
    }
}
 
源代码15 项目: cm_ext   文件: ReferenceValidatorImpl.java
@Override
public void beforeNode(Object obj, DescriptorPath path) {
  Preconditions.checkState(!refsStack.containsKey(path));

  SetMultimap<ReferenceType, String> refs = getRelatedPaths(obj, path);
  SetMultimap<ReferenceType, String> newRefs = LinkedHashMultimap.create();

  for (Map.Entry<ReferenceType, Collection<String>> entry : refs.asMap().entrySet()) {
    ReferenceType type = entry.getKey();
    for (String reference : entry.getValue()) {
      if (!allowedRefs.containsEntry(type, reference)) {
        newRefs.put(type, reference);
        allowedRefs.put(type, reference);
      }
    }
  }

  // consolidate into the singleton if it's empty
  newRefs = newRefs.size() == 0 ? ImmutableSetMultimap
      .<ReferenceType, String> of() : newRefs;
  refsStack.put(path, newRefs);

  callReferenceConstraints(obj, path);
}
 
源代码16 项目: brooklyn-server   文件: FunctionFeed.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void preStart() {
    SetMultimap<FunctionPollIdentifier, FunctionPollConfig<?, ?>> polls = getConfig(POLLS);
    for (final FunctionPollIdentifier pollInfo : polls.keySet()) {
        Set<FunctionPollConfig<?,?>> configs = polls.get(pollInfo);
        long minPeriod = Integer.MAX_VALUE;
        Set<AttributePollHandler<?>> handlers = Sets.newLinkedHashSet();

        for (FunctionPollConfig<?,?> config : configs) {
            handlers.add(new AttributePollHandler(config, entity, this));
            if (config.getPeriod() > 0) minPeriod = Math.min(minPeriod, config.getPeriod());
        }
        
        getPoller().scheduleAtFixedRate(
                (Callable)pollInfo.job,
                new DelegatingPollHandler(handlers), 
                minPeriod);
    }
}
 
源代码17 项目: docker-java   文件: DefaultDockerCmdExecFactory.java
@Override
public DefaultWebTarget queryParamsSet(String name, Set<?> values) {
    SetMultimap<String, String> newQueryParams = HashMultimap.create(queryParams);
    newQueryParams.replaceValues(name, values.stream().filter(Objects::nonNull).map(Object::toString).collect(Collectors.toSet()));

    return new DefaultWebTarget(path, newQueryParams);
}
 
源代码18 项目: EclipseCodeFormatter   文件: XBAR.java
public static void bar() {
	new XAAA();
	aaa();
	new XFOO();
	foo();

	SetMultimap<Object, Object> objectObjectSetMultimap = forMap(new HashMap<Object, Object>());
	IMocksControl control = createControl();
	List s = new ArrayList();

}
 
源代码19 项目: gef   文件: SetMultimapExpression.java
@Override
public void clear() {
	final SetMultimap<K, V> setMultimap = get();
	if (setMultimap == null) {
		EMPTY_SETMULTIMAP.clear();
	} else {
		setMultimap.clear();
	}
}
 
源代码20 项目: glowroot   文件: Transaction.java
public SetMultimap<String, String> getAttributes() {
    synchronized (attributesLock) {
        if (attributes == null) {
            return ImmutableSetMultimap.of();
        }
        SetMultimap<String, String> orderedAttributes = TreeMultimap.create();
        orderedAttributes.putAll(attributes);
        return orderedAttributes;
    }
}
 
源代码21 项目: presto   文件: TestRaptorIntegrationSmokeTest.java
@Test
public void testShardingByTemporalDateColumn()
{
    // Make sure we have at least 2 different orderdate.
    assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);

    assertUpdate("CREATE TABLE test_shard_temporal_date " +
                    "WITH (temporal_column = 'orderdate') AS " +
                    "SELECT orderdate, orderkey " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'",
            "SELECT count(*) " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'");

    MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date");

    // Each shard will only contain data of one date.
    SetMultimap<String, LocalDate> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (LocalDate) row.getField(0));
    }

    for (Collection<LocalDate> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }

    // Make sure we have all the rows
    assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date",
            "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
 
源代码22 项目: presto   文件: TestRaptorIntegrationSmokeTest.java
@Test
public void testShardingByTemporalDateColumnBucketed()
{
    // Make sure we have at least 2 different orderdate.
    assertEquals(computeActual("SELECT count(DISTINCT orderdate) >= 2 FROM orders WHERE orderdate < date '1992-02-08'").getOnlyValue(), true);

    assertUpdate("CREATE TABLE test_shard_temporal_date_bucketed " +
                    "WITH (temporal_column = 'orderdate', bucket_count = 10, bucketed_on = ARRAY ['orderkey']) AS " +
                    "SELECT orderdate, orderkey " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'",
            "SELECT count(*) " +
                    "FROM orders " +
                    "WHERE orderdate < date '1992-02-08'");

    MaterializedResult results = computeActual("SELECT orderdate, \"$shard_uuid\" FROM test_shard_temporal_date_bucketed");

    // Each shard will only contain data of one date.
    SetMultimap<String, LocalDate> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (LocalDate) row.getField(0));
    }

    for (Collection<LocalDate> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }

    // Make sure we have all the rows
    assertQuery("SELECT orderdate, orderkey FROM test_shard_temporal_date_bucketed",
            "SELECT orderdate, orderkey FROM orders WHERE orderdate < date '1992-02-08'");
}
 
源代码23 项目: presto   文件: TestRaptorIntegrationSmokeTest.java
@Test
public void testShardingByTemporalTimestampColumnBucketed()
{
    assertUpdate("" +
            "CREATE TABLE test_shard_temporal_timestamp_bucketed(col1 BIGINT, col2 TIMESTAMP) " +
            "WITH (temporal_column = 'col2', bucket_count = 3, bucketed_on = ARRAY ['col1'])");

    int rows = 100;
    StringJoiner joiner = new StringJoiner(", ", "INSERT INTO test_shard_temporal_timestamp_bucketed VALUES ", "");
    for (int i = 0; i < rows; i++) {
        joiner.add(format("(%s, TIMESTAMP '2016-08-08 01:00' + interval '%s' hour)", i, i));
    }

    assertUpdate(joiner.toString(), format("VALUES(%s)", rows));

    MaterializedResult results = computeActual("" +
            "SELECT format_datetime(col2 AT TIME ZONE 'UTC', 'yyyyMMdd'), \"$shard_uuid\" " +
            "FROM test_shard_temporal_timestamp_bucketed");

    assertEquals(results.getRowCount(), rows);

    // Each shard will only contain data of one date.
    SetMultimap<String, String> shardDateMap = HashMultimap.create();
    for (MaterializedRow row : results.getMaterializedRows()) {
        shardDateMap.put((String) row.getField(1), (String) row.getField(0));
    }

    for (Collection<String> dates : shardDateMap.asMap().values()) {
        assertEquals(dates.size(), 1);
    }

    // Ensure one shard can contain different timestamps from the same day
    assertLessThan(shardDateMap.size(), rows);
}
 
/**
 * Convert the response to a Map<DimensionKey, MetricTimeSeries>. DimensionKey is generated based
 * off of schemaDimensions, while the MetricTimeSeries objects are generated based on the rows
 * within the response input. The metrics returned in the MetricTimeSeries instances correspond to
 * the metric names as opposed to the full metric function (eg __COUNT instead of SUM(__COUNT))
 */
public static Map<DimensionKey, MetricTimeSeries> toMap(TimeSeriesResponse response,
    List<String> schemaDimensions) {
  DimensionKeyGenerator dimensionKeyGenerator = new DimensionKeyGenerator(schemaDimensions);

  List<String> metrics = new ArrayList<>(response.getMetrics());
  Set<String> metricSet = new HashSet<>(metrics);
  List<MetricType> types = Collections.nCopies(metrics.size(), MetricType.DOUBLE);
  MetricSchema metricSchema = new MetricSchema(metrics, types);

  SetMultimap<DimensionKey, TimeSeriesRow> dimensionKeyToRows = HashMultimap.create();
  // group the rows by their dimension key
  for (int i = 0; i < response.getNumRows(); i++) {
    TimeSeriesRow row = response.getRow(i);
    DimensionKey dimensionKey =
        dimensionKeyGenerator.get(row.getDimensionNames(), row.getDimensionValues());
    dimensionKeyToRows.put(dimensionKey, row);
  }

  Map<DimensionKey, MetricTimeSeries> result = new HashMap<>();
  for (Entry<DimensionKey, Collection<TimeSeriesRow>> entry : dimensionKeyToRows.asMap()
      .entrySet()) {
    DimensionKey key = entry.getKey();
    MetricTimeSeries metricTimeSeries = new MetricTimeSeries(metricSchema);
    result.put(key, metricTimeSeries);
    for (TimeSeriesRow timeSeriesRow : entry.getValue()) {
      long timestamp = timeSeriesRow.getStart();
      for (TimeSeriesMetric metric : timeSeriesRow.getMetrics()) {
        String metricName = metric.getMetricName();
        // Only add the row metric if it's listed in the response object. The row metric may
        // contain additional info, eg the raw metrics required for calculating derived ones.
        if (metricSet.contains(metricName)) {
          Double value = metric.getValue();
          metricTimeSeries.increment(timestamp, metricName, value);
        }
      }
    }
  }
  return result;
}
 
源代码25 项目: grakn   文件: RelationAtomValidator.java
@Override
public Set<String> validateAsRuleBody(RelationAtom atom, Label ruleLabel, ReasoningContext ctx) {
    Set<String> errors = new HashSet<>();
    SchemaConcept type = atom.getSchemaConcept();
    if (type != null && !type.isRelationType()) {
        errors.add(ErrorMessage.VALIDATION_RULE_INVALID_RELATION_TYPE.getMessage(ruleLabel, type.label()));
        return errors;
    }

    //check role-type compatibility
    SetMultimap<Variable, Type> varTypeMap = atom.getParentQuery().getVarTypeMap();
    for (Map.Entry<Role, Collection<Variable>> e : atom.getRoleVarMap().asMap().entrySet()) {
        Role role = e.getKey();
        if (!Schema.MetaSchema.isMetaLabel(role.label())) {
            //check whether this role can be played in this relation
            if (type != null && type.asRelationType().roles().noneMatch(r -> r.equals(role))) {
                errors.add(ErrorMessage.VALIDATION_RULE_ROLE_CANNOT_BE_PLAYED.getMessage(ruleLabel, role.label(), type.label()));
            }

            //check whether the role player's type allows playing this role
            for (Variable player : e.getValue()) {
                varTypeMap.get(player).stream()
                        .filter(playerType -> playerType.playing().noneMatch(plays -> plays.equals(role)))
                        .forEach(playerType ->
                                errors.add(ErrorMessage.VALIDATION_RULE_TYPE_CANNOT_PLAY_ROLE.getMessage(ruleLabel, playerType.label(), role.label(), type == null ? "" : type.label()))
                        );
            }
        }
    }
    return errors;
}
 
源代码26 项目: bazel-buildfarm   文件: WorkerQueuesTest.java
@Test
public void noConfig_emptyProvisionNotEnqueued() {

  // Arrange
  WorkerQueues queues = new WorkerQueues();

  // Act
  Operation operation = Operation.newBuilder().build();
  SetMultimap<String, String> provisions = HashMultimap.create();
  boolean success = queues.enqueueOperation(operation, provisions);

  // Assert
  assertThat(success).isFalse();
}
 
源代码27 项目: tracing-framework   文件: BaggageImpl.java
/** Returns a set view of the keys in the specified namespace that have 1 or more values assigned
 * 
 * @param namespace the namespace to look up
 * @return all the distinct keys under the given namespace with values assigned */
public Set<ByteString> keys(ByteString namespace) {
    if (namespace != null) {
        SetMultimap<ByteString, ByteString> namespaceData = contents.get(namespace);
        if (namespaceData != null) {
            return namespaceData.keySet();
        }
    }
    return Collections.emptySet();
}
 
源代码28 项目: qconfig   文件: RegisterServiceImpl.java
private CurrentServers initCurrentServer() {
    List<QConfigServer> availableServers = serverStore.getAvailableServers();
    SetMultimap<String, QConfigServer> roomProServerMap = HashMultimap.create();
    SetMultimap<String, QConfigServer> roomTestServerMap = HashMultimap.create();
    for (QConfigServer server : availableServers) {
        if (testEnvIpSet.contains(server.getIp())) {
            roomTestServerMap.put(server.getRoom(), server);
        } else {
            roomProServerMap.put(server.getRoom(), server);
        }
    }
    return new CurrentServers(roomProServerMap, roomTestServerMap);
}
 
源代码29 项目: PeerWasp   文件: InitialState.java
private void addComponentToMoveTargetCandidates() {
	if(action.getFile().getPath().toString().contains("CONFLICT")){
		logger.trace("Workaround: Don't add conflict file {} to move target candidates",
				action.getFile().getPath());
		return;
	}
	if(action.getFile().isFile()){
		SetMultimap<String, FileComponent> createdByContentHash = action.getFileEventManager().getFileTree().getCreatedByContentHash();
		logger.trace("Put file {} with content hash {}", action.getFile().getPath(), action.getFile().getContentHash());
		createdByContentHash.put(action.getFile().getContentHash(), action.getFile());
	} else {
		SetMultimap<String, FolderComposite> createdByStructureHash = action.getFileEventManager().getFileTree().getCreatedByStructureHash();
		createdByStructureHash.put(((FolderComposite)action.getFile()).getStructureHash(), (FolderComposite)action.getFile());
	}
}
 
源代码30 项目: tracing-framework   文件: BaggageImpl.java
/** Construct a baggage instance from the provided BaggageMessage. If the provided message is invalid, null, or
 * empty, this method will return null
 * 
 * @param message A baggagemessage protobuf
 * @return A baggage instance if the provided message is valid and has contents, null otherwise */
static BaggageImpl create(BaggageMessage message) {
    // Check the message is not null and has some namespaces
    if (message == null || message.getNamespaceCount() == 0) {
        return null;
    }

    // Construct the baggage from the received message
    Map<ByteString, SetMultimap<ByteString, ByteString>> data = Maps.newHashMapWithExpectedSize(message.getNamespaceCount());
    for (NamespaceData namespaceData : message.getNamespaceList()) {
        SetMultimap<ByteString, ByteString> namespace = HashMultimap.create(namespaceData.getBagCount(), 1);
        for (BagData bag : namespaceData.getBagList()) {
            namespace.putAll(bag.getKey(), bag.getValueList());
        }
        if (!namespace.isEmpty()) {
            data.put(namespaceData.getKey(), namespace);
        }
    }

    // If there was no data after all, return null
    if (data.isEmpty()) {
        return null;
    }

    BaggageImpl impl = new BaggageImpl(data);
    Handlers.postDeserialize(impl);
    return impl;
}
 
 同包方法