com.google.common.collect.ArrayListMultimap#create ( )源码实例Demo

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

源代码1 项目: incubator-pinot   文件: MetricMappingPipeline.java
/**
 * Prunes filter set to only allow dimensions that are available in a metrics own dataset
 *
 * @param metricId metric id
 * @return pruned filter multimap
 */
private Multimap<String, String> pruneFilters(Multimap<String, String> filters, long metricId) {
  MetricConfigDTO metric = this.metricDAO.findById(metricId);
  if (metric == null) {
    LOG.warn("Could not resolve metric id {} while pruning filters", metricId);
    return ArrayListMultimap.create();
  }

  DatasetConfigDTO dataset = this.datasetDAO.findByDataset(metric.getDataset());
  if (dataset == null) {
    LOG.warn("Could not resolve dataset '{}' for metric id {} while pruning filters", metric.getDataset(), metricId);
    return ArrayListMultimap.create();
  }

  Multimap<String, String> output = TreeMultimap.create(); // sorted, unique keys
  Set<String> validKeys = new HashSet<>(dataset.getDimensions());
  for (Map.Entry<String, String> entry : filters.entries()) {
    if (validKeys.contains(entry.getKey())) {
      output.put(entry.getKey(), entry.getValue());
    }
  }
  return output;
}
 
源代码2 项目: py4j   文件: Py4jDictionary.java
private ArrayListMultimap<String, String> loadVocabulary0(String name) {
    debug("******start load py4j config******");
    ArrayListMultimap<String,String> duoYinZiMap = ArrayListMultimap.create(512, 32);
    String filename = PREFIX + name;
    try{
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Enumeration<URL> urls = cl.getResources(filename);
        if(urls!=null){
            while (urls.hasMoreElements()) {
                URL url = urls.nextElement();
                parseURL(url, duoYinZiMap);
            }
        }
    } catch (Exception e){
        error("caught exception when load py4j vocabulary", e);
        throw new RuntimeException("caught exception when load py4j vocabulary", e);
    }
    debug("******load py4j config over******");
    debug("py4j map key size:{}", duoYinZiMap.keySet().size());
    return duoYinZiMap;
}
 
源代码3 项目: score   文件: ExecutionQueueServiceTest.java
@Test
public void pollWithoutAckTestInProgressState() throws Exception {
	Multimap<String, String> groupWorkerMap = ArrayListMultimap.create();
	groupWorkerMap.put("group1", "worker1");
	groupWorkerMap.put("group1", "worker2");
	when(workerNodeService.readGroupWorkersMapActiveAndRunningAndVersion(engineVersionService.getEngineVersionId())).thenReturn(groupWorkerMap);

	when(versionService.getCurrentVersion(anyString())).thenReturn(0L);

	List<ExecutionMessage> msgInQueue = executionQueueService.pollMessagesWithoutAck(100, 0);
	Assert.assertEquals(0, msgInQueue.size());

	ExecutionMessage message1 = generateMessage("group1", "5");
	message1.setWorkerId("worker1");
	message1.setStatus(ExecStatus.IN_PROGRESS);

	msgInQueue.clear();
	msgInQueue.add(message1);

	executionQueueService.enqueue(msgInQueue);

	//now we set current system version(100) to be mush higher then msg version (0)
	msgInQueue = executionQueueService.pollMessagesWithoutAck(100, 100);
	Assert.assertEquals("since we sent a msg in IN_PROGRESS status, pollMessagesWithoutAck should not find it", 0, msgInQueue.size());
}
 
源代码4 项目: javaide   文件: ExternalAnnotationRepository.java
private void mergeMethodOrParameter(Element item, Matcher matcher, String containingClass,
        String methodName, boolean constructor, String parameters) {
    parameters = fixParameterString(parameters);

    MethodInfo method = createMethod(containingClass, methodName, constructor, parameters);
    List<ResolvedAnnotation> annotations = createAnnotations(item);

    String argNum = matcher.group(7);
    if (argNum != null) {
        argNum = argNum.trim();
        int parameter = Integer.parseInt(argNum);

        if (method.parameterAnnotations == null) {
            // Do I know the parameter count here?
            int parameterCount = 4;
            method.parameterAnnotations = ArrayListMultimap
                    .create(parameterCount, annotations.size());
        }
        for (ResolvedAnnotation annotation : annotations) {
            method.parameterAnnotations.put(parameter, annotation);
        }
    } else {
        if (method.annotations == null) {
            method.annotations = Lists.newArrayListWithExpectedSize(annotations.size());
        }
        method.annotations.addAll(annotations);
    }
}
 
源代码5 项目: mars-sim   文件: TabPanelCooking.java
private CookingTableModel(Settlement settlement) {
	this.settlement = settlement;

	// dotRed = ImageLoader.getIcon(Msg.getString("img.dotRed")); //$NON-NLS-1$
	// dotYellow = ImageLoader.getIcon(Msg.getString("img.dotYellow"));
	// //$NON-NLS-1$
	// dotGreen = ImageLoader.getIcon(Msg.getString("img.dotGreen")); //$NON-NLS-1$

	allServingsSet = HashMultiset.create();
	allQualityMap = ArrayListMultimap.create();
	allTimeMap = ArrayListMultimap.create();

}
 
源代码6 项目: javaide   文件: MergedResourceWriter.java
@Override
public void start(@NonNull DocumentBuilderFactory factory) throws ConsumerException {
    super.start(factory);
    mValuesResMap = ArrayListMultimap.create();
    mQualifierWithDeletedValues = Sets.newHashSet();
    mFactory = factory;
}
 
源代码7 项目: onos   文件: YangXmlUtils.java
/**
 * Retrieves a valid XML configuration for a specific XML path for multiple
 * instance of YangElements objects.
 *
 * @param file     path of the file to be used.
 * @param elements List of YangElements that are to be set.
 * @return Hierachical configuration containing XML with values.
 */
public XMLConfiguration getXmlConfiguration(String file, List<YangElement> elements) {
    InputStream stream = getCfgInputStream(file);
    HierarchicalConfiguration cfg = loadXml(stream);
    XMLConfiguration complete = new XMLConfiguration();
    Multimap<String, YangElement> commonElements = ArrayListMultimap.create();

    //saves the elements in a Multimap based on the computed key.
    elements.forEach(element -> {
        String completeKey = nullIsNotFound(findPath(cfg, element.getBaseKey()),
                                            "Yang model does not contain desired path");
        commonElements.put(completeKey, element);
    });

    //iterates over the elements and constructs the configuration
    commonElements.keySet().forEach(key -> {
        // if there is more than one element for a given path
        if (commonElements.get(key).size() > 1) {
            //creates a list of nodes that have to be added for that specific path
            ArrayList<ConfigurationNode> nodes = new ArrayList<>();
            //creates the nodes
            commonElements.get(key).forEach(element -> nodes.add(getInnerNode(element).getRootNode()));
            //computes the parent path
            String parentPath = key.substring(0, key.lastIndexOf("."));
            //adds the nodes to the complete configuration
            complete.addNodes(parentPath, nodes);
        } else {
            //since there is only a single element we can assume it's the first one.
            Map<String, String> keysAndValues = commonElements.get(key).stream().
                    findFirst().get().getKeysAndValues();
            keysAndValues.forEach((k, v) -> complete.setProperty(key + "." + k, v));
        }
    });
    addProperties(cfg, complete);
    return complete;
}
 
源代码8 项目: incubator-pinot   文件: DimensionsEntityTest.java
@Test
public void testEncode() {
  Multimap<String, String> dimensions = ArrayListMultimap.create();
  dimensions.put("key", "value!");
  dimensions.put("key", "other=Value");
  dimensions.put("otherKey", "another:Value");

  DimensionsEntity e = DimensionsEntity.fromDimensions(1.0, dimensions);

  Assert.assertEquals(e.getUrn(), "thirdeye:dimensions:key%3Dother%3DValue:key%3Dvalue!:otherKey%3Danother%3AValue");
}
 
源代码9 项目: cloudbreak   文件: SaltErrorResolver.java
public Multimap<String, String> resolveErrorMessages(Multimap<String, String> missingNodesWithReason) {
    LOGGER.info("Original missing nodes: {}", missingNodesWithReason);
    Multimap<String, String> missingTargetsWithReplacedReasons = ArrayListMultimap.create();
    missingNodesWithReason.entries().forEach(entry -> {
        String value = resolveMessageIfAvailable(entry.getValue());
        missingTargetsWithReplacedReasons.put(entry.getKey(), value);
    });
    LOGGER.info("Missing nodes after replace: {}", missingTargetsWithReplacedReasons);
    return missingTargetsWithReplacedReasons;
}
 
private Multimap<String, String> run() throws IOException {
  List<Fact> typesRelationSet = yago3Reader.getFacts(YAGO3RelationNames.hasWikipediaCategory);
  Multimap<String, String> entityTypeMap = ArrayListMultimap.create();
  
  for(Fact entry: typesRelationSet) {
    entityTypeMap.put(entry.getSubject(), entry.getObject());
  }
  
  return entityTypeMap;
}
 
@Test
public void fire_event() {
    ArrayListMultimap<Class<? extends DomainEvent>, Class<? extends DomainEventHandler>> multiMap =
            ArrayListMultimap.create();
    multiMap.put(SomeDomainEvent.class, MyDomainEventHandler.class);

    underTest = new DomainEventPublisherImpl(injector, multiMap);
    underTest.publish(new MyDomainEvent());
}
 
源代码12 项目: simpleretrogen   文件: WorldRetrogen.java
private void queueRetrogen(String retro, World world, ChunkPos chunkCoords)
{
    if (world instanceof WorldServer)
    {
        ListMultimap<ChunkPos, String> currentWork = pendingWork.get(world);
        if (currentWork == null)
        {
            currentWork = ArrayListMultimap.create();
            pendingWork.put(world, currentWork);
        }

        currentWork.put(chunkCoords, retro);
    }
}
 
源代码13 项目: Strata   文件: FpmlDocument.java
private static ImmutableListMultimap<String, String> parseParties(XmlElement root) {
  ListMultimap<String, String> parties = ArrayListMultimap.create();
  for (XmlElement child : root.getChildren("party")) {
    parties.putAll(child.getAttribute(ID), findPartyIds(child));
  }
  return ImmutableListMultimap.copyOf(parties);
}
 
源代码14 项目: onos   文件: VirtualIntentInstallCoordinator.java
/**
 * Applies Intent data to be uninstalled and to be installed.
 *
 * @param toUninstall Intent data to be uninstalled
 * @param toInstall Intent data to be installed
 */
public void installIntents(Optional<IntentData> toUninstall,
                           Optional<IntentData> toInstall) {
    // If no any Intents to be uninstalled or installed, ignore it.
    if (!toUninstall.isPresent() && !toInstall.isPresent()) {
        return;
    }

    // Classify installable Intents to different installers.
    ArrayListMultimap<IntentInstaller, Intent> uninstallInstallers;
    ArrayListMultimap<IntentInstaller, Intent> installInstallers;
    Set<IntentInstaller> allInstallers = Sets.newHashSet();

    if (toUninstall.isPresent()) {
        uninstallInstallers = getInstallers(toUninstall.get());
        allInstallers.addAll(uninstallInstallers.keySet());
    } else {
        uninstallInstallers = ArrayListMultimap.create();
    }

    if (toInstall.isPresent()) {
        installInstallers = getInstallers(toInstall.get());
        allInstallers.addAll(installInstallers.keySet());
    } else {
        installInstallers = ArrayListMultimap.create();
    }

    // Generates an installation context for the high level Intent.
    IntentInstallationContext installationContext =
            new IntentInstallationContext(toUninstall.orElse(null), toInstall.orElse(null));

    //Generates different operation context for different installable Intents.
    Map<IntentInstaller, IntentOperationContext> contexts = Maps.newHashMap();
    allInstallers.forEach(installer -> {
        List<Intent> intentsToUninstall = uninstallInstallers.get(installer);
        List<Intent> intentsToInstall = installInstallers.get(installer);

        // Connect context to high level installation context
        IntentOperationContext context =
                new IntentOperationContext(intentsToUninstall, intentsToInstall,
                                           installationContext);
        installationContext.addPendingContext(context);
        contexts.put(installer, context);
    });

    // Apply contexts to installers
    contexts.forEach((installer, context) -> {
        installer.apply(context);
    });
}
 
源代码15 项目: Clusion   文件: RH2Lev.java
public static RH2Lev constructEMMPar(final byte[] key, final Multimap<String, String> lookup, final int bigBlock,
		final int smallBlock, final int dataSize) throws InterruptedException, ExecutionException, IOException {

	final Multimap<String, byte[]> dictionary = ArrayListMultimap.create();

	for (int i = 0; i < dataSize; i++) {
		free.add(i);
	}
	random.setSeed(CryptoPrimitives.randomSeed(16));

	List<String> listOfKeyword = new ArrayList<String>(lookup.keySet());
	int threads = 0;
	if (Runtime.getRuntime().availableProcessors() > listOfKeyword.size()) {
		threads = listOfKeyword.size();
	} else {
		threads = Runtime.getRuntime().availableProcessors();
	}

	ExecutorService service = Executors.newFixedThreadPool(threads);
	ArrayList<String[]> inputs = new ArrayList<String[]>(threads);

	final Map<Integer, String> concurrentMap = new ConcurrentHashMap<Integer, String>();
	for (int i = 0; i < listOfKeyword.size(); i++) {
		concurrentMap.put(i, listOfKeyword.get(i));
	}

	for (int j = 0; j < threads; j++) {
		service.execute(new Runnable() {
			@SuppressWarnings("unused")
			@Override
			public void run() {

				while (concurrentMap.keySet().size() > 0) {

					Random rand = new Random();
					String[] input = {""};
					synchronized (concurrentMap) {
						Set<Integer> possibleValues = concurrentMap.keySet();
						int temp = rand.nextInt(possibleValues.size());
						List<Integer> listOfPossibleKeywords = new ArrayList<Integer>(possibleValues);
						// set the input as randomly selected from the remaining
						// possible keys
						input[0] = concurrentMap.get(listOfPossibleKeywords.get(temp)) ;
						// remove the key
						concurrentMap.remove(listOfPossibleKeywords.get(temp));
					}

					try {

						Multimap<String, byte[]> output = setup(key, input, lookup, bigBlock, smallBlock, dataSize);
						Set<String> keys = output.keySet();

						for (String k : keys) {
							dictionary.putAll(k, output.get(k));
						}
					} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException
							| NoSuchPaddingException | IOException | InvalidAlgorithmParameterException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});
	}

	service.shutdown();

	// Blocks until all tasks have completed execution after a shutdown
	// request
	service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);

	return new RH2Lev(dictionary, array);
}
 
源代码16 项目: incubator-pinot   文件: EventSlice.java
public EventSlice() {
  this.start = -1;
  this.end = -1;
  this.filters = ArrayListMultimap.create();
}
 
源代码17 项目: kite   文件: ExtractProtobufPathsBuilder.java
public ExtractProtobufPaths(CommandBuilder builder, Config config, Command parent, Command child,
    MorphlineContext context) {

  super(builder, config, parent, child, context);
  ListMultimap<String, String> stepMultiMap = ArrayListMultimap.create();

  this.objectExtractMethod = new Validator<ObjectExtractMethods>().validateEnum(config,
      getConfigs().getString(config, OBJECT_EXTRACT_METHOD, ObjectExtractMethods.toByteArray.name()),
      ObjectExtractMethods.class);
  this.enumExtractMethod = new Validator<EnumExtractMethods>()
      .validateEnum(config, getConfigs().getString(config, ENUM_EXTRACT_METHOD, EnumExtractMethods.name.name()),
          EnumExtractMethods.class);

  Config paths = getConfigs().getConfig(config, "paths");
  for (Map.Entry<String, Object> entry : new Configs().getEntrySet(paths)) {
    String fieldName = entry.getKey();
    String path = entry.getValue().toString().trim();
    if (path.contains("//")) {
      throw new MorphlineCompilationException("No support for descendant axis available yet", config);
    }
    if (path.startsWith("/")) {
      path = path.substring(1);
    }
    if (path.endsWith("/")) {
      path = path.substring(0, path.length() - 1);
    }
    path = path.trim();
    for (String step : path.split("/")) {
      step = step.trim();
      if (step.length() > ARRAY_TOKEN.length() && step.endsWith(ARRAY_TOKEN)) {
        step = step.substring(0, step.length() - ARRAY_TOKEN.length());
        stepMultiMap.put(fieldName, normalize(step));
        stepMultiMap.put(fieldName, ARRAY_TOKEN);
      } else {
        stepMultiMap.put(fieldName, normalize(step));
      }
    }
  }
  this.stepMap = stepMultiMap.asMap();
  LOG.debug("stepMap: {}", stepMap);
  validateArguments();
}
 
源代码18 项目: tassal   文件: SampleUtils.java
/**
 * Partition a set of elements into different weight bins (defined by
 * partitionWeights), where each element has a weight defined by
 * elementWeights. The order with which the partition is made is given by
 * orderedElements.
 * 
 * This method sequentially adds elements into bins until the bin weight has
 * been fully filled. No guarantees are given about how accurate the binning
 * will be, since this is not an optimization algorithm.
 * 
 * @param elementWeights
 * @param partitionWeights
 * @param orderedElements
 * @return
 */
public static <K, T> Multimap<K, T> partitionGivenOrder(
		final Map<T, Double> elementWeights,
		final Map<K, Double> partitionWeights,
		final List<Entry<T, Double>> orderedElements) {
	final Multimap<K, T> partitions = ArrayListMultimap.create();

	final double elementWeightSum = StatsUtil.sum(elementWeights.values());
	final double partitionWeightSum = StatsUtil.sum(partitionWeights
			.values());

	final List<Entry<K, Double>> partitionList = Lists
			.newArrayList(partitionWeights.entrySet());

	int currentPartitionIdx = 0;
	double currentElementSum = 0;
	double currentPartitionSum = 0;

	for (int currentElementIdx = 0; currentElementIdx < orderedElements
			.size(); currentElementIdx++) {
		double partitionPoint = (currentPartitionSum + partitionList.get(
				currentPartitionIdx).getValue())
				/ partitionWeightSum;
		final double elementWeightPoint = currentElementSum
				/ elementWeightSum;
		currentElementSum += orderedElements.get(currentElementIdx)
				.getValue();

		while (partitionPoint <= elementWeightPoint) {
			currentPartitionSum += partitionList.get(currentPartitionIdx)
					.getValue();
			currentPartitionIdx++;
			partitionPoint = (currentPartitionSum + partitionList.get(
					currentPartitionIdx).getValue())
					/ partitionWeightSum;
		}
		partitions.put(partitionList.get(currentPartitionIdx).getKey(),
				orderedElements.get(currentElementIdx).getKey());
	}

	return partitions;
}
 
源代码19 项目: phoenix   文件: TestParalleIndexWriter.java
@SuppressWarnings({ "unchecked", "deprecation" })
@Test
public void testSynchronouslyCompletesAllWrites() throws Exception {
  LOGGER.info("Starting " + test.getTableNameString());
  LOGGER.info("Current thread is interrupted: " + Thread.interrupted());
  Abortable abort = new StubAbortable();
  Stoppable stop = Mockito.mock(Stoppable.class);
  ExecutorService exec = Executors.newFixedThreadPool(1);
  Map<ImmutableBytesPtr, Table> tables =
      new LinkedHashMap<ImmutableBytesPtr, Table>();
  FakeTableFactory factory = new FakeTableFactory(tables);
  RegionCoprocessorEnvironment e =Mockito.mock(RegionCoprocessorEnvironment.class);
  Configuration conf =new Configuration();
  Mockito.when(e.getConfiguration()).thenReturn(conf);
  Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
  Region mockRegion = Mockito.mock(Region.class);
  Mockito.when(e.getRegion()).thenReturn(mockRegion);
  TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
  Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
  Mockito.when(mockTableDesc.getTableName()).thenReturn(TableName.valueOf("test"));
  Connection mockConnection = Mockito.mock(Connection.class);
  Mockito.when(e.getConnection()).thenReturn(mockConnection);
  ImmutableBytesPtr tableName = new ImmutableBytesPtr(this.test.getTableName());
  Put m = new Put(row);
  m.addColumn(Bytes.toBytes("family"), Bytes.toBytes("qual"), null);
  Multimap<HTableInterfaceReference, Mutation> indexUpdates =
      ArrayListMultimap.<HTableInterfaceReference, Mutation> create();
  indexUpdates.put(new HTableInterfaceReference(tableName), m);

  Table table = Mockito.mock(Table.class);
  final boolean[] completed = new boolean[] { false };
  Mockito.doAnswer(new Answer<Void>() {

    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      // just keep track that it was called
      completed[0] = true;
      return null;
    }
  }).when(table).batch(Mockito.anyList(),Mockito.any());
  Mockito.when(table.getName()).thenReturn(org.apache.hadoop.hbase.TableName.valueOf(test.getTableName()));
  // add the table to the set of tables, so its returned to the writer
  tables.put(tableName, table);

  // setup the writer and failure policy
  TrackingParallelWriterIndexCommitter writer = new TrackingParallelWriterIndexCommitter(VersionInfo.getVersion());
  writer.setup(factory, exec, stop, e);
  writer.write(indexUpdates, true, ScanUtil.UNKNOWN_CLIENT_VERSION);
  assertTrue("Writer returned before the table batch completed! Likely a race condition tripped",
    completed[0]);
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
}
 
源代码20 项目: onos   文件: FlowObjectiveService.java
/**
 * Returns all next objective that are waiting for the completion of previous objective
 * with the same NextObjQueueKey.
 *
 * @return Next objective queue as map
 */
default ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
    return ArrayListMultimap.create();
}