Java Code Examples for com.google.common.collect.ListMultimap#size()

The following examples show how to use com.google.common.collect.ListMultimap#size() . 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: ListMultimapParser.java    From caravan with Apache License 2.0 6 votes vote down vote up
@Override
public ListMultimap<String, String> parse(String value) {
    if (StringValues.isNullOrWhitespace(value))
        return null;

    value = value.trim();
    ListMultimap<String, String> listMultimap = ArrayListMultimap.create();
    String[] pairValues = value.trim().split(";");
    for (String pairValue : pairValues) {
        KeyValuePair<String, String> pair = StringValues.toKeyValuePair(pairValue);
        if (pair == null)
            continue;

        String[] values = pair.getValue().split(",");
        for (String item : values) {
            if (StringValues.isNullOrWhitespace(item))
                continue;

            listMultimap.put(pair.getKey(), item.trim());
        }
    }

    return listMultimap.size() == 0 ? null : listMultimap;
}
 
Example 2
Source File: ServiceCluster.java    From artemis with Apache License 2.0 6 votes vote down vote up
protected void updateClusterNodes() {
    ListMultimap<String, String> zoneIdNodeUrlsMap = _clusterNodesProperty.typedValue();
    _logger.info("ClusterNodes setting raw value: " + _clusterNodesProperty.value() + ", typedValue: "
            + zoneIdNodeUrlsMap);
    ListMultimap<Zone, ServiceNode> clusterNodes = ArrayListMultimap.create();
    for (String zoneId : zoneIdNodeUrlsMap.keySet()) {
        Zone zone = new Zone(_regionId, zoneId);
        for (String serviceUrl : zoneIdNodeUrlsMap.get(zoneId)) {
            if (StringValues.isNullOrWhitespace(serviceUrl))
                continue;
            ServiceNode peerNode = new ServiceNode(zone, serviceUrl);
            clusterNodes.put(zone, peerNode);
        }
    }

    if (clusterNodes.size() == 0) {
        _logger.warn("New ClusterNodes is empty. Skip to update");
        return;
    }

    _logger.info("ClusterNodes is updated. from: " + _clusterNodes + ", to: " + clusterNodes);
    _clusterNodes = clusterNodes;
}
 
Example 3
Source File: NYTEntitySalienceFeatureExtractor.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
@Override
public List<EntityInstance> getEntityInstances(JCas jCas, TrainingSettings.FeatureExtractor featureExtractor) throws Exception {
  Collection<AidaEntity> aidaEntities = JCasUtil.select(jCas, AidaEntity.class);
  ListMultimap<String, AidaEntity> entitiesMentions = ArrayListMultimap.create();

  // Group by actual entity (uima.Entity is a mention).
  for (AidaEntity aidaEntity : aidaEntities) {
    entitiesMentions.put(aidaEntity.getID(), aidaEntity);
  }

  Logger logger = LoggerFactory.getLogger(NYTEntitySalienceFeatureExtractor.class);
  String docId = JCasUtil.selectSingle(jCas, DocumentMetaData.class).getDocumentId();
  logger.debug("[" + docId + "] AIDA entities: " + entitiesMentions.keySet());

  List<EntityInstance> entityInstances = new ArrayList<>(entitiesMentions.size());

  // Extract features for entities.
  for (Map.Entry<String, Collection<AidaEntity>> entry : entitiesMentions.asMap().entrySet()) {
    String entityId = entry.getKey();
    Collection<AidaEntity> entityMentions = entry.getValue();

    // Generate feature 8.
    Map<Integer, Double> entityFeatureValues = getEntityFeatureValues(jCas, entityMentions, featureExtractor);
    EntityInstance ei = new EntityInstance(entityId, entityFeatureValues);
    entityInstances.add(ei);
  }

  return entityInstances;
}
 
Example 4
Source File: AmberPersistence.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
void persistSnpCheck(@NotNull final ListMultimap<Chromosome, BaseDepth> baseDepths) {
    if (baseDepths.size() > 0) {
        final String outputVcf = config.outputDirectory() + File.separator + config.reference().get(0) + ".amber.snp.vcf.gz";
        LOGGER.info("Writing {} germline snp records to {}", baseDepths.size(), outputVcf);
        new AmberVCF(config).writeSNPCheck(outputVcf, Lists.newArrayList(baseDepths.values()));
    }
}
 
Example 5
Source File: ShuffleScheduler.java    From tez with Apache License 2.0 4 votes vote down vote up
public synchronized List<InputAttemptIdentifier> getMapsForHost(MapHost host) {
  List<InputAttemptIdentifier> origList = host.getAndClearKnownMaps();

  ListMultimap<Integer, InputAttemptIdentifier> dedupedList = LinkedListMultimap.create();

  Iterator<InputAttemptIdentifier> listItr = origList.iterator();
  while (listItr.hasNext()) {
    // we may want to try all versions of the input but with current retry
    // behavior older ones are likely to be lost and should be ignored.
    // This may be removed after TEZ-914
    InputAttemptIdentifier id = listItr.next();
    if (inputShouldBeConsumed(id)) {
      Integer inputNumber = Integer.valueOf(id.getInputIdentifier());
      List<InputAttemptIdentifier> oldIdList = dedupedList.get(inputNumber);

      if (oldIdList == null || oldIdList.isEmpty()) {
        dedupedList.put(inputNumber, id);
        continue;
      }

      //In case of pipelined shuffle, we can have multiple spills. In such cases, we can have
      // more than one item in the oldIdList.
      boolean addIdentifierToList = false;
      Iterator<InputAttemptIdentifier> oldIdIterator = oldIdList.iterator();
      while(oldIdIterator.hasNext()) {
        InputAttemptIdentifier oldId = oldIdIterator.next();

        //no need to add if spill ids are same
        if (id.canRetrieveInputInChunks()) {
          if (oldId.getSpillEventId() == id.getSpillEventId()) {
            //TODO: need to handle deterministic spills later.
            addIdentifierToList = false;
            continue;
          } else if (oldId.getAttemptNumber() == id.getAttemptNumber()) {
            //but with different spill id.
            addIdentifierToList = true;
            break;
          }
        }

        //if its from different attempt, take the latest attempt
        if (oldId.getAttemptNumber() < id.getAttemptNumber()) {
          //remove existing identifier
          oldIdIterator.remove();
          LOG.warn("Old Src for InputIndex: " + inputNumber + " with attemptNumber: "
              + oldId.getAttemptNumber()
              + " was not determined to be invalid. Ignoring it for now in favour of "
              + id.getAttemptNumber());
          addIdentifierToList = true;
          break;
        }
      }
      if (addIdentifierToList) {
        dedupedList.put(inputNumber, id);
      }
    } else {
      LOG.info("Ignoring finished or obsolete source: " + id);
    }
  }

  // Compute the final list, limited by NUM_FETCHERS_AT_ONCE
  List<InputAttemptIdentifier> result = new ArrayList<InputAttemptIdentifier>();
  int includedMaps = 0;
  int totalSize = dedupedList.size();

  for(Integer inputIndex : dedupedList.keySet()) {
    List<InputAttemptIdentifier> attemptIdentifiers = dedupedList.get(inputIndex);
    for (InputAttemptIdentifier inputAttemptIdentifier : attemptIdentifiers) {
      if (includedMaps++ >= maxTaskOutputAtOnce) {
        host.addKnownMap(inputAttemptIdentifier);
      } else {
        if (inputAttemptIdentifier.canRetrieveInputInChunks()) {
          ShuffleEventInfo shuffleEventInfo =
              pipelinedShuffleInfoEventsMap.get(inputAttemptIdentifier.getInputIdentifier());
          if (shuffleEventInfo != null) {
            shuffleEventInfo.scheduledForDownload = true;
          }
        }
        result.add(inputAttemptIdentifier);
      }
    }
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("assigned " + includedMaps + " of " + totalSize + " to " +
        host + " to " + Thread.currentThread().getName());
  }
  return result;
}
 
Example 6
Source File: ModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 3 votes vote down vote up
protected int getNumberOfVisibleFields(){

		if(this.numberOfVisibleFields == null){
			ListMultimap<FieldName, Field<?>> visibleFields = getVisibleFields();

			this.numberOfVisibleFields = visibleFields.size();
		}

		return this.numberOfVisibleFields;
	}