public void testBuilder_orderEntriesByValue() { ImmutableMap<String, Integer> map = new Builder<String, Integer>() .orderEntriesByValue(Ordering.natural()) .put("three", 3) .put("one", 1) .put("five", 5) .put("four", 4) .put("two", 2) .build(); assertMapEquals(map, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5); }
public void testBuilder_orderEntriesByValueAfterExactSizeBuild() { Builder<String, Integer> builder = new Builder<String, Integer>(2).put("four", 4).put("one", 1); ImmutableMap<String, Integer> keyOrdered = builder.build(); ImmutableMap<String, Integer> valueOrdered = builder.orderEntriesByValue(Ordering.natural()).build(); assertMapEquals(keyOrdered, "four", 4, "one", 1); assertMapEquals(valueOrdered, "one", 1, "four", 4); }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * * <p>The sort order is stable, that is, if two entries have values that compare as equivalent, * the entry that was inserted first will be first in the built map's iteration order. * * @throws IllegalStateException if this method was already called * @since 19.0 */ @CanIgnoreReturnValue @Beta @Override public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) { super.orderEntriesByValue(valueComparator); return this; }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * * <p>The sort order is stable, that is, if two entries have values that compare as equivalent, * the entry that was inserted first will be first in the built map's iteration order. * * @throws IllegalStateException if this method was already called * @since 19.0 */ @CanIgnoreReturnValue @Beta @Override public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) { super.orderEntriesByValue(valueComparator); return this; }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * * <p>The sort order is stable, that is, if two entries have values that compare as equivalent, * the entry that was inserted first will be first in the built map's iteration order. * * @throws IllegalStateException if this method was already called * @since 19.0 */ @CanIgnoreReturnValue @Beta @Override public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) { super.orderEntriesByValue(valueComparator); return this; }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * * <p>The sort order is stable, that is, if two entries have values that compare * as equivalent, the entry that was inserted first will be first in the built map's * iteration order. * * @throws IllegalStateException if this method was already called * @since 19.0 */ @Beta @Override public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) { super.orderEntriesByValue(valueComparator); return this; }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * <p> * <p>The sort order is stable, that is, if two entries have values that compare * as equivalent, the entry that was inserted first will be first in the built map's * iteration order. * * @param valueComparator * @throws IllegalStateException if this method was already called */ @Beta public Builder orderEntriesByValue(Comparator<? super Component> valueComparator) { builder.orderEntriesByValue(valueComparator); return this; }
public void testBuilder_orderEntriesByValue_usedTwiceFails() { ImmutableMap.Builder<String, Integer> builder = new Builder<String, Integer>() .orderEntriesByValue(Ordering.natural()); try { builder.orderEntriesByValue(Ordering.natural()); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) {} }
public void testBuilder_orderEntriesByValue() { ImmutableMap<String, Integer> map = new Builder<String, Integer>() .orderEntriesByValue(Ordering.natural()) .put("three", 3) .put("one", 1) .put("five", 5) .put("four", 4) .put("two", 2) .build(); assertMapEquals(map, "one", 1, "two", 2, "three", 3, "four", 4, "five", 5); }
public void testBuilder_orderEntriesByValueAfterExactSizeBuild() { Builder<String, Integer> builder = new Builder<String, Integer>(2) .put("four", 4) .put("one", 1); ImmutableMap<String, Integer> keyOrdered = builder.build(); ImmutableMap<String, Integer> valueOrdered = builder.orderEntriesByValue(Ordering.natural()).build(); assertMapEquals(keyOrdered, "four", 4, "one", 1); assertMapEquals(valueOrdered, "one", 1, "four", 4); }
/** * Configures this {@code Builder} to order entries by value according to the specified * comparator. * * <p>The sort order is stable, that is, if two entries have values that compare as equivalent, * the entry that was inserted first will be first in the built map's iteration order. * * @throws IllegalStateException if this method was already called * @since 19.0 */ @CanIgnoreReturnValue @Beta @Override public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) { super.orderEntriesByValue(valueComparator); return this; }
public void testBuilder_orderEntriesByValue_usedTwiceFails() { ImmutableMap.Builder<String, Integer> builder = new Builder<String, Integer>().orderEntriesByValue(Ordering.natural()); try { builder.orderEntriesByValue(Ordering.natural()); fail("Expected IllegalStateException"); } catch (IllegalStateException expected) { } }