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

The following examples show how to use com.google.common.collect.ArrayListMultimap#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: MetricMappingPipeline.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: ExecutionQueueServiceTest.java    From score with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: Py4jDictionary.java    From py4j with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: FpmlDocument.java    From Strata with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: ExternalAnnotationRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: WorldRetrogen.java    From simpleretrogen with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: DomainDomainEventPublisherImplTest.java    From business with Mozilla Public License 2.0 5 votes vote down vote up
@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());
}
 
Example 8
Source File: Yago3EntitiesWikidataCategoryDataProvider.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: SaltErrorResolver.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: DimensionsEntityTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 11
Source File: YangXmlUtils.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: MergedResourceWriter.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(@NonNull DocumentBuilderFactory factory) throws ConsumerException {
    super.start(factory);
    mValuesResMap = ArrayListMultimap.create();
    mQualifierWithDeletedValues = Sets.newHashSet();
    mFactory = factory;
}
 
Example 13
Source File: TabPanelCooking.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
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();

}
 
Example 14
Source File: ExtractProtobufPathsBuilder.java    From kite with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 15
Source File: EventSlice.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public EventSlice() {
  this.start = -1;
  this.end = -1;
  this.filters = ArrayListMultimap.create();
}
 
Example 16
Source File: RH2Lev.java    From Clusion with GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example 17
Source File: SampleUtils.java    From tassal with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: TestParalleIndexWriter.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 19
Source File: VirtualIntentInstallCoordinator.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    });
}
 
Example 20
Source File: FlowObjectiveService.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}