本文整理匯總了Java中com.google.common.collect.TreeMultimap.put方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeMultimap.put方法的具體用法?Java TreeMultimap.put怎麽用?Java TreeMultimap.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.TreeMultimap
的用法示例。
在下文中一共展示了TreeMultimap.put方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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())));
}
示例3: tag
import com.google.common.collect.TreeMultimap; //導入方法依賴的package包/類
public Map<String, String> tag(Feature feature) {
TreeMultimap<String, Integer> speeds = TreeMultimap.create();
List<SpeedRestriction> restrictions = dbf.getSpeedRestrictions(feature.getLong("ID"));
boolean reversed = isReversed(feature);
for (SpeedRestriction restriction : restrictions) {
switch (restriction.getValidity()) {
case positive:
speeds.put(reversed ? "maxspeed:backward" : "maxspeed:forward", restriction.getSpeed());
break;
case negative:
speeds.put(reversed ? "maxspeed:forward" : "maxspeed:backward", restriction.getSpeed());
break;
case both:
speeds.put("maxspeed", restriction.getSpeed());
break;
}
}
Map<String, String> result = Maps.newHashMap();
for (String key : speeds.keySet()) {
result.put(key, String.valueOf(speeds.get(key).iterator().next()));
}
return result;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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));
}
示例7: 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);
}
}
示例8: 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;
}
示例9: buildInt
import com.google.common.collect.TreeMultimap; //導入方法依賴的package包/類
@Test
public void buildInt() 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.IntIndexToIndexMultiMap(
elements.asMap().values());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
mutable.writeTo(baos);
final Buffer buf = Buffer.from(baos.toByteArray());
final IndexToIndexMultiMap result =
IndexToIndexMultiMapReader.from(buf);
assertTrue(result instanceof IntIndexToIndexMultiMap);
}
示例10: 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);
}
示例11: 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;
}
示例12: 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());
}
示例13: string
import com.google.common.collect.TreeMultimap; //導入方法依賴的package包/類
@Test
public void string() {
final TreeMultimap<Integer, Integer> elements = TreeMultimap.create();
final int documents = 10;
for (int i = 0; i < documents; i++)
elements.put(i / 2, i);
final IndexToIndexMultiMap set =
new BitSetIndexToIndexMultiMap(
elements.asMap().values(),
documents);
final String text = set.toString();
assertTrue(text.contains(Integer.toString(documents / 2)));
assertTrue(text.contains(Integer.toString(documents)));
set.getSizeInBytes();
assertTrue(text.contains(Integer.toString(documents / 2)));
assertTrue(text.contains(Integer.toString(documents)));
}
示例14: forkByClassifier
import com.google.common.collect.TreeMultimap; //導入方法依賴的package包/類
private Map<String, TreeMultimap<Calendar, ItemInfo>> forkByClassifier(
TreeMultimap<Calendar, ItemInfo> cleanupCandidates) {
Map<String, TreeMultimap<Calendar, ItemInfo>> result= Maps.newHashMap();
for (Calendar calendar : cleanupCandidates.keySet()) {
NavigableSet<ItemInfo> itemInfos = cleanupCandidates.get(calendar);
for (ItemInfo itemInfo : itemInfos) {
String classifier=resolveClassifier(itemInfo);
TreeMultimap<Calendar, ItemInfo> classifierMap = result.get(classifier);
if(classifierMap==null){
//classifierMap= TreeMultimap.create(Ordering.natural().reverse(), Ordering.natural().reverse());
classifierMap= TreeMultimap.create(Ordering.natural(), Ordering.natural());;
result.put(classifier,classifierMap);
}
classifierMap.put(calendar,itemInfo);
}
}
return result;
}
示例15: findCandidatesFor
import com.google.common.collect.TreeMultimap; //導入方法依賴的package包/類
private TreeMultimap<String, MatchCandidate> findCandidatesFor(Map<String, Field> fields) throws StageException {
TreeMultimap<String, MatchCandidate> candidates = TreeMultimap.create();
for (String outputField : outputFieldNames) {
for (Map.Entry<String, Field> entry : fields.entrySet()) {
String fieldPath = entry.getKey();
Field field = entry.getValue();
int score = FuzzyMatch.getRatio(outputField, fieldPath, true);
if (score >= matchThreshold) {
if (greaterScore(candidates.get(outputField), score) || allCandidates) {
if (!allCandidates) {
// If not storing all candidates we must clear any existing candidates for this key
// since a Multimap won't replace multiple values for a key.
candidates.get(outputField).clear();
}
candidates.put(outputField, new MatchCandidate(outputField, score, fieldPath, field));
}
}
}
}
return candidates;
}