Skip to content

Commit

Permalink
Change RangeMap.putAll() to take RangeMap<K, ? extends V> so that…
Browse files Browse the repository at this point in the history
…, for example, you could put a `RangeMap<Instant, String>` into a `RangeMap<Instant, CharSequence>` just as you could put each entry using `put(Range<Instant>, CharSequence)`.

RELNOTES=n/a
PiperOrigin-RevId: 449758638
  • Loading branch information
netdpb authored and Google Java Core Libraries committed May 19, 2022
1 parent 7581939 commit 7731825
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Expand Up @@ -241,7 +241,7 @@ public final void putCoalescing(Range<K> range, V value) {
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
public final void putAll(RangeMap<K, V> rangeMap) {
public final void putAll(RangeMap<K, ? extends V> rangeMap) {
throw new UnsupportedOperationException();
}

Expand Down
2 changes: 1 addition & 1 deletion android/guava/src/com/google/common/collect/RangeMap.java
Expand Up @@ -101,7 +101,7 @@ public interface RangeMap<K extends Comparable, V> {
void putCoalescing(Range<K> range, V value);

/** Puts all the associations from {@code rangeMap} into this range map (optional operation). */
void putAll(RangeMap<K, V> rangeMap);
void putAll(RangeMap<K, ? extends V> rangeMap);

/** Removes all associations from this range map (optional operation). */
void clear();
Expand Down
8 changes: 4 additions & 4 deletions android/guava/src/com/google/common/collect/TreeRangeMap.java
Expand Up @@ -167,8 +167,8 @@ private static <K extends Comparable, V> Range<K> coalesce(
}

@Override
public void putAll(RangeMap<K, V> rangeMap) {
for (Entry<Range<K>, V> entry : rangeMap.asMapOfRanges().entrySet()) {
public void putAll(RangeMap<K, ? extends V> rangeMap) {
for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ public void putCoalescing(Range<Comparable<?>> range, Object value) {
}

@Override
public void putAll(RangeMap<Comparable<?>, Object> rangeMap) {
public void putAll(RangeMap<Comparable<?>, ? extends Object> rangeMap) {
if (!rangeMap.asMapOfRanges().isEmpty()) {
throw new IllegalArgumentException(
"Cannot putAll(nonEmptyRangeMap) into an empty subRangeMap");
Expand Down Expand Up @@ -447,7 +447,7 @@ public void putCoalescing(Range<K> range, V value) {
}

@Override
public void putAll(RangeMap<K, V> rangeMap) {
public void putAll(RangeMap<K, ? extends V> rangeMap) {
if (rangeMap.asMapOfRanges().isEmpty()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/collect/ImmutableRangeMap.java
Expand Up @@ -258,7 +258,7 @@ public final void putCoalescing(Range<K> range, V value) {
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
public final void putAll(RangeMap<K, V> rangeMap) {
public final void putAll(RangeMap<K, ? extends V> rangeMap) {
throw new UnsupportedOperationException();
}

Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/collect/RangeMap.java
Expand Up @@ -103,7 +103,7 @@ public interface RangeMap<K extends Comparable, V> {
void putCoalescing(Range<K> range, V value);

/** Puts all the associations from {@code rangeMap} into this range map (optional operation). */
void putAll(RangeMap<K, V> rangeMap);
void putAll(RangeMap<K, ? extends V> rangeMap);

/** Removes all associations from this range map (optional operation). */
void clear();
Expand Down
8 changes: 4 additions & 4 deletions guava/src/com/google/common/collect/TreeRangeMap.java
Expand Up @@ -169,8 +169,8 @@ private static <K extends Comparable, V> Range<K> coalesce(
}

@Override
public void putAll(RangeMap<K, V> rangeMap) {
for (Entry<Range<K>, V> entry : rangeMap.asMapOfRanges().entrySet()) {
public void putAll(RangeMap<K, ? extends V> rangeMap) {
for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
Expand Down Expand Up @@ -417,7 +417,7 @@ public void putCoalescing(Range<Comparable<?>> range, Object value) {
}

@Override
public void putAll(RangeMap<Comparable<?>, Object> rangeMap) {
public void putAll(RangeMap<Comparable<?>, ? extends Object> rangeMap) {
if (!rangeMap.asMapOfRanges().isEmpty()) {
throw new IllegalArgumentException(
"Cannot putAll(nonEmptyRangeMap) into an empty subRangeMap");
Expand Down Expand Up @@ -534,7 +534,7 @@ public void putCoalescing(Range<K> range, V value) {
}

@Override
public void putAll(RangeMap<K, V> rangeMap) {
public void putAll(RangeMap<K, ? extends V> rangeMap) {
if (rangeMap.asMapOfRanges().isEmpty()) {
return;
}
Expand Down

0 comments on commit 7731825

Please sign in to comment.