/** * Returns a newly-created immutable sorted map. * * @throws IllegalArgumentException if any two keys are equal according to the comparator (which * might be the keys' natural order) */ @Override public ImmutableSortedMap<K, V> build() { switch (size) { case 0: return emptyMap(comparator); case 1: return of(comparator, entries[0].getKey(), entries[0].getValue()); default: return fromEntries(comparator, false, entries, size); } } }
/** * Returns a newly-created immutable sorted map. * * @throws IllegalArgumentException if any two keys are equal according to the comparator (which * might be the keys' natural order) */ @Override public ImmutableSortedMap<K, V> build() { switch (size) { case 0: return emptyMap(comparator); case 1: return of(comparator, entries[0].getKey(), entries[0].getValue()); default: return fromEntries(comparator, false, entries, size); } } }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
@Override public ImmutableSortedMap<K, V> descendingMap() { // TODO(kevinb): the descendingMap is never actually cached at all. Either it should be or the // code below simplified. ImmutableSortedMap<K, V> result = descendingMap; if (result == null) { if (isEmpty()) { return result = emptyMap(Ordering.from(comparator()).reverse()); } else { return result = new ImmutableSortedMap<>( (RegularImmutableSortedSet<K>) keySet.descendingSet(), valueList.reverse(), this); } } return result; }
switch (size) { case 0: return emptyMap(comparator); case 1: return ImmutableSortedMap.<K, V>of(
switch (size) { case 0: return emptyMap(comparator); case 1: return of(comparator, (K) keys[0], (V) values[0]);
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
@Override public ImmutableSortedMap<K, V> descendingMap() { // TODO(kevinb): the descendingMap is never actually cached at all. Either it should be or the // code below simplified. ImmutableSortedMap<K, V> result = descendingMap; if (result == null) { if (isEmpty()) { return result = emptyMap(Ordering.from(comparator()).reverse()); } else { return result = new ImmutableSortedMap<>( (RegularImmutableSortedSet<K>) keySet.descendingSet(), valueList.reverse(), this); } } return result; }
switch (size) { case 0: return emptyMap(comparator); case 1: return ImmutableSortedMap.<K, V>of(
private ImmutableSortedMap<K, V> createSubmap( int newFromIndex, int newToIndex) { if (newFromIndex < newToIndex) { return new ImmutableSortedMap<K, V>(entries, comparator, newFromIndex, newToIndex); } else { return emptyMap(comparator); } }
private ImmutableSortedMap<K, V> createSubmap( int newFromIndex, int newToIndex) { if (newFromIndex < newToIndex) { return new ImmutableSortedMap<K, V>(entries, comparator, newFromIndex, newToIndex); } else { return emptyMap(comparator); } }
private ImmutableSortedMap<K, V> createSubmap( int newFromIndex, int newToIndex) { if (newFromIndex < newToIndex) { return new ImmutableSortedMap<K, V>(entries, comparator, newFromIndex, newToIndex); } else { return emptyMap(comparator); } }
private ImmutableSortedMap<K, V> createSubmap( int newFromIndex, int newToIndex) { if (newFromIndex < newToIndex) { return new ImmutableSortedMap<K, V>( entries.subList(newFromIndex, newToIndex), comparator); } else { return emptyMap(comparator); } }
static <K, V> ImmutableSortedMap<K, V> from( ImmutableSortedSet<K> keySet, ImmutableList<V> valueList) { if (keySet.isEmpty()) { return emptyMap(keySet.comparator()); } else { return new RegularImmutableSortedMap<K, V>( (RegularImmutableSortedSet<K>) keySet, valueList); } }
static <K, V> ImmutableSortedMap<K, V> from( ImmutableSortedSet<K> keySet, ImmutableList<V> valueList) { if (keySet.isEmpty()) { return emptyMap(keySet.comparator()); } else { return new RegularImmutableSortedMap<K, V>( (RegularImmutableSortedSet<K>) keySet, valueList); } }
static <K, V> ImmutableSortedMap<K, V> from( ImmutableSortedSet<K> keySet, ImmutableList<V> valueList) { if (keySet.isEmpty()) { return emptyMap(keySet.comparator()); } else { return new RegularImmutableSortedMap<K, V>( (RegularImmutableSortedSet<K>) keySet, valueList); } }
static <K, V> ImmutableSortedMap<K, V> from( ImmutableSortedSet<K> keySet, ImmutableList<V> valueList) { if (keySet.isEmpty()) { return emptyMap(keySet.comparator()); } else { return new RegularImmutableSortedMap<K, V>( (RegularImmutableSortedSet<K>) keySet, valueList); } }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }
private ImmutableSortedMap<K, V> getSubMap(int fromIndex, int toIndex) { if (fromIndex == 0 && toIndex == size()) { return this; } else if (fromIndex == toIndex) { return emptyMap(comparator()); } else { return new ImmutableSortedMap<K, V>( keySet.getSubSet(fromIndex, toIndex), valueList.subList(fromIndex, toIndex)); } }