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

The following examples show how to use com.google.common.collect.ListMultimap#asMap() . 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: MethodHierarchyReader.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@link ListMultimap#asMap multimap.asMap()}, with its type
 * corrected from {@code Map<K, Collection<V>>} to {@code Map<K, List<V>>}.
 */
// Copied from com.google.common.collect.Multimaps.  We can't use the actual method from
// that class as appengine build magic gives us an older version of guava that doesn't yet have
// this method.
// TODO: Switch to Multimaps.asMap() once it becomes available in appengine.
@SuppressWarnings("unchecked")
// safe by specification of ListMultimap.asMap()
private static <K, V> Map<K, List<V>> asMap(ListMultimap<K, V> multimap) {
  return (Map<K, List<V>>) (Map<K, ?>) multimap.asMap();
}
 
Example 2
Source File: NeuralNetworkEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<FieldName, List<NeuralOutput>> parseNeuralOutputs(){
	NeuralNetwork neuralNetwork = getModel();

	ListMultimap<FieldName, NeuralOutput> result = ArrayListMultimap.create();

	NeuralOutputs neuralOutputs = neuralNetwork.getNeuralOutputs();
	for(NeuralOutput neuralOutput : neuralOutputs){
		FieldName name;

		Expression expression = getOutputExpression(neuralOutput);

		if(expression instanceof HasFieldReference){
			HasFieldReference<?> hasFieldReference = (HasFieldReference<?>)expression;

			name = hasFieldReference.getField();
			if(name == null){
				throw new MissingAttributeException(MissingAttributeException.formatMessage(XPathUtil.formatElement((Class)hasFieldReference.getClass()) + "@field"), expression);
			}
		} else

		{
			throw new MisplacedElementException(expression);
		}

		result.put(name, neuralOutput);
	}

	return (Map)result.asMap();
}
 
Example 3
Source File: MiningModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
static
private Map<FieldName, ?> selectAll(List<SegmentResult> segmentResults){
	ListMultimap<FieldName, Object> result = ArrayListMultimap.create();

	Set<FieldName> keys = null;

	for(SegmentResult segmentResult : segmentResults){

		if(keys == null){
			keys = new LinkedHashSet<>(segmentResult.keySet());
		} // End if

		// Ensure that all List values in the ListMultimap contain the same number of elements
		if(!(keys).equals(segmentResult.keySet())){
			Function<Object, String> function = new Function<Object, String>(){

				@Override
				public String apply(Object object){
					return PMMLException.formatKey(object);
				}
			};

			throw new EvaluationException("Field sets " + Iterables.transform(keys, function) + " and " + Iterables.transform(segmentResult.keySet(), function) + " do not match");
		}

		for(FieldName key : keys){
			result.put(key, segmentResult.get(key));
		}
	}

	return result.asMap();
}
 
Example 4
Source File: GeneralRegressionModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings (
	value = {"rawtypes", "unchecked"}
)
static
private <K, C extends ParameterCell> Map<K, List<C>> asMap(ListMultimap<K, C> multimap){
	return (Map)multimap.asMap();
}
 
Example 5
Source File: ExtractJsonPathsBuilder.java    From kite with Apache License 2.0 5 votes vote down vote up
public ExtractJsonPaths(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);
  ListMultimap<String, String> stepMultiMap = ArrayListMultimap.create();
  this.flatten = getConfigs().getBoolean(config, "flatten", true);
  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 6
Source File: ExtractAvroPathsBuilder.java    From kite with Apache License 2.0 5 votes vote down vote up
public ExtractAvroPaths(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);
  ListMultimap<String, String> stepMultiMap = ArrayListMultimap.create();
  this.flatten = getConfigs().getBoolean(config, "flatten", true);
  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 7
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();
}