/** * Returns a {@code Collector} that accumulates the input elements into a new {@code * ImmutableMultiset}. Elements are sorted by the specified comparator. * * <p><b>Warning:</b> {@code comparator} should be <i>consistent with {@code equals}</i> as * explained in the {@link Comparator} documentation. * * @since 21.0 */ @Beta public static <E> Collector<E, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset( Comparator<? super E> comparator) { return toImmutableSortedMultiset(comparator, Function.identity(), e -> 1); }
/** * Returns a {@code Collector} that accumulates the input elements into a new {@code * ImmutableMultiset}. Elements are sorted by the specified comparator. * * <p><b>Warning:</b> {@code comparator} should be <i>consistent with {@code equals}</i> as * explained in the {@link Comparator} documentation. * * @since 21.0 */ @Beta public static <E> Collector<E, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset( Comparator<? super E> comparator) { return toImmutableSortedMultiset(comparator, Function.identity(), e -> 1); }
public void testToImmutableSortedMultiset() { BiPredicate<ImmutableSortedMultiset<String>, ImmutableSortedMultiset<String>> equivalence = (ms1, ms2) -> ms1.equals(ms2) && ms1.entrySet().asList().equals(ms2.entrySet().asList()) && ms1.comparator().equals(ms2.comparator()); CollectorTester.of( ImmutableSortedMultiset.<String>toImmutableSortedMultiset( String.CASE_INSENSITIVE_ORDER), equivalence) .expectCollects(ImmutableSortedMultiset.emptyMultiset(String.CASE_INSENSITIVE_ORDER)) .expectCollects( ImmutableSortedMultiset.orderedBy(String.CASE_INSENSITIVE_ORDER) .addCopies("a", 2) .addCopies("b", 1) .addCopies("c", 3) .build(), "a", "c", "b", "c", "A", "C"); }
public void testToImmutableSortedMultisetCountFunction() { BiPredicate<ImmutableSortedMultiset<String>, ImmutableSortedMultiset<String>> equivalence = (ms1, ms2) -> ms1.equals(ms2) && ms1.entrySet().asList().equals(ms2.entrySet().asList()) && ms1.comparator().equals(ms2.comparator()); CollectorTester.of( ImmutableSortedMultiset.<String, String>toImmutableSortedMultiset( String.CASE_INSENSITIVE_ORDER, e -> e, e -> 1), equivalence) .expectCollects(ImmutableSortedMultiset.emptyMultiset(String.CASE_INSENSITIVE_ORDER)) .expectCollects( ImmutableSortedMultiset.orderedBy(String.CASE_INSENSITIVE_ORDER) .addCopies("a", 2) .addCopies("b", 1) .addCopies("c", 3) .build(), "a", "c", "b", "c", "A", "C"); }
/** * Returns a {@code Collector} that accumulates the input elements into a new {@code * ImmutableMultiset}. Elements are sorted by the specified comparator. * * <p><b>Warning:</b> {@code comparator} should be <i>consistent with {@code equals}</i> as * explained in the {@link Comparator} documentation. * * @since 21.0 */ @Beta public static <E> Collector<E, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset( Comparator<? super E> comparator) { return toImmutableSortedMultiset(comparator, Function.identity(), e -> 1); }
/** * Returns a {@code Collector} that accumulates the input elements into a new {@code * ImmutableMultiset}. Elements are sorted by the specified comparator. * * <p><b>Warning:</b> {@code comparator} should be <i>consistent with {@code equals}</i> as * explained in the {@link Comparator} documentation. * * @since 21.0 */ @Beta public static <E> Collector<E, ?, ImmutableSortedMultiset<E>> toImmutableSortedMultiset( Comparator<? super E> comparator) { return toImmutableSortedMultiset(comparator, Function.identity(), e -> 1); }
public void testToImmutableSortedMultisetCountFunction() { BiPredicate<ImmutableSortedMultiset<String>, ImmutableSortedMultiset<String>> equivalence = (ms1, ms2) -> ms1.equals(ms2) && ms1.entrySet().asList().equals(ms2.entrySet().asList()) && ms1.comparator().equals(ms2.comparator()); CollectorTester.of( ImmutableSortedMultiset.<String, String>toImmutableSortedMultiset( String.CASE_INSENSITIVE_ORDER, e -> e, e -> 1), equivalence) .expectCollects(ImmutableSortedMultiset.emptyMultiset(String.CASE_INSENSITIVE_ORDER)) .expectCollects( ImmutableSortedMultiset.orderedBy(String.CASE_INSENSITIVE_ORDER) .addCopies("a", 2) .addCopies("b", 1) .addCopies("c", 3) .build(), "a", "c", "b", "c", "A", "C"); }
public void testToImmutableSortedMultiset() { BiPredicate<ImmutableSortedMultiset<String>, ImmutableSortedMultiset<String>> equivalence = (ms1, ms2) -> ms1.equals(ms2) && ms1.entrySet().asList().equals(ms2.entrySet().asList()) && ms1.comparator().equals(ms2.comparator()); CollectorTester.of( ImmutableSortedMultiset.<String>toImmutableSortedMultiset( String.CASE_INSENSITIVE_ORDER), equivalence) .expectCollects(ImmutableSortedMultiset.emptyMultiset(String.CASE_INSENSITIVE_ORDER)) .expectCollects( ImmutableSortedMultiset.orderedBy(String.CASE_INSENSITIVE_ORDER) .addCopies("a", 2) .addCopies("b", 1) .addCopies("c", 3) .build(), "a", "c", "b", "c", "A", "C"); }