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

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

源代码1 项目: datawave   文件: ExpandCompositeTermsTest.java
@BeforeClass
public static void beforeClass() {
    Multimap<String,String> multimap = LinkedListMultimap.create();
    multimap.clear();
    multimap.put("MAKE_COLOR", "MAKE");
    multimap.put("MAKE_COLOR", "COLOR");
    multimap.put("COLOR_WHEELS", "COLOR");
    multimap.put("COLOR_WHEELS", "WHEELS");
    multimap.put("TEAM_NAME_POINTS", "TEAM");
    multimap.put("TEAM_NAME_POINTS", "NAME");
    multimap.put("TEAM_NAME_POINTS", "POINTS");
    multimap.put("TEAM_POINTS", "TEAM");
    multimap.put("TEAM_POINTS", "POINTS");
    compositeToFieldMap = Multimaps.unmodifiableMultimap(multimap);
    
    Map<String,String> sepMap = new HashMap<>();
    sepMap.put("MAKE_COLOR", ",");
    sepMap.put("COLOR_WHEELS", ",");
    sepMap.put("TEAM_NAME_POINTS", ",");
    sepMap.put("TEAM_POINTS", ",");
    compositeFieldSeparators = Collections.unmodifiableMap(sepMap);
}
 
源代码2 项目: emissary   文件: BaseDataObjectTest.java
@Test
public void testPutParametersWithMultimapAsMap() {
    final Multimap<String, String> map = ArrayListMultimap.create();
    map.put("ONE", "uno");
    map.put("ONE", "ein");
    map.put("ONE", "neo");
    map.put("TWO", "deux");
    this.b.putParameter("TWO", "dos");
    this.b.putParameters(map.asMap());
    assertEquals("Multimap parameters should merge", 3, this.b.getParameter("ONE").size());
    assertEquals("Multimap parameters should merge", 2, this.b.getParameter("TWO").size());
    map.clear();
    assertEquals("Multimap parameters should be detached from callers map", 3, this.b.getParameter("ONE").size());
    assertEquals("Multimap parameters should be detached from callers map", 2, this.b.getParameter("TWO").size());
    map.put("THREE", "tres");
    this.b.mergeParameters(map.asMap());
    assertEquals("Multimap parameters should merge", 1, this.b.getParameter("THREE").size());
    map.put("FOUR", "cuatro");
    this.b.putUniqueParameters(map.asMap());
    assertEquals("Multimap parameters should remain unique", 1, this.b.getParameter("THREE").size());
    assertEquals("Multimap params should add on unique", 1, this.b.getParameter("FOUR").size());
}
 
源代码3 项目: emodb   文件: DefaultFanout.java
private void flush(List<String> eventKeys, Multimap<String, ByteBuffer> eventsByChannel,
                   int numOutboundReplicationEvents) {
    try (Timer.Context ignore = _eventFlushTimer.time()) {
        if (!eventsByChannel.isEmpty()) {
            _eventSink.apply(eventsByChannel);
            _eventsWrittenLocal.mark(eventsByChannel.size() - numOutboundReplicationEvents);
            _eventsWrittenOutboundReplication.mark(numOutboundReplicationEvents);
            eventsByChannel.clear();
        }
        if (!eventKeys.isEmpty()) {
            _eventSource.delete(eventKeys);
            _eventsRead.mark(eventKeys.size());
            eventKeys.clear();
        }
    }
}
 
源代码4 项目: n4js   文件: MultiCleartriggerCache.java
/** Removes all cached values for a given key */
public void clear(String key) {
	Map<URI, Object> map = entryCache.get(key);
	Multimap<URI, URI> triggerMap = triggerCache.get(key);
	if (map != null) {
		map.clear();
	}
	if (triggerMap != null) {
		triggerMap.clear();
	}
}
 
源代码5 项目: xtext-eclipse   文件: AbstractReferenceUpdater.java
protected void createClusteredReferenceUpdates(ElementRenameArguments elementRenameArguments,
		Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
		IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
	SubMonitor progress = SubMonitor.convert(monitor, resource2references.keySet().size() + 1);
	if (loadTargetResources(resourceSet, elementRenameArguments, status, progress.newChild(1))) {
		if (getClusterSize() > 0) {
			Set<Resource> targetResources = newHashSet(resourceSet.getResources());
			Multimap<URI, IReferenceDescription> cluster = HashMultimap.create();
			SubMonitor clusterMonitor = progress.newChild(1);
			for (URI referringResourceURI : resource2references.keySet()) {
				cluster.putAll(referringResourceURI, resource2references.get(referringResourceURI));
				if (cluster.keySet().size() == getClusterSize()) {
					unloadNonTargetResources(resourceSet, targetResources);
					createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor, status, clusterMonitor);
					cluster.clear();
				}
			}
			if (!cluster.isEmpty()) {
				unloadNonTargetResources(resourceSet, targetResources);
				createReferenceUpdatesForCluster(elementRenameArguments, cluster, resourceSet, updateAcceptor,
						status, clusterMonitor);
			}
		} else {
			createReferenceUpdatesForCluster(elementRenameArguments, resource2references, resourceSet,
					updateAcceptor, status, progress.newChild(resource2references.keySet().size()));
		}
	}
}
 
源代码6 项目: kylin-on-parquet-v2   文件: OLAPJoinRel.java
@Override
    public void implementOLAP(OLAPImplementor implementor) {

        // create context for root join
        if (!(implementor.getParentNode() instanceof OLAPJoinRel) && !isParentMerelyPermutation(implementor)) {
            implementor.allocateContext();
        }
        //parent context
        this.context = implementor.getContext();
        this.context.allOlapJoins.add(this);
        this.isTopJoin = !this.context.hasJoin;
        this.context.hasJoin = true;

        boolean leftHasSubquery = false;
        boolean rightHasSubquery = false;

        // as we keep the first table as fact table, we need to visit from left to right
        implementor.fixSharedOlapTableScanOnTheLeft(this);
        implementor.visitChild(this.left, this);

        //current  has another context
        if (this.context != implementor.getContext() || ((OLAPRel) this.left).hasSubQuery()) {
            this.hasSubQuery = true;
            leftHasSubquery = true;
            // if child is also an OLAPJoin, then the context has already been popped
            if (this.context != implementor.getContext()) {
                implementor.freeContext();
            }
        }

        if (leftHasSubquery) {
            // After KYLIN-2579, leftHasSubquery means right side have to be separate olap context 
            implementor.setNewOLAPContextRequired(true);
        }

        implementor.fixSharedOlapTableScanOnTheRight(this);
        implementor.visitChild(this.right, this);
        if (this.context != implementor.getContext() || ((OLAPRel) this.right).hasSubQuery()) {
            this.hasSubQuery = true;
            rightHasSubquery = true;
            // if child is also an OLAPJoin, then the context has already been popped

            if (leftHasSubquery) {
                Preconditions.checkState(!implementor.isNewOLAPContextRequired());//should have been satisfied
                Preconditions.checkState(this.context != implementor.getContext(), "missing a new olapcontext");
            }

            if (this.context != implementor.getContext()) {
                implementor.freeContext();
            }
        }

        this.columnRowType = buildColumnRowType();

        if (isTopJoin) {
            this.context.afterJoin = true;
        }

        if (!this.hasSubQuery) {
//            this.context.allColumns.clear();

            // build JoinDesc
            Preconditions.checkState(this.getCondition() instanceof RexCall, "Cartesian Join is not supported.");

            RexCall condition = (RexCall) this.getCondition();
            JoinDesc join = buildJoin(condition);

            JoinRelType joinRelType = this.getJoinType();
            String joinType = joinRelType == JoinRelType.INNER ? "INNER"
                    : joinRelType == JoinRelType.LEFT ? "LEFT" : joinRelType == JoinRelType.RIGHT ? "RIGHT" : "FULL";
            join.setType(joinType);

            this.context.joins.add(join);
        } else {
            //When join contains subquery, the join-condition fields of fact_table will add into context.
            Multimap<TblColRef, TblColRef> joinCol = HashMultimap.create();
            translateJoinColumn(this.getCondition(), joinCol);

            for (Map.Entry<TblColRef, TblColRef> columnPair : joinCol.entries()) {
                TblColRef fromCol = (rightHasSubquery ? columnPair.getKey() : columnPair.getValue());
                this.context.subqueryJoinParticipants.add(fromCol);
            }
            joinCol.clear();
        }
    }
 
源代码7 项目: datawave   文件: EventMapper.java
/**
 * This is where we apply a list of handlers to an event.
 *
 * @param key
 *            The key of the map process
 * @param value
 *            The event
 * @param handlers
 *            The list of handlers to apply
 * @param fields
 *            The list which keeps the last set of fields (retained in case the caller needs to handle a thrown exception)
 * @param context
 *            The context
 * @throws Exception
 */
public void processEvent(K1 key, RawRecordContainer value, List<DataTypeHandler<K1>> handlers, Multimap<String,NormalizedContentInterface> fields,
                Context context) throws Exception {
    IngestHelperInterface previousHelper = null;
    
    for (DataTypeHandler<K1> handler : handlers) {
        if (log.isTraceEnabled())
            log.trace("executing handler: " + handler.getClass().getName());
        
        // gather the fields
        IngestHelperInterface thisHelper = handler.getHelper(value.getDataType());
        
        // This handler has no helper for the event's data type. Therefore, we should
        // just move on to the next handler. This can happen, for example, with the
        // edge handler, depending on the event's data type.
        if (thisHelper == null) {
            if (log.isTraceEnabled())
                log.trace("Aborting processing due to null ingest helper");
            continue;
        }
        
        // Try to only parse the event once. Parse the event on the first pass and only if
        // the BaseIngestHelper class differs. The same class used by different handlers
        // *should* produce the same result.
        if (null == previousHelper || !previousHelper.getClass().getName().equals(thisHelper.getClass().getName())) {
            fields.clear();
            Throwable e = null;
            for (Map.Entry<String,NormalizedContentInterface> entry : getFields(value, handler).entries()) {
                // noinspection ThrowableResultOfMethodCallIgnored
                if (entry.getValue().getError() != null) {
                    e = entry.getValue().getError();
                }
                fields.put(entry.getKey(), entry.getValue());
            }
            if (e != null) {
                throw new FieldNormalizationError("Failed getting all fields", e);
            }
            
            // Event based metrics
            if (metricsEnabled) {
                metricsLabels.clear();
                metricsLabels.put("dataType", value.getDataType().typeName());
                
                metricsService.collect(Metric.EVENT_COUNT, metricsLabels.get(), fields, 1L);
                metricsService.collect(Metric.BYTE_COUNT, metricsLabels.get(), fields, (long) value.getRawData().length);
            }
            
            previousHelper = thisHelper;
        }
        
        Collection<FieldValidator> fieldValidators = validators.get(value.getDataType().outputName());
        for (FieldValidator validator : fieldValidators) {
            validator.validate(value, fields);
        }
        
        executeHandler(key, value, fields, handler, context);
        
        context.progress();
    }
}
 
源代码8 项目: Clusion   文件: Partition.java
public static Multimap<Integer, String> partitioning(Multimap<String, String> lookup) {

		// Partitions Creation
		Set<String> keys = lookup.keySet();

		int partitionId = 0;
		Multimap<Integer, String> partitions = ArrayListMultimap.create();
		int counter2 = 0;

		for (String key : keys) {
			Set<Integer> keys2 = partitions.keySet();
			List<String> inter = (List<String>) lookup.get(key);
			List<String> interTMP = new ArrayList<String>(inter);

			Printer.debugln("Step number: " + counter2++ + "Number of keywords " + keys.size());

			Set<String> set = new HashSet<String>(interTMP);
			Multimap<Integer, String> partitionsTMP = ArrayListMultimap.create();

			for (Integer key2 : keys2) {

				if (!set.isEmpty()) {
					Set<String> tmp = new HashSet<String>(partitions.get(key2));

					Set<String> intersection = Sets.intersection(tmp, set);

					Set<String> difference;

					if (intersection.isEmpty()) {
						difference = tmp;
					} else {
						difference = Sets.difference(tmp, intersection);
						set = Sets.difference(set, intersection);

					}

					if (!difference.isEmpty()) {
						partitionId = partitionId + 1;
						partitionsTMP.putAll(partitionId, difference);
					}

					if (!intersection.isEmpty()) {
						partitionId = partitionId + 1;
						partitionsTMP.putAll(partitionId, intersection);
					}

				} else {
					partitionId = partitionId + 1;
					partitionsTMP.putAll(partitionId, new HashSet<String>(partitions.get(key2)));
				}

			}

			interTMP = new ArrayList<String>(set);

			if (!interTMP.isEmpty()) {

				partitionId = partitionId + 1;
				partitionsTMP.putAll(partitionId, interTMP);

			}

			partitions = ArrayListMultimap.create(partitionsTMP);
			partitionsTMP.clear();
			interTMP.clear();

		}

		Printer.debugln("Partitions size " + partitions.keySet().size());
		Printer.debugln("\n");

		return partitions;
	}
 
源代码9 项目: kylin   文件: OLAPJoinRel.java
@Override
    public void implementOLAP(OLAPImplementor implementor) {

        // create context for root join
        if (!(implementor.getParentNode() instanceof OLAPJoinRel) && !isParentMerelyPermutation(implementor)) {
            implementor.allocateContext();
        }
        //parent context
        this.context = implementor.getContext();
        this.context.allOlapJoins.add(this);
        this.isTopJoin = !this.context.hasJoin;
        this.context.hasJoin = true;

        boolean leftHasSubquery = false;
        boolean rightHasSubquery = false;

        // as we keep the first table as fact table, we need to visit from left to right
        implementor.fixSharedOlapTableScanOnTheLeft(this);
        implementor.visitChild(this.left, this);

        //current  has another context
        if (this.context != implementor.getContext() || ((OLAPRel) this.left).hasSubQuery()) {
            this.hasSubQuery = true;
            leftHasSubquery = true;
            // if child is also an OLAPJoin, then the context has already been popped
            if (this.context != implementor.getContext()) {
                implementor.freeContext();
            }
        }

        if (leftHasSubquery) {
            // After KYLIN-2579, leftHasSubquery means right side have to be separate olap context 
            implementor.setNewOLAPContextRequired(true);
        }

        implementor.fixSharedOlapTableScanOnTheRight(this);
        implementor.visitChild(this.right, this);
        if (this.context != implementor.getContext() || ((OLAPRel) this.right).hasSubQuery()) {
            this.hasSubQuery = true;
            rightHasSubquery = true;
            // if child is also an OLAPJoin, then the context has already been popped

            if (leftHasSubquery) {
                Preconditions.checkState(!implementor.isNewOLAPContextRequired());//should have been satisfied
                Preconditions.checkState(this.context != implementor.getContext(), "missing a new olapcontext");
            }

            if (this.context != implementor.getContext()) {
                implementor.freeContext();
            }
        }

        this.columnRowType = buildColumnRowType();

        if (isTopJoin) {
            this.context.afterJoin = true;
        }

        if (!this.hasSubQuery) {
//            this.context.allColumns.clear();

            // build JoinDesc
            Preconditions.checkState(this.getCondition() instanceof RexCall, "Cartesian Join is not supported.");

            RexCall condition = (RexCall) this.getCondition();
            JoinDesc join = buildJoin(condition);

            JoinRelType joinRelType = this.getJoinType();
            String joinType = joinRelType == JoinRelType.INNER ? "INNER"
                    : joinRelType == JoinRelType.LEFT ? "LEFT" : joinRelType == JoinRelType.RIGHT ? "RIGHT" : "FULL";
            join.setType(joinType);

            this.context.joins.add(join);
        } else {
            //When join contains subquery, the join-condition fields of fact_table will add into context.
            Multimap<TblColRef, TblColRef> joinCol = HashMultimap.create();
            translateJoinColumn(this.getCondition(), joinCol);

            for (Map.Entry<TblColRef, TblColRef> columnPair : joinCol.entries()) {
                TblColRef fromCol = (rightHasSubquery ? columnPair.getKey() : columnPair.getValue());
                this.context.subqueryJoinParticipants.add(fromCol);
            }
            joinCol.clear();
        }
    }