public void addTag(String name, String value) { tags.put(name, value); }
public void addTag(String name, String value) { m_tags.put(name, value); }
/** Create and populate a {@code TreeMultimap} with the natural ordering of keys and values. */ private TreeMultimap<String, Integer> createPopulate() { TreeMultimap<String, Integer> multimap = TreeMultimap.create(); multimap.put("google", 2); multimap.put("google", 6); multimap.put("foo", 3); multimap.put("foo", 1); multimap.put("foo", 7); multimap.put("tree", 4); multimap.put("tree", 0); return multimap; }
/** Create and populate a {@code TreeMultimap} with explicit comparators. */ private TreeMultimap<String, Integer> createPopulate() { TreeMultimap<String, Integer> multimap = TreeMultimap.create(StringLength.COMPARATOR, DECREASING_INT_COMPARATOR); multimap.put("google", 2); multimap.put("google", 6); multimap.put(null, 3); multimap.put(null, 1); multimap.put(null, 7); multimap.put("tree", 0); multimap.put("tree", null); return multimap; }
public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) { TreeMultimap<E, T> reorgnized = TreeMultimap.create(); while (input.hasNext()) { T t = input.next(); E e = extractor.apply(t); reorgnized.put(e, t); } return reorgnized.values().iterator(); } }
public void addTags(DataPointGroup dpGroup) { for (String key : dpGroup.getTagNames()) { for (String value : dpGroup.getTagValues(key)) { this.tags.put(key, value); } } }
public void testTailSetClear() { TreeMultimap<String, Integer> multimap = TreeMultimap.create(); multimap.put("a", 1); multimap.put("a", 11); multimap.put("b", 2); multimap.put("c", 3); multimap.put("d", 4); multimap.put("e", 5); multimap.put("e", 55); multimap.keySet().tailSet("d").clear(); assertEquals(ImmutableSet.of("a", "b", "c"), multimap.keySet()); assertEquals(4, multimap.size()); assertEquals(4, multimap.values().size()); assertEquals(4, multimap.keys().size()); }
@Override protected NavigableSet<String> create(String[] elements) { TreeMultimap<String, Integer> multimap = TreeMultimap.create(Ordering.natural().nullsFirst(), Ordering.natural()); for (int i = 0; i < elements.length; i++) { multimap.put(elements[i], i); } return multimap.keySet(); }
/** * Appends the specified element to the end of this list. * * @param userId userId * @param itemId itemId * @param score predicted score value */ public void addIndependently(int userId, int itemId, double score) { if (contextMultimap == null) { synchronized (this) { if (independentRanking) { contextMultimap = TreeMultimap.create(Comparator.comparingInt(k -> k), Comparator.comparingDouble(v -> -v.value)); } else { contextMultimap = TreeMultimap.create(Comparator.comparingInt(k -> k), Comparator.comparingInt(v -> v.key)); } } } contextMultimap.put(userId, new KeyValue<>(itemId, score)); }
public void testToMultimap() { Collector<Entry<String, Integer>, ?, TreeMultimap<String, Integer>> collector = Multimaps.toMultimap(Entry::getKey, Entry::getValue, TreeMultimap::create); BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence = Equivalence.equals() .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet())) .and(Equivalence.equals()); TreeMultimap<String, Integer> empty = TreeMultimap.create(); TreeMultimap<String, Integer> filled = TreeMultimap.create(); filled.put("a", 1); filled.put("a", 2); filled.put("b", 2); filled.put("c", 3); CollectorTester.of(collector, equivalence) .expectCollects(empty) .expectCollects( filled, mapEntry("a", 1), mapEntry("a", 2), mapEntry("b", 2), mapEntry("c", 3)); }
private synchronized void addPermitAllocation(PermitAllocation allocation) { this.batches.put(allocation.getExpiration(), new PermitBatch(allocation.getPermits(), allocation.getExpiration())); this.totalAvailablePermits += allocation.getPermits(); } }
/** Test that a TreeMultimap created from another uses the natural ordering. */ public void testMultimapCreateFromTreeMultimap() { TreeMultimap<String, Integer> tree = TreeMultimap.create(StringLength.COMPARATOR, DECREASING_INT_COMPARATOR); tree.put("google", 2); tree.put("google", 6); tree.put("tree", 0); tree.put("tree", 3); assertThat(tree.keySet()).containsExactly("tree", "google").inOrder(); assertThat(tree.get("google")).containsExactly(6, 2).inOrder(); TreeMultimap<String, Integer> copy = TreeMultimap.create(tree); assertEquals(tree, copy); assertThat(copy.keySet()).containsExactly("google", "tree").inOrder(); assertThat(copy.get("google")).containsExactly(2, 6).inOrder(); assertEquals(Ordering.natural(), copy.keyComparator()); assertEquals(Ordering.natural(), copy.valueComparator()); assertEquals(Ordering.natural(), copy.get("google").comparator()); }
@GwtIncompatible // SerializableTester public void testTreeMultimapNonGeneric() { TreeMultimap<LegacyComparable, LegacyComparable> multimap = TreeMultimap.create(); assertEquals(ImmutableMultimap.of(), multimap); multimap.put(new LegacyComparable("foo"), new LegacyComparable("f")); multimap.put(new LegacyComparable("foo"), new LegacyComparable("o")); multimap.put(new LegacyComparable("foo"), new LegacyComparable("o")); multimap.put(new LegacyComparable("bar"), new LegacyComparable("b")); multimap.put(new LegacyComparable("bar"), new LegacyComparable("a")); multimap.put(new LegacyComparable("bar"), new LegacyComparable("r")); assertThat(multimap.keySet()) .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo")) .inOrder(); assertThat(multimap.values()) .containsExactly( new LegacyComparable("a"), new LegacyComparable("b"), new LegacyComparable("r"), new LegacyComparable("f"), new LegacyComparable("o")) .inOrder(); assertEquals(Ordering.natural(), multimap.keyComparator()); assertEquals(Ordering.natural(), multimap.valueComparator()); SerializableTester.reserializeAndAssert(multimap); }
@GwtIncompatible // SerializableTester public void testTreeMultimapDerived() { TreeMultimap<DerivedComparable, DerivedComparable> multimap = TreeMultimap.create(); assertEquals(ImmutableMultimap.of(), multimap); multimap.put(new DerivedComparable("foo"), new DerivedComparable("f")); multimap.put(new DerivedComparable("foo"), new DerivedComparable("o")); multimap.put(new DerivedComparable("foo"), new DerivedComparable("o")); multimap.put(new DerivedComparable("bar"), new DerivedComparable("b")); multimap.put(new DerivedComparable("bar"), new DerivedComparable("a")); multimap.put(new DerivedComparable("bar"), new DerivedComparable("r")); assertThat(multimap.keySet()) .containsExactly(new DerivedComparable("bar"), new DerivedComparable("foo")) .inOrder(); assertThat(multimap.values()) .containsExactly( new DerivedComparable("a"), new DerivedComparable("b"), new DerivedComparable("r"), new DerivedComparable("f"), new DerivedComparable("o")) .inOrder(); assertEquals(Ordering.natural(), multimap.keyComparator()); assertEquals(Ordering.natural(), multimap.valueComparator()); SerializableTester.reserializeAndAssert(multimap); }
/** * Adds an object to the results of the search as long as maxCapacity nor maxDistance is not exceeded. * * @param entry The object to add to the results of the search */ void addEntry(Entry<T> entry) { results.put(entry.distance, entry); int size = results.size(); if (size > maxCapacity) { //Removes some entries if maxCapacity is exceeded Float maxDistanceInResults = results.keySet().last(); NavigableSet<Entry<T>> entriesAtThisDistance = results.get(maxDistanceInResults); entriesAtThisDistance.pollLast(); if (entriesAtThisDistance.size() == 0) { results.removeAll(maxDistanceInResults); } maxDistance = results.keySet().last(); } else if (size == maxCapacity) { //If the size is at maxCapacity, then set maxDistance to the distance of the last entry maxDistance = results.keySet().last(); } } }
@Override synchronized void touch(final String bpid, final long blockId) { Map<Long, RamDiskReplicaLru> map = replicaMaps.get(bpid); RamDiskReplicaLru ramDiskReplicaLru = map.get(blockId); if (ramDiskReplicaLru == null) { return; } ramDiskReplicaLru.numReads.getAndIncrement(); // Reinsert the replica with its new timestamp. if (replicasPersisted.remove(ramDiskReplicaLru.lastUsedTime, ramDiskReplicaLru)) { ramDiskReplicaLru.lastUsedTime = Time.monotonicNow(); replicasPersisted.put(ramDiskReplicaLru.lastUsedTime, ramDiskReplicaLru); } }