Java Code Examples for com.google.common.collect.HashMultimap#create()

The following examples show how to use com.google.common.collect.HashMultimap#create() . 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: StateMachineExporterBase.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
protected void init(IDependencyCollector ownerDependencyCollector) {
	
	allSubMachineName = new LinkedList<>();
	stateMachineMap = HashMultimap.create();
	guardExporter = new GuardExporter(Optional.of(ownerDependencyCollector));
	transitionExporter = new TransitionExporter(getActualCompilationUnit(),ownerDependencyCollector, stateMachineRegion.getTransitions(), guardExporter);
	
	createStateList();
	entryExitFunctionExporter = new EntryExitFunctionExporter(getActualCompilationUnit(), ownerDependencyCollector, stateList);
	entryExitFunctionExporter.createEntryFunctionTypeMap();
	entryExitFunctionExporter.createExitFunctionTypeMap();
	
	createMachine();
	createSubMachines();

}
 
Example 2
Source File: PathLabelVisitor.java    From bazel with Apache License 2.0 6 votes vote down vote up
private void visitAspectsIfRequired(Target from, Attribute attribute, final Target to)
    throws InterruptedException, NoSuchThingException {
  // TODO(bazel-team): The getAspects call below is duplicate work for each direct dep entailed
  // by an attribute's value. Additionally, we might end up enqueueing the same exact visitation
  // multiple times: consider the case where the same direct dependency is entailed by aspects
  // of *different* attributes. These visitations get culled later, but we still have to pay the
  // overhead for all that.

  if (!(from instanceof Rule) || !(to instanceof Rule)) {
    return;
  }
  Rule fromRule = (Rule) from;
  Rule toRule = (Rule) to;
  for (Aspect aspect : attribute.getAspects(fromRule)) {
    if (AspectDefinition.satisfies(
        aspect, toRule.getRuleClassObject().getAdvertisedProviders())) {
      Multimap<Attribute, Label> allLabels = HashMultimap.create();
      AspectDefinition.addAllAttributesOfAspect(fromRule, allLabels, aspect, edgeFilter);
      for (Map.Entry<Attribute, Label> e : allLabels.entries()) {
        enqueue(from, e.getKey(), e.getValue());
      }
    }
  }
}
 
Example 3
Source File: TestRaptorIntegrationSmokeTest.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testShardingByTemporalTimestampColumn()
{
    assertUpdate("CREATE TABLE test_shard_temporal_timestamp(col1 BIGINT, col2 TIMESTAMP) WITH (temporal_column = 'col2')");

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

    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");
    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);
}
 
Example 4
Source File: AbstractSearchIndex.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add a complete Lucene Document based on these statements. Do not search for an existing document with the same
 * subject id. (assume the existing document was deleted)
 *
 * @param statements the statements that make up the resource
 * @throws IOException
 */
@Override
public final synchronized void addDocuments(Resource subject, List<Statement> statements) throws IOException {

	String resourceId = SearchFields.getResourceID(subject);

	SetMultimap<String, Statement> stmtsByContextId = HashMultimap.create();

	String contextId;
	for (Statement statement : statements) {
		contextId = SearchFields.getContextID(statement.getContext());

		stmtsByContextId.put(contextId, statement);
	}

	BulkUpdater batch = newBulkUpdate();
	for (Entry<String, Collection<Statement>> entry : stmtsByContextId.asMap().entrySet()) {
		// create a new document
		String id = SearchFields.formIdString(resourceId, entry.getKey());
		SearchDocument document = newDocument(id, resourceId, entry.getKey());

		for (Statement stmt : entry.getValue()) {
			// determine stuff to store
			addProperty(stmt, document);
		}
		// add it to the index
		batch.add(document);
	}
	batch.end();
}
 
Example 5
Source File: ExceededOrThresholdMarkerJexlNodeTest.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public Multimap<String,NormalizedContentInterface> getEventFields(RawRecordContainer record) {
    Multimap<String,NormalizedContentInterface> eventFields = HashMultimap.create();
    NormalizedContentInterface geo_nci = new NormalizedFieldAndValue(GEO_FIELD, new String(record.getRawData()));
    eventFields.put(GEO_FIELD, geo_nci);
    return normalizeMap(eventFields);
}
 
Example 6
Source File: BaseIngestHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
private void compilePatterns() {
    Multimap<Matcher,datawave.data.type.Type<?>> patterns = HashMultimap.create();
    if (typePatternMap != null) {
        for (String pattern : typePatternMap.keySet()) {
            patterns.putAll(compileFieldNamePattern(pattern), typePatternMap.get(pattern));
        }
    }
    typeCompiledPatternMap = patterns;
}
 
Example 7
Source File: ComputeExecutorImpl.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * The Graql compute path query run method
 *
 * @return a Answer containing the list of shortest paths
 */
private Stream<ConceptList> runComputePath(GraqlCompute.Path query) {
    ConceptId fromID = ConceptId.of(query.from());
    ConceptId toID = ConceptId.of(query.to());

    if (!scopeContainsInstances(query, fromID, toID)) throw GraqlSemanticException.instanceDoesNotExist();
    if (fromID.equals(toID)) return Stream.of(new ConceptList(ImmutableList.of(fromID)));

    Set<LabelId> scopedLabelIds = convertLabelsToIds(scopeTypeLabels(query));

    ComputerResult result = compute(new ShortestPathVertexProgram(fromID, toID), null, scopedLabelIds);

    Multimap<ConceptId, ConceptId> pathsAsEdgeList = HashMultimap.create();
    Map<String, Set<String>> resultFromMemory = result.memory().get(ShortestPathVertexProgram.SHORTEST_PATH);
    resultFromMemory.forEach((id, idSet) -> idSet.forEach(id2 -> {
        pathsAsEdgeList.put(Schema.conceptIdFromVertexId(id), Schema.conceptIdFromVertexId(id2));
    }));

    List<List<ConceptId>> paths;
    if (!resultFromMemory.isEmpty()) {
        paths = getComputePathResultList(pathsAsEdgeList, fromID);
        if (scopeIncludesAttributes(query)) {
            paths = getComputePathResultList(paths);
        }
    } else {
        paths = Collections.emptyList();
    }

    return paths.stream().map(ConceptList::new);
}
 
Example 8
Source File: RuleUtils.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @param rules defining the subgraph by their when and then parts
 * @return type subgraph created by the input rules
 */
private static HashMultimap<Type, Type> persistedTypeSubGraph(Set<InferenceRule> rules){
    HashMultimap<Type, Type> graph = HashMultimap.create();
    rules.stream()
            .flatMap(persistedRuleToTypePair)
            .forEach(p -> graph.put(p.first(), p.second()));
    return graph;
}
 
Example 9
Source File: NodeOptions.java    From selenium with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: CypherUtilTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void substituteSingleRelationship() {
  Multimap<String, Object> valueMap = HashMultimap.create();
  valueMap.put("node_id", "HP_123");
  valueMap.put("rel_id", "RO_1");
  String actual = util.substituteRelationships("({node_id})-[:${rel_id}!]-(end)", valueMap);
  assertThat(actual, is("({node_id})-[:RO_1!]-(end)"));
}
 
Example 11
Source File: Closure_118_DisambiguateProperties_t.java    From coming with MIT License 5 votes vote down vote up
/** Returns a map from field name to types for which it will be renamed. */
Multimap<String, Collection<T>> getRenamedTypesForTesting() {
  Multimap<String, Collection<T>> ret = HashMultimap.create();
  for (Map.Entry<String, Property> entry : properties.entrySet()) {
    Property prop = entry.getValue();
    if (!prop.skipRenaming) {
      for (Collection<T> c : prop.getTypes().allEquivalenceClasses()) {
        if (!c.isEmpty() && !prop.typesToSkip.contains(c.iterator().next())) {
          ret.put(entry.getKey(), c);
        }
      }
    }
  }
  return ret;
}
 
Example 12
Source File: ExtendedCSVIngestHelper.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public Multimap<String,NormalizedContentInterface> normalize(Multimap<String,String> fields) {
    Multimap<String,NormalizedContentInterface> results = HashMultimap.create();
    
    for (Entry<String,String> e : fields.entries()) {
        if (e.getValue() != null) {
            // overriding this method, so we can apply groupNormalizer before other normalizers are applied
            applyNormalizationAndAddToResults(results, groupNormalizer.extractFieldNameComponents(new NormalizedFieldAndValue(e.getKey(), e.getValue())));
        } else
            log.warn(this.getType().typeName() + " has key " + e.getKey() + " with a null value.");
    }
    return results;
}
 
Example 13
Source File: SearchOccupationsDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Multimap<Occupation, Interval> getEventSpaceOccupations(Space space, Interval searchInterval) {
    Multimap<Occupation, Interval> result = HashMultimap.create();
    for (Occupation occupation : space.getOccupationSet()) {
        for (Interval occupationInterval : occupation.getIntervals()) {
            if (occupationInterval.overlaps(searchInterval)) {
                result.put(occupation, occupationInterval);
            }
        }
    }
    return result;
}
 
Example 14
Source File: PlanValidator.java    From quantumdb with Apache License 2.0 5 votes vote down vote up
private static void verifyThatAllColumnsAreMigrated(Plan plan) {
	Multimap<Table, String> columns = HashMultimap.create();
	plan.getSteps().stream()
			.map(Step::getOperation)
			.filter(op -> op.getType() == Type.COPY)
			.forEach(op -> op.getTables().forEach(table -> columns.putAll(table, op.getColumns())));

	columns.asMap().forEach((k, v) -> {
		Set<String> columnNames = k.getColumns().stream()
				.map(Column::getName)
				.collect(Collectors.toSet());

		checkState(columnNames.equals(v));
	});
}
 
Example 15
Source File: Factions0106.java    From factions-top with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onClaim(LandUnclaimEvent event) {
    Multimap<String, ChunkPos> claims = HashMultimap.create();
    claims.put(event.getFaction().getId(), getChunkPos(event.getLocation()));
    callEvent(new FactionClaimEvent(Factions.getInstance().getNone().getId(), claims));
}
 
Example 16
Source File: BucketBalancer.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Multimap<String, BucketAssignment> computeAssignmentChanges(ClusterState clusterState)
{
    Multimap<String, BucketAssignment> sourceToAllocationChanges = HashMultimap.create();

    Map<String, Long> allocationBytes = new HashMap<>(clusterState.getAssignedBytes());
    Set<String> activeNodes = clusterState.getActiveNodes();

    for (Distribution distribution : clusterState.getDistributionAssignments().keySet()) {
        // number of buckets in this distribution assigned to a node
        Multiset<String> allocationCounts = HashMultiset.create();
        Collection<BucketAssignment> distributionAssignments = clusterState.getDistributionAssignments().get(distribution);
        distributionAssignments.stream()
                .map(BucketAssignment::getNodeIdentifier)
                .forEach(allocationCounts::add);

        int currentMin = allocationBytes.keySet().stream()
                .mapToInt(allocationCounts::count)
                .min()
                .getAsInt();
        int currentMax = allocationBytes.keySet().stream()
                .mapToInt(allocationCounts::count)
                .max()
                .getAsInt();

        int numBuckets = distributionAssignments.size();
        int targetMin = (int) Math.floor((numBuckets * 1.0) / clusterState.getActiveNodes().size());
        int targetMax = (int) Math.ceil((numBuckets * 1.0) / clusterState.getActiveNodes().size());

        log.info("Distribution %s: Current bucket skew: min %s, max %s. Target bucket skew: min %s, max %s", distribution.getId(), currentMin, currentMax, targetMin, targetMax);

        for (String source : ImmutableSet.copyOf(allocationCounts)) {
            List<BucketAssignment> existingAssignments = distributionAssignments.stream()
                    .filter(assignment -> assignment.getNodeIdentifier().equals(source))
                    .collect(toList());

            for (BucketAssignment existingAssignment : existingAssignments) {
                if (activeNodes.contains(source) && allocationCounts.count(source) <= targetMin) {
                    break;
                }

                // identify nodes with bucket counts lower than the computed target, and greedily select from this set based on projected disk utilization.
                // greediness means that this may produce decidedly non-optimal results if one looks at the global distribution of buckets->nodes.
                // also, this assumes that nodes in a cluster have identical storage capacity
                String target = activeNodes.stream()
                        .filter(candidate -> !candidate.equals(source) && allocationCounts.count(candidate) < targetMax)
                        .sorted(comparingInt(allocationCounts::count))
                        .min(Comparator.comparingDouble(allocationBytes::get))
                        .orElseThrow(() -> new VerifyException("unable to find target for rebalancing"));

                long bucketSize = clusterState.getDistributionBucketSize().get(distribution);

                // only move bucket if it reduces imbalance
                if (activeNodes.contains(source) && (allocationCounts.count(source) == targetMax && allocationCounts.count(target) == targetMin)) {
                    break;
                }

                allocationCounts.remove(source);
                allocationCounts.add(target);
                allocationBytes.compute(source, (k, v) -> v - bucketSize);
                allocationBytes.compute(target, (k, v) -> v + bucketSize);

                sourceToAllocationChanges.put(
                        existingAssignment.getNodeIdentifier(),
                        new BucketAssignment(existingAssignment.getDistributionId(), existingAssignment.getBucketNumber(), target));
            }
        }
    }

    return sourceToAllocationChanges;
}
 
Example 17
Source File: DatabaseEntities.java    From cassandra-backup with Apache License 2.0 4 votes vote down vote up
public DatabaseEntities() {
    this.keyspaces = new ArrayList<>();
    this.keyspacesAndTables = HashMultimap.create();
}
 
Example 18
Source File: DeleteIndexMigration.java    From elasticsearch-migration with Apache License 2.0 4 votes vote down vote up
@Override
public Multimap<String, String> getHeaders() {
    return HashMultimap.create();
}
 
Example 19
Source File: PackageJsonValidatorExtension.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Validates the correct structure of a {@link PackageJsonProperties#SOURCES} section and returns a map between the
 * declared source container types and corresponding {@link JSONStringLiteral}s that specify the various source
 * container paths.
 */
private Multimap<SourceContainerType, List<JSONStringLiteral>> doGetSourceContainers() {
	final Collection<JSONValue> sourcesValues = getDocumentValues(SOURCES);

	// first check whether n4js.sources section has been defined at all
	if (sourcesValues.isEmpty()) {
		// return an empty map
		return ImmutableMultimap.<SourceContainerType, List<JSONStringLiteral>> of();
	}

	// first check type of all occuring 'sources' sections
	if (!checkIsType(sourcesValues, JSONPackage.Literals.JSON_OBJECT, "as source container section")) {
		// return an empty map
		return ImmutableMultimap.<SourceContainerType, List<JSONStringLiteral>> of();
	}

	// only consider the first n4js.sources section for further validation (in case of duplicates)
	final JSONValue sourcesValue = sourcesValues.iterator().next();
	final JSONObject sourceContainerObject = (JSONObject) sourcesValue;

	final Multimap<SourceContainerType, List<JSONStringLiteral>> sourceContainerValues = HashMultimap.create();

	for (NameValuePair pair : sourceContainerObject.getNameValuePairs()) {
		final String sourceContainerType = pair.getName();

		// check that sourceContainerType represents a valid source container type
		if (!isValidSourceContainerTypeLiteral(sourceContainerType)) {
			addIssue(IssueCodes.getMessageForPKGJ_INVALID_SOURCE_CONTAINER_TYPE(sourceContainerType),
					pair, JSONPackage.Literals.NAME_VALUE_PAIR__NAME,
					IssueCodes.PKGJ_INVALID_SOURCE_CONTAINER_TYPE);
			continue;
		}
		// compute type of source container sub-section
		final SourceContainerType containerType = SourceContainerType.get(pair.getName().toUpperCase());

		// check type of RHS (list of source paths)
		if (!checkIsType(pair.getValue(), JSONPackage.Literals.JSON_ARRAY, "as source container list")) {
			continue;
		}
		final JSONArray sourceContainerSpecifiers = (JSONArray) pair.getValue();
		// collect all source container paths in this list
		final List<JSONStringLiteral> specifierLiterals = new ArrayList<>();

		for (JSONValue specifier : sourceContainerSpecifiers.getElements()) {
			if (!checkIsType(specifier, JSONPackage.Literals.JSON_STRING_LITERAL,
					"as source container specifier")) {
				continue;
			}
			specifierLiterals.add((JSONStringLiteral) specifier);
		}

		// This may override a value in case of a duplicate containerType (e.g. two external sections).
		// However, this will also issue an appropriate warning for a duplicate key and
		// is therefore not handled here.
		sourceContainerValues.put(containerType, specifierLiterals);
	}

	return sourceContainerValues;
}
 
Example 20
Source File: EventMapperTest.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    long eventTime = System.currentTimeMillis();
    
    eventMapper = new EventMapper<>();
    conf = new Configuration();
    conf.setClass(EventMapper.CONTEXT_WRITER_CLASS, TestContextWriter.class, ContextWriter.class);
    
    Type type = new Type("file", null, null, new String[] {SimpleDataTypeHandler.class.getName()}, 10, null);
    Type errorType = new Type(TypeRegistry.ERROR_PREFIX, null, null, new String[] {SimpleDataTypeHandler.class.getName()}, 20, null);
    
    TypeRegistry registry = TypeRegistry.getInstance(conf);
    registry.put(type.typeName(), type);
    registry.put(errorType.typeName(), errorType);
    
    Multimap<String,NormalizedContentInterface> fields = HashMultimap.create();
    fields.put("fileExtension", new BaseNormalizedContent("fileExtension", "gz"));
    fields.put("lastModified", new BaseNormalizedContent("lastModified", "2016-01-01"));
    
    SimpleDataTypeHelper.registerFields(fields);
    
    record = new SimpleRawRecord();
    record.setRawFileTimestamp(eventTime);
    record.setDataType(type);
    record.setDate(eventTime);
    record.setRawFileName("/some/filename");
    record.setRawData("some data".getBytes());
    record.generateId(null);
    
    errorRecord = new SimpleRawRecord();
    errorRecord.setRawFileTimestamp(0);
    errorRecord.setDataType(type);
    errorRecord.setDate(eventTime);
    errorRecord.setRawFileName("/some/filename");
    errorRecord.setRawData("some data".getBytes());
    errorRecord.generateId(null);
    errorRecord.setRawFileName("");
    errorRecord.addError("EVENT_DATE_MISSING");
    errorRecord.setFatalError(true);
    
    expect(mapContext.getConfiguration()).andReturn(conf).anyTimes();
    
    mapContext.progress();
    expectLastCall().anyTimes();
    
    TestContextWriter<BulkIngestKey,Value> testContextWriter = new TestContextWriter<>();
    mapContext.write(anyObject(BulkIngestKey.class), anyObject(Value.class));
    expectLastCall().andDelegateTo(testContextWriter).anyTimes();
    
    expect(mapContext.getInputSplit()).andReturn(null);
    expect(mapContext.getMapOutputValueClass()).andReturn(null);
    
    StandaloneTaskAttemptContext standaloneContext = new StandaloneTaskAttemptContext(conf, new StandaloneStatusReporter());
    expect(mapContext.getCounter(anyObject())).andDelegateTo(standaloneContext).anyTimes();
    expect(mapContext.getCounter(anyString(), anyString())).andDelegateTo(standaloneContext).anyTimes();
    
    replay(mapContext);
}