Skip to content

Commit

Permalink
Add ImmutableMap.getOrDefault() in the Android branch.
Browse files Browse the repository at this point in the history
[]

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176589307
  • Loading branch information
cpovirk committed Nov 22, 2017
1 parent dc32104 commit 1e4938c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions android/guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,23 @@ public boolean containsValue(@Nullable Object value) {
@Override
public abstract V get(@Nullable Object key);

/**
* {@inheritDoc}
*
* <p>See <a
* href="https://developer.android.com/reference/java/util/Map.html#getOrDefault%28java.lang.Object,%20V%29">{@code
* Map.getOrDefault}</a>.
*
* @since 23.5 (but since 21.0 in the JRE <a
* href="https://github.com/google/guava#guava-google-core-libraries-for-java">flavor</a>).
* Note that API Level 24 users can call this method with any version of Guava.
*/
// @Override under Java 8 / API Level 24
public final V getOrDefault(@Nullable Object key, @Nullable V defaultValue) {
V result = get(key);
return (result != null) ? result : defaultValue;
}

@LazyInit private transient ImmutableSet<Entry<K, V>> entrySet;

/**
Expand Down
5 changes: 5 additions & 0 deletions guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,11 @@ public boolean containsValue(@Nullable Object value) {
@Override
public abstract V get(@Nullable Object key);

/**
* @since 21.0 (but only since 23.5 in the Android <a
* href="https://github.com/google/guava#guava-google-core-libraries-for-java">flavor</a>).
* Note, however, that Java 8 users can call this method with any version and flavor of Guava.
*/

This comment has been minimized.

Copy link
@jbduncan

jbduncan Nov 22, 2017

Contributor

@cpovirk, I wonder if the end-result documentation would look better if it looked something like this?

/**
 * {@inheritDoc}
 *
 * @since 21.0 (but only since 23.5 in the Android <a
 *     href="https://github.com/google/guava#guava-google-core-libraries-for-java">flavor</a>).
 *     Note, however, that Java 8 users can call this method with any version and flavor of Guava.
 */

This comment has been minimized.

Copy link
@cpovirk

cpovirk Nov 22, 2017

Author Member

The doc does get inherited regardless:

http://google.github.io/guava/releases/snapshot-jre/api/docs/com/google/common/collect/ImmutableMap.html#getOrDefault-java.lang.Object-V-
http://google.github.io/guava/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableMap.html#getOrDefault-java.lang.Object-V-

As I understand it, doc is still inherited as long as you have only "block tags."

That said, I see that the Android branch doc looks nicer because it omits "Description copied from interface: java.util.Map." So arguably that's a reason to include {@inheritDoc}. I'd probably rather postprocess the output to remove that everywhere, though :) But maybe I should do it here, since it also helps reduce the diffs between the branches....

This comment has been minimized.

Copy link
@jbduncan

jbduncan Nov 22, 2017

Contributor

The doc does get inherited regardless...

Oh cool, I actually didn't know that, Thank you for enlightening me on this!

This comment has been minimized.

Copy link
@jbduncan

jbduncan Nov 22, 2017

Contributor

...But maybe I should do it here, since it also helps reduce the diffs between the branches....

I can't comment on this with full knowledge, as I'm not a Google employee, but I get the impression from other issues, PRs and commits that that would be a sensible thing to do. :)

@Override
public final V getOrDefault(@Nullable Object key, @Nullable V defaultValue) {
V result = get(key);
Expand Down

0 comments on commit 1e4938c

Please sign in to comment.