当前位置: 首页>>代码示例>>Java>>正文


Java ImmutableMultimap类代码示例

本文整理汇总了Java中com.google.common.collect.ImmutableMultimap的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMultimap类的具体用法?Java ImmutableMultimap怎么用?Java ImmutableMultimap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ImmutableMultimap类属于com.google.common.collect包,在下文中一共展示了ImmutableMultimap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: use

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
default void use() {
  ImmutableExtraCollection.of(
      ImmutableList.<String>of(),
      ImmutableMultimap.<Integer, String>of(),
      ImmutableMultimap.<Integer, String>of(),
      ImmutableMultimap.<Integer, String>of(),
      ImmutableBiMap.<Integer, String>of());
  ImmutableExtraCollection.of();
  ImmutableExtraCollection collection = ImmutableExtraCollection.builder()
      .addBag("2", "2")
      .putIndex(1, "2", "3", "4")
      .putAllIndex(1, Arrays.asList("2", "3", "4"))
      .putIndex(2, "5")
      .putIndexList(1, "")
      .putIndexSet(2, "2")
      .putAllIndexSet(2, Arrays.asList("3", "4"))
      .putBiMap(1, "a")
      .putBiMap(2, "b")
      .putAllBiMap(Collections.singletonMap(3, "c"))
      .build();

  collection.bag().count("2");
  collection.index().get(1);
  collection.indexList().get(1);
  collection.indexSet().get(2);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:ExtraCollection.java

示例2: flatten

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public static <K,V> ImmutableList<ImmutableMap<K, V>> flatten(ImmutableMultimap<K, V> src) {
	ImmutableList.Builder<ImmutableMap<K, V>> listBuilder=ImmutableList.builder();
	
	if (!src.isEmpty()) {
		ImmutableMap<K, Collection<V>> map = src.asMap();
		int entries=map.values().stream().reduce(1, (s,l) -> s*l.size(), (a,b) -> a*b);
		
		ImmutableList<Line<K,V>> lines = map.entrySet().stream()
				.map(e -> new Line<>(e.getKey(), e.getValue()))
				.collect(ImmutableList.toImmutableList());
		
		for (int i=0;i<entries;i++) {
			ImmutableMap.Builder<K, V> mapBuilder = ImmutableMap.builder();
			
			int fact=1;
			for (Line<K,V> line: lines) {
				mapBuilder.put(line.key, line.get((i/fact) % line.values.length));
				fact=fact*line.values.length;
			}
			
			listBuilder.add(mapBuilder.build());
		}
	}
	return listBuilder.build();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:26,代码来源:Multimaps.java

示例3: apply

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
@Override
public Multimap<Character, Map.Entry<String, ValueAttribute>> apply(Iterable<ValueAttribute> attributes) {
  ImmutableMultimap.Builder<Character, Map.Entry<String, ValueAttribute>> builder = ImmutableMultimap.builder();

  for (ValueAttribute attribute : attributes) {
    String serializedName = attribute.getMarshaledName();
    builder.put(serializedName.charAt(0), Maps.immutableEntry(serializedName, attribute));

    for (String alternateName : attribute.getAlternateSerializedNames()) {
      if (!alternateName.isEmpty()) {
        builder.put(alternateName.charAt(0), Maps.immutableEntry(alternateName, attribute));
      }
    }
  }

  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:Gsons.java

示例4: testOf

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
@Test public void testOf() {
  assertKeyValues(BiStream.of("one", 1))
      .containsExactlyEntriesIn(ImmutableMultimap.of("one", 1))
      .inOrder();
  assertKeyValues(BiStream.of("one", 1, "two", 2))
      .containsExactlyEntriesIn(ImmutableMultimap.of("one", 1, "two", 2))
      .inOrder();
  assertKeyValues(BiStream.of("one", 1, "two", 2, "three", 3))
      .containsExactlyEntriesIn(ImmutableMultimap.of("one", 1, "two", 2, "three", 3))
      .inOrder();
  assertKeyValues(BiStream.of("one", 1, "two", 2, "three", 3, "four", 4))
      .containsExactlyEntriesIn(ImmutableMultimap.of(
          "one", 1, "two", 2, "three", 3, "four", 4))
      .inOrder();
  assertKeyValues(BiStream.of("one", 1, "two", 2, "three", 3, "four", 4, "five", 5))
      .containsExactlyEntriesIn(ImmutableMultimap.of(
          "one", 1, "two", 2, "three", 3, "four", 4, "five", 5))
      .inOrder();
}
 
开发者ID:google,项目名称:mug,代码行数:20,代码来源:BiStreamTest.java

示例5: pathPropertiesOfAsMultimap

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public static ImmutableMultimap<String, Object> pathPropertiesOfAsMultimap(Blob blob, Function<String, Collection<String>> pathPropertyMapping, Path path, PropertyCollectionResolver propertyResolver) {
	ImmutableList<String> pathProperties = path.propertyNamesWithoutPage();
	
	ImmutableMap<String, ImmutableSet<?>> blopPathPropertyMap = pathProperties.stream()
		.map(p -> Pair.<String, ImmutableSet<?>>of(p, propertyOf(blob, pathPropertyMapping, propertyResolver, p)))
		.filter(pair -> !pair.b().isEmpty())
		.collect(ImmutableMap.toImmutableMap(Pair::a, Pair::b));
	
	if (blopPathPropertyMap.keySet().size()<pathProperties.size()) {
		return ImmutableMultimap.of();
	}
	
	Builder<String, Object> multiMapBuilder = ImmutableMultimap.builder();
	
	blopPathPropertyMap.forEach((key, values) -> {
		multiMapBuilder.putAll(key, values);
	});
	
	return multiMapBuilder.build();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:21,代码来源:Blobs.java

示例6: build

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public ImmutableGroupedPropertyMap build() {
	ImmutableMap.Builder<Key, ImmutableMap<String, Object>> mapOfMapsBuilder=ImmutableMap.builder();
	ImmutableMultimap.Builder<Key, String> groupOfKeyBuilder=ImmutableMultimap.builder();
	
	maps.forEach((key, map) -> {
		mapOfMapsBuilder.put(key, ImmutableMap.copyOf(map));
	});
	
	maps.keySet().forEach(key -> {
		Key current=key;
		while (!current.isRoot()) {
			Key parent = current.parent();
			groupOfKeyBuilder.put(parent, current.last());
			current=parent;
		}
	});
	
	return new ImmutableGroupedPropertyMap(mapOfMapsBuilder.build(), groupOfKeyBuilder.build());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:20,代码来源:ImmutableGroupedPropertyMap.java

示例7: toFMeasures

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
private ImmutableMultimap<String, FMeasureCounts> toFMeasures(
    Collection<BrokenDownSummaryConfusionMatrix<Symbol>> data,
    Map.Entry<String, Collection<Symbol>> FMeasureSymbol) {
  final ImmutableMultimap.Builder<String, FMeasureCounts> ret = ImmutableMultimap.builder();

    /*
     MapUtils.copyWithTransformedEntries(data.asMap(),
                        Functions.toStringFunction(), FmeasureVs(FMeasureSymbol.getValue()));
     */
  final Function<SummaryConfusionMatrix, FMeasureCounts> scoringFunction =
      FmeasureVs(ImmutableSet.copyOf(FMeasureSymbol.getValue()));
  for (final BrokenDownSummaryConfusionMatrix<Symbol> dataPoint : data) {
    for (final Map.Entry<Symbol, SummaryConfusionMatrix> entry : dataPoint.asMap().entrySet()) {
      ret.put(entry.getKey().toString(), scoringFunction.apply(entry.getValue()));
    }
  }

  return ret.build();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:20,代码来源:EAScoringObserver.java

示例8: execute

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
@Override
public void execute(final ImmutableMultimap<String, String> parameters, final PrintWriter output) throws Exception {

    LOGGER.info("{} endpoint called", TASK_NAME);

    @SuppressWarnings("FutureReturnValueIgnored")
    Future<Void> future = CompletableFuture
            .runAsync(statisticsIngestService::stop)
            .handle((aVoid, ex) -> {
                if (ex != null) {
                    LOGGER.error("Task {} failed with error {}", TASK_NAME, ex.getMessage(), ex);
                } else {
                    LOGGER.info("Task {} completed successfully", TASK_NAME);
                }
                return aVoid;
            });
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:18,代码来源:StopProcessingTask.java

示例9: of

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public static ImmutableList<Menu> of(ImmutableMultimap<ImmutableMap<String, Object>, Blob> groupedBlobs) {
	ImmutableList<BlobAndMenu> sortedBlobs = groupedBlobs.inverse().asMap()
			.entrySet()
			.stream()
			.filter(e -> !e.getValue().isEmpty())
			.map(e -> BlobAndMenu.of(e.getKey(), e.getValue().iterator().next()))
			.sorted((a,b) -> Long.compare(a.menu().weight(), b.menu().weight()))
			.collect(ImmutableList.toImmutableList());
	
	ImmutableList<BlobAndMenu> parents = sortedBlobs.stream()
			.filter(blobmenu -> !blobmenu.menu().parent().isPresent())
			.collect(ImmutableList.toImmutableList());
	
	return parents.stream()
		.map(parent -> asMenu(parent,sortedBlobs))
		.collect(ImmutableList.toImmutableList());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:18,代码来源:Menu.java

示例10: combine

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public static <K, V> Multimap<K, V> combine(Iterable<Multimap<K, V>> maps) {
    Multimap<K, V> singleton = null;
    ImmutableMultimap.Builder<K, V> builder = null;
    for(Multimap<K, V> map : maps) {
        if(!map.isEmpty()) {
            if(singleton == null) {
                singleton = map;
            } else {
                if(builder == null) {
                    builder = ImmutableMultimap.builder();
                }
                builder.putAll(singleton);
                builder.putAll(map);
            }
        }
    }

    if(builder != null) {
        return builder.build();
    } else if(singleton != null) {
        return singleton;
    } else {
        return ImmutableMultimap.of();
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:26,代码来源:MapUtils.java

示例11: groupingByValues

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public static <T, L, K> Collector<T, ?, ImmutableMultimap<K, T>> groupingByValues(Function<? super T, ? extends Iterable<? extends K>> classifier) {
	return ImmutableGenericCollector.<T, LinkedListMultimap<K, T>, ImmutableMultimap<K, T>>builder()
		.supplier(LinkedListMultimap::create)
		.accumulator((map, t) -> {
			classifier.apply(t).forEach(k -> {
				map.put(k, t);
			});
		})
		.combiner((a,b) -> {
			LinkedListMultimap<K, T> ret = LinkedListMultimap.create(a);
			ret.putAll(b);
			return ret;
		})
		.finisher(map -> ImmutableMultimap.copyOf(map))
		.build();
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:Collectors.java

示例12: getCollaboratorsForItemIds

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public Multimap<Long, String> getCollaboratorsForItemIds(Collection<Long> itemIds)
{
	if( itemIds.isEmpty() )
	{
		return ImmutableMultimap.of();
	}
	List<Object[]> attachments = getHibernateTemplate().findByNamedParam(
		"select c, i.id from Item i join i.collaborators c where i.id in (:items)", "items", itemIds);
	ListMultimap<Long, String> multiMap = ArrayListMultimap.create();
	for( Object[] attachmentRow : attachments )
	{
		multiMap.put((Long) attachmentRow[1], (String) attachmentRow[0]);
	}
	return multiMap;
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:ItemDaoImpl.java

示例13: getResultingSourceMapping

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public ImmutableMultimap<Integer, Record> getResultingSourceMapping(XmlDocument xmlDocument)
        throws ParserConfigurationException, SAXException, IOException {

    XmlLoader.SourceLocation inMemory = XmlLoader.UNKNOWN;

    XmlDocument loadedWithLineNumbers = XmlLoader.load(
            xmlDocument.getSelectors(),
            xmlDocument.getSystemPropertyResolver(),
            inMemory,
            xmlDocument.prettyPrint(),
            XmlDocument.Type.MAIN,
            Optional.<String>absent() /* mainManifestPackageName */);

    ImmutableMultimap.Builder<Integer, Record> mappingBuilder = ImmutableMultimap.builder();
    for (XmlElement xmlElement : loadedWithLineNumbers.getRootNode().getMergeableElements()) {
        parse(xmlElement, mappingBuilder);
    }
    return mappingBuilder.build();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:Actions.java

示例14: parse

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
private void parse(XmlElement element,
        ImmutableMultimap.Builder<Integer, Record> mappings) {
    DecisionTreeRecord decisionTreeRecord = mRecords.get(element.getId());
    if (decisionTreeRecord != null) {
        NodeRecord nodeRecord = findNodeRecord(decisionTreeRecord);
        if (nodeRecord != null) {
            mappings.put(element.getPosition().getLine(), nodeRecord);
        }
        for (XmlAttribute xmlAttribute : element.getAttributes()) {
            AttributeRecord attributeRecord = findAttributeRecord(decisionTreeRecord,
                    xmlAttribute);
            if (attributeRecord != null) {
                mappings.put(xmlAttribute.getPosition().getLine(), attributeRecord);
            }
        }
    }
    for (XmlElement xmlElement : element.getMergeableElements()) {
        parse(xmlElement, mappings);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:21,代码来源:Actions.java

示例15: blame

import com.google.common.collect.ImmutableMultimap; //导入依赖的package包/类
public String blame(XmlDocument xmlDocument)
        throws IOException, SAXException, ParserConfigurationException {

    ImmutableMultimap<Integer, Record> resultingSourceMapping =
            getResultingSourceMapping(xmlDocument);
    LineReader lineReader = new LineReader(
            new StringReader(xmlDocument.prettyPrint()));

    StringBuilder actualMappings = new StringBuilder();
    String line;
    int count = 1;
    while ((line = lineReader.readLine()) != null) {
        actualMappings.append(count).append(line).append("\n");
        if (resultingSourceMapping.containsKey(count)) {
            for (Record record : resultingSourceMapping.get(count)) {
                actualMappings.append(count).append("-->")
                        .append(record.getActionLocation().toString())
                        .append("\n");
            }
        }
        count++;
    }
    return actualMappings.toString();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:25,代码来源:Actions.java


注:本文中的com.google.common.collect.ImmutableMultimap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。