本文整理汇总了Java中com.google.common.collect.TreeMultimap.create方法的典型用法代码示例。如果您正苦于以下问题:Java TreeMultimap.create方法的具体用法?Java TreeMultimap.create怎么用?Java TreeMultimap.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.TreeMultimap
的用法示例。
在下文中一共展示了TreeMultimap.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
public ColumnFilter build()
{
boolean isFetchAll = metadata != null;
PartitionColumns queried = queriedBuilder == null ? null : queriedBuilder.build();
// It's only ok to have queried == null in ColumnFilter if isFetchAll. So deal with the case of a selectionBuilder
// with nothing selected (we can at least happen on some backward compatible queries - CASSANDRA-10471).
if (!isFetchAll && queried == null)
queried = PartitionColumns.NONE;
SortedSetMultimap<ColumnIdentifier, ColumnSubselection> s = null;
if (subSelections != null)
{
s = TreeMultimap.create(Comparator.<ColumnIdentifier>naturalOrder(), Comparator.<ColumnSubselection>naturalOrder());
for (ColumnSubselection subSelection : subSelections)
s.put(subSelection.column().name, subSelection);
}
return new ColumnFilter(isFetchAll, metadata, queried, s);
}
示例2: testSelfDataOrdered
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
/**
* 测试 TreeMultimap,自定义数据结构的排序
*/
@Test
public void testSelfDataOrdered() {
// 创建TreeMultimap,使用Ordering.natural()指定自然排序,Ordering.from指定排序规则
// Order4TreeMultimap::compareTo 是lambda的简写形式
TreeMultimap<String, Order4TreeMultimap> treeMultimap = TreeMultimap
.create(Ordering.natural(),
Ordering.from(Order4TreeMultimap::compareTo));
// 列表2
treeMultimap.put("order_list1", new Order4TreeMultimap(1, "haha1"));
treeMultimap.put("order_list1", new Order4TreeMultimap(5, "haha2"));
treeMultimap.put("order_list1", new Order4TreeMultimap(9, "haha3"));
treeMultimap.put("order_list1", new Order4TreeMultimap(10, "haha3"));
treeMultimap.put("order_list1", new Order4TreeMultimap(22, "haha4"));
treeMultimap.put("order_list1", new Order4TreeMultimap(444, "haha5"));
// 列表2
treeMultimap.put("order_list2", new Order4TreeMultimap(1, "haha3"));
treeMultimap.put("order_list2", new Order4TreeMultimap(3, "haha4"));
treeMultimap.put("order_list3", new Order4TreeMultimap(2, "haha5"));
// 输出
treeMultimap.forEach((key, order) -> System.out.println("key=" + key + ",order=" + order));
}
示例3: identifyDuplicates
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private void identifyDuplicates(List<ModContainer> mods)
{
TreeMultimap<ModContainer, File> dupsearch = TreeMultimap.create(new ModIdComparator(), Ordering.arbitrary());
for (ModContainer mc : mods)
{
if (mc.getSource() != null)
{
dupsearch.put(mc, mc.getSource());
}
}
ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
for (Entry<ModContainer> e : duplist.entrySet())
{
if (e.getCount() > 1)
{
FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(), dupsearch.get(e.getElement()));
dupes.putAll(e.getElement(),dupsearch.get(e.getElement()));
}
}
if (!dupes.isEmpty())
{
throw new DuplicateModsFoundException(dupes);
}
}
示例4: alternateNames
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private static TreeMultimap<Integer, AlternateName> alternateNames(String path) {
Stopwatch stopwatch = Stopwatch.createStarted();
TreeMultimap<Integer, AlternateName> multimap = TreeMultimap.create();
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
for (String line = br.readLine(); line != null; line = br.readLine()) {
List<String> list = Splitter.on('\t').splitToList(line);
if ("fr".equals(list.get(2))) {
AlternateName name = new AlternateName(list.get(3), "1".equals(list.get(4)), "1".equals(list.get(5)), "1".equals(list.get(6)), "1".equals(list.get(7)));
multimap.put(parseInt(list.get(1)), name);
}
}
}
catch (IOException e) {
throw propagate(e);
}
log.info("Alternate names loaded: {}s", stopwatch.elapsed(SECONDS));
return multimap;
}
示例5: spFile
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private static Multimap<Long, SignPostPath> spFile(TomtomFolder folder) {
File file = new File(folder.getFile("sp.dbf"));
Multimap<Long, SignPostPath> result = TreeMultimap.create();
if (!file.exists()) {
return result;
}
log.info("Reading SP {}", file);
try (DbfReader reader = new DbfReader(file)) {
DbfRow row;
while ((row = reader.nextRow()) != null) {
SignPostPath path = SignPostPath.fromRow(row);
result.put(path.getId(), path);
}
}
log.info("Loaded {} sign paths", result.size());
return result;
}
示例6: loadSpeedProfiles
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private static Map<Integer, PrecomputeSpeedProfile> loadSpeedProfiles(String filename) {
File file = new File(filename);
if (!file.exists()) {
log.info("File not found : {}", file.getAbsolutePath());
return newHashMap();
}
TreeMultimap<Integer, SpeedProfile> profilesMap = TreeMultimap.create();
log.info("Reading HSPR {}", file);
try (DbfReader reader = new DbfReader(file)) {
DbfRow row;
while ((row = reader.nextRow()) != null) {
SpeedProfile profile = new SpeedProfile(row.getInt("PROFILE_ID"), row.getInt("TIME_SLOT"), row.getDouble("REL_SP"));
profilesMap.put(profile.getId(), profile);
}
}
log.info("Loaded {} hspr", profilesMap.size());
return profilesMap.asMap().entrySet().stream().collect(toMap(Entry::getKey, e -> precomputeProfile(e.getValue())));
}
示例7: calcCoverage
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
/**
* Generates a coverage multimap from split key to Regions that start with the
* split key.
*
* @return coverage multimap
*/
public Multimap<byte[], R> calcCoverage() {
// This needs to be sorted to force the use of the comparator on the values,
// otherwise byte array comparison isn't used
Multimap<byte[], R> regions = TreeMultimap.create(BYTES_COMPARATOR,
rangeCmp);
// march through all splits from the start points
for (Entry<byte[], Collection<R>> start : starts.asMap().entrySet()) {
byte[] key = start.getKey();
for (R r : start.getValue()) {
regions.put(key, r);
for (byte[] coveredSplit : splits.subSet(r.getStartKey(),
specialEndKey(r))) {
regions.put(coveredSplit, r);
}
}
}
return regions;
}
示例8: testCreate
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
/**
* 基本数据类型的排序
*/
@Test
public void testCreate() {
TreeMultimap<String, Integer> treeMultimap = TreeMultimap.create();
treeMultimap.put("list_1", 1);
treeMultimap.put("list_1", 1);
treeMultimap.put("list_1", 2);
treeMultimap.put("list_1", 9);
treeMultimap.put("list_1", 7);
treeMultimap.put("list_1", 3);
treeMultimap.put("list_2", 9);
treeMultimap.put("list_2", 7);
// {list_1=[1, 2, 3, 7, 9], list_2=[7, 9]}
System.out.println(treeMultimap);
}
示例9: indexSolutionGeneratorsOld
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
/**
* Repartition subsequent partitions while the predicate is true
*
* This unifies three common use cases:
* - k = 0 : Do not repartition at all
* - k = 1 : Repartition the next largest equivalence class
* - k = null: Repartition all equivalence classes
*
*/
// public static <N, M> Entry<? extends Collection<M>, ? extends Collection<M>>
// nextEquivClassRepartitionK(TreeMultimap<K, V> equivClasses, BiPredicate<Integer, Entry<? extends Collection<M>, ? extends Collection<M>>>) {
// return null;
// }
//
public static <S> TreeMultimap<Long, Problem<S>> indexSolutionGeneratorsOld(Collection<Problem<S>> solGens) {
TreeMultimap<Long, Problem<S>> result = TreeMultimap.create();
for(Problem<S> solutionGenerator : solGens) {
long size = solutionGenerator.getEstimatedCost();
result.put(size, solutionGenerator);
}
return result;
}
示例10: decodeRecords
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
/**
* Decodes a list of MX records into a tree map, ranking them automatically.
*
* @param records The list of MX records.
* @return The tree map containing ranked MX records.
*/
private TreeMultimap<Integer, String> decodeRecords(List<Record> records) {
TreeMultimap<Integer, String> recordMap = TreeMultimap.create(Ordering.natural(), Ordering.natural());
records.forEach(record -> {
String[] split = record.rdataToString().split(" ");
if (split.length >= 2) {
try {
int rank = Integer.parseInt(split[0]);
String domain = split[1];
recordMap.put(rank, domain);
} catch (NumberFormatException ex) {
ex.printStackTrace();
}
}
});
return recordMap;
}
示例11: getDomainApplicationMap
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
/** Return a map of all fully-qualified domain names mapped to the applications for that name. */
private static Multimap<String, DomainApplication> getDomainApplicationMap(final String tld) {
DateTime now = DateTime.now(UTC);
Multimap<String, DomainApplication> domainApplicationMap =
TreeMultimap.create(Ordering.natural(), comparing(DomainApplication::getForeignKey));
Iterable<DomainApplication> domainApplications =
ofy().load().type(DomainApplication.class).filter("tld", tld);
for (DomainApplication domainApplication : domainApplications) {
// Ignore deleted and rejected applications. They aren't under consideration.
ApplicationStatus applicationStatus = domainApplication.getApplicationStatus();
DateTime deletionTime = domainApplication.getDeletionTime();
if (applicationStatus == REJECTED || isAtOrAfter(now, deletionTime)) {
continue;
}
boolean result = domainApplicationMap.put(
domainApplication.getFullyQualifiedDomainName(), domainApplication);
checkState(result, "Domain application not added to map: %s", domainApplication);
}
return domainApplicationMap;
}
示例12: build
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private IndexToIndexMultiMap build() throws IOException {
final TreeMultimap<Integer, Integer> elements = TreeMultimap.create();
for (int i = 0; i < DOCS; i++) {
elements.put(i / 2, i);
}
final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap mutable =
new com.yandex.yoctodb.util.mutable.impl.BitSetIndexToIndexMultiMap(
elements.asMap().values(),
DOCS);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
mutable.writeTo(baos);
final Buffer buf = Buffer.from(baos.toByteArray());
assertEquals(
V1DatabaseFormat.MultiMapType.LONG_ARRAY_BIT_SET_BASED.getCode(),
buf.getInt());
final IndexToIndexMultiMap result =
BitSetIndexToIndexMultiMap.from(buf);
assertEquals(DOCS / 2, result.getKeysCount());
return result;
}
示例13: buildBitSet
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
@Test
public void buildBitSet() throws IOException {
final TreeMultimap<Integer, Integer> elements = TreeMultimap.create();
for (int i = 0; i < DOCS; i++) {
elements.put(i / 2, i);
}
final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap mutable =
new com.yandex.yoctodb.util.mutable.impl.BitSetIndexToIndexMultiMap(
elements.asMap().values(),
DOCS);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
mutable.writeTo(baos);
final Buffer buf = Buffer.from(baos.toByteArray());
final IndexToIndexMultiMap result =
IndexToIndexMultiMapReader.from(buf);
assertTrue(result instanceof BitSetIndexToIndexMultiMap);
}
示例14: build
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private IndexToIndexMultiMap build() throws IOException {
final TreeMultimap<Integer, Integer> elements = TreeMultimap.create();
for (int i = 0; i < VALUES; i++) {
elements.put(i / 2, i);
}
final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap mutable =
new com.yandex.yoctodb.util.mutable.impl.IntIndexToIndexMultiMap(
elements.asMap().values());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
mutable.writeTo(baos);
final Buffer buf = Buffer.from(baos.toByteArray());
assertEquals(
V1DatabaseFormat.MultiMapType.LIST_BASED.getCode(),
buf.getInt());
final IndexToIndexMultiMap result =
IntIndexToIndexMultiMap.from(buf);
assertEquals(VALUES / 2, result.getKeysCount());
return result;
}
示例15: prepareData
import com.google.common.collect.TreeMultimap; //导入方法依赖的package包/类
private Buffer prepareData(
final int keys,
final int values) throws IOException {
final TreeMultimap<Integer, Integer> elements = TreeMultimap.create();
for (int i = 0; i < keys; i++) {
//same elements
elements.put(i, (keys - i) % values);
elements.put(i, (keys - i) % values);
elements.put(i, (keys - i) % values);
elements.put(i, (keys - i) % values);
elements.put(i, (2 * keys - i) % values);
elements.put(i, (3 * keys - i) % values);
}
final com.yandex.yoctodb.util.mutable.IndexToIndexMultiMap indexToIndexMultiMap =
new com.yandex.yoctodb.util.mutable.impl.IntIndexToIndexMultiMap(
elements.asMap().values());
final ByteArrayOutputStream os = new ByteArrayOutputStream();
indexToIndexMultiMap.writeTo(os);
Assert.assertEquals(os.size(), indexToIndexMultiMap.getSizeInBytes());
return Buffer.from(os.toByteArray());
}