@GwtIncompatible // SerializableTester public void testNewSortedSetMultimapSerialization() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); multimap.putAll(Color.BLUE, asList(3, 1, 4)); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); SerializableTester.reserializeAndAssert(multimap); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }
public void testSynchronizedSortedSetMultimap() { SortedSetMultimap<String, Integer> multimap = Multimaps.synchronizedSortedSetMultimap(TreeMultimap.<String, Integer>create()); multimap.putAll("foo", Arrays.asList(3, -1, 2, 4, 1)); multimap.putAll("bar", Arrays.asList(1, 2, 3, 1)); assertThat(multimap.removeAll("foo")).containsExactly(-1, 1, 2, 3, 4).inOrder(); assertFalse(multimap.containsKey("foo")); assertThat(multimap.replaceValues("bar", Arrays.asList(6, 5))) .containsExactly(1, 2, 3) .inOrder(); assertThat(multimap.get("bar")).containsExactly(5, 6).inOrder(); }
public void testNewSortedSetMultimap() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); // newSortedSetMultimap calls the factory once to determine the comparator. assertEquals(1, factory.count); multimap.putAll(Color.BLUE, asList(3, 1, 4)); assertEquals(2, factory.count); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(3, factory.count); assertEquals("[4, 3, 1]", multimap.get(Color.BLUE).toString()); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }
private void init(final Set<? extends KillbillService> services) { for (final KillbillService service : services) { handlersByLevel.putAll(findAllHandlers(service)); } }
public void updateRelInMap( SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) { for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) { if (oldToNewRelMap.containsKey(rel)) { SortedSet<CorrelationId> corVarSet = mapRefRelToCorVar.removeAll(rel); mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet); } } }
public void updateRelInMap( SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) { for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) { if (oldToNewRelMap.containsKey(rel)) { SortedSet<CorrelationId> corVarSet = mapRefRelToCorVar.removeAll(rel); mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet); } } }
public void updateRelInMap( SortedSetMultimap<RelNode, Correlation> mapRefRelToCorVar) { for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) { if (oldToNewRelMap.containsKey(rel)) { SortedSet<Correlation> corVarSet = mapRefRelToCorVar.removeAll(rel); mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet); } } }
public static String sortAndConcatHeadersIntoString(Multimap<String, String> headers) { StringBuilder buffer = new StringBuilder(); SortedSetMultimap<String, String> sortedMap = TreeMultimap.create(); sortedMap.putAll(headers); for (Entry<String, String> header : sortedMap.entries()) { if (header.getKey() != null) buffer.append(String.format("%s: %s\n", header.getKey(), header.getValue())); } return buffer.toString(); }
public static String sortAndConcatHeadersIntoString(Multimap<String, String> headers) { StringBuilder buffer = new StringBuilder(); SortedSetMultimap<String, String> sortedMap = TreeMultimap.create(); sortedMap.putAll(headers); for (Entry<String, String> header : sortedMap.entries()) { if (header.getKey() != null) buffer.append(String.format("%s: %s\n", header.getKey(), header.getValue())); } return buffer.toString(); }
@Override public void storeSone(Sone sone) { lock.writeLock().lock(); try { removeSone(sone); allSones.put(sone.getId(), sone); sonePosts.putAll(sone.getId(), sone.getPosts()); for (Post post : sone.getPosts()) { allPosts.put(post.getId(), post); } sonePostReplies.putAll(sone.getId(), sone.getReplies()); for (PostReply postReply : sone.getReplies()) { allPostReplies.put(postReply.getId(), postReply); } soneAlbums.putAll(sone.getId(), toAllAlbums.apply(sone)); for (Album album : toAllAlbums.apply(sone)) { allAlbums.put(album.getId(), album); } soneImages.putAll(sone.getId(), toAllImages.apply(sone)); for (Image image : toAllImages.apply(sone)) { allImages.put(image.getId(), image); } } finally { lock.writeLock().unlock(); } }
answerElement.getAsns().putAll(asn, asns.get(asn));
@GwtIncompatible // SerializableTester public void testNewSortedSetMultimapSerialization() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); multimap.putAll(Color.BLUE, asList(3, 1, 4)); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); SerializableTester.reserializeAndAssert(multimap); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }
private void dataSourceSyncWithinTransaction() { m_lock.writeLock().lock(); try { /* * Make a new list with which we'll replace the existing one, that way * if something goes wrong with the DB we won't lose whatever was already * in there */ final SortedSetMultimap<Key, Value> newAlreadyDiscovered = Multimaps.newSortedSetMultimap(Maps.newHashMap(), TreeSet::new); // Fetch all non-deleted nodes final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.ne("type", String.valueOf(NodeType.DELETED.value())); for (OnmsNode node : m_nodeDao.findMatching(builder.toCriteria())) { for (final OnmsIpInterface iface : node.getIpInterfaces()) { // Skip deleted interfaces // TODO: Refactor the 'D' value with an enumeration if ("D".equals(iface.getIsManaged())) { continue; } LOG.debug("Adding entry: {}:{} -> {}", node.getLocation().getLocationName(), iface.getIpAddress(), node.getId()); newAlreadyDiscovered.put(new Key(node.getLocation().getLocationName(), iface.getIpAddress()), new Value(node.getId(), iface.getIsSnmpPrimary())); } } m_managedAddresses.clear(); m_managedAddresses.putAll(newAlreadyDiscovered); LOG.info("dataSourceSync: initialized list of managed IP addresses with {} members", m_managedAddresses.size()); } finally { m_lock.writeLock().unlock(); } }
public void testSynchronizedSortedSetMultimap() { SortedSetMultimap<String, Integer> multimap = Multimaps.synchronizedSortedSetMultimap( TreeMultimap.<String, Integer>create()); multimap.putAll("foo", Arrays.asList(3, -1, 2, 4, 1)); multimap.putAll("bar", Arrays.asList(1, 2, 3, 1)); assertThat(multimap.removeAll("foo")).containsExactly(-1, 1, 2, 3, 4).inOrder(); assertFalse(multimap.containsKey("foo")); assertThat(multimap.replaceValues("bar", Arrays.asList(6, 5))) .containsExactly(1, 2, 3).inOrder(); assertThat(multimap.get("bar")).containsExactly(5, 6).inOrder(); }
public void testNewSortedSetMultimap() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); // newSortedSetMultimap calls the factory once to determine the comparator. assertEquals(1, factory.count); multimap.putAll(Color.BLUE, asList(3, 1, 4)); assertEquals(2, factory.count); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(3, factory.count); assertEquals("[4, 3, 1]", multimap.get(Color.BLUE).toString()); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }