8310571: Use inline @return tag on java.util.Objects

Reviewed-by: smarks
This commit is contained in:
Joe Darcy 2023-06-23 22:55:06 +00:00
parent dad7bd9efc
commit 0db63ec76d

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,8 +45,8 @@ public final class Objects {
} }
/** /**
* Returns {@code true} if the arguments are equal to each other * {@return {@code true} if the arguments are equal to each other
* and {@code false} otherwise. * and {@code false} otherwise}
* Consequently, if both arguments are {@code null}, {@code true} * Consequently, if both arguments are {@code null}, {@code true}
* is returned. Otherwise, if the first argument is not {@code * is returned. Otherwise, if the first argument is not {@code
* null}, equality is determined by calling the {@link * null}, equality is determined by calling the {@link
@ -56,8 +56,6 @@ public final class Objects {
* *
* @param a an object * @param a an object
* @param b an object to be compared with {@code a} for equality * @param b an object to be compared with {@code a} for equality
* @return {@code true} if the arguments are equal to each other
* and {@code false} otherwise
* @see Object#equals(Object) * @see Object#equals(Object)
*/ */
public static boolean equals(Object a, Object b) { public static boolean equals(Object a, Object b) {
@ -65,8 +63,8 @@ public final class Objects {
} }
/** /**
* Returns {@code true} if the arguments are deeply equal to each other * {@return {@code true} if the arguments are deeply equal to each other
* and {@code false} otherwise. * and {@code false} otherwise}
* *
* Two {@code null} values are deeply equal. If both arguments are * Two {@code null} values are deeply equal. If both arguments are
* arrays, the algorithm in {@link Arrays#deepEquals(Object[], * arrays, the algorithm in {@link Arrays#deepEquals(Object[],
@ -76,8 +74,6 @@ public final class Objects {
* *
* @param a an object * @param a an object
* @param b an object to be compared with {@code a} for deep equality * @param b an object to be compared with {@code a} for deep equality
* @return {@code true} if the arguments are deeply equal to each other
* and {@code false} otherwise
* @see Arrays#deepEquals(Object[], Object[]) * @see Arrays#deepEquals(Object[], Object[])
* @see Objects#equals(Object, Object) * @see Objects#equals(Object, Object)
*/ */
@ -91,12 +87,10 @@ public final class Objects {
} }
/** /**
* Returns the hash code of a non-{@code null} argument and 0 for * {@return the hash code of a non-{@code null} argument and 0 for
* a {@code null} argument. * a {@code null} argument}
* *
* @param o an object * @param o an object
* @return the hash code of a non-{@code null} argument and 0 for
* a {@code null} argument
* @see Object#hashCode * @see Object#hashCode
*/ */
public static int hashCode(Object o) { public static int hashCode(Object o) {
@ -104,7 +98,7 @@ public final class Objects {
} }
/** /**
* Generates a hash code for a sequence of input values. The hash * {@return a hash code for a sequence of input values} The hash
* code is generated as if all the input values were placed into an * code is generated as if all the input values were placed into an
* array, and that array were hashed by calling {@link * array, and that array were hashed by calling {@link
* Arrays#hashCode(Object[])}. * Arrays#hashCode(Object[])}.
@ -125,7 +119,6 @@ public final class Objects {
* value can be computed by calling {@link #hashCode(Object)}. * value can be computed by calling {@link #hashCode(Object)}.
* *
* @param values the values to be hashed * @param values the values to be hashed
* @return a hash value of the sequence of input values
* @see Arrays#hashCode(Object[]) * @see Arrays#hashCode(Object[])
* @see List#hashCode * @see List#hashCode
*/ */
@ -134,12 +127,11 @@ public final class Objects {
} }
/** /**
* Returns the result of calling {@code toString} for a non-{@code * {@return the result of calling {@code toString} for a
* null} argument and {@code "null"} for a {@code null} argument. * non-{@code null} argument and {@code "null"} for a
* {@code null} argument}
* *
* @param o an object * @param o an object
* @return the result of calling {@code toString} for a non-{@code
* null} argument and {@code "null"} for a {@code null} argument
* @see Object#toString * @see Object#toString
* @see String#valueOf(Object) * @see String#valueOf(Object)
*/ */
@ -148,16 +140,13 @@ public final class Objects {
} }
/** /**
* Returns the result of calling {@code toString} on the first * {@return the result of calling {@code toString} on the first
* argument if the first argument is not {@code null} and returns * argument if the first argument is not {@code null} and the
* the second argument otherwise. * second argument otherwise}
* *
* @param o an object * @param o an object
* @param nullDefault string to return if the first argument is * @param nullDefault string to return if the first argument is
* {@code null} * {@code null}
* @return the result of calling {@code toString} on the first
* argument if it is not {@code null} and the second argument
* otherwise.
* @see Objects#toString(Object) * @see Objects#toString(Object)
*/ */
public static String toString(Object o, String nullDefault) { public static String toString(Object o, String nullDefault) {
@ -189,8 +178,8 @@ public final class Objects {
} }
/** /**
* Returns 0 if the arguments are identical and {@code * {@return 0 if the arguments are identical and {@code
* c.compare(a, b)} otherwise. * c.compare(a, b)} otherwise}
* Consequently, if both arguments are {@code null} 0 * Consequently, if both arguments are {@code null} 0
* is returned. * is returned.
* *
@ -203,8 +192,6 @@ public final class Objects {
* @param a an object * @param a an object
* @param b an object to be compared with {@code a} * @param b an object to be compared with {@code a}
* @param c the {@code Comparator} to compare the first two arguments * @param c the {@code Comparator} to compare the first two arguments
* @return 0 if the arguments are identical and {@code
* c.compare(a, b)} otherwise.
* @see Comparable * @see Comparable
* @see Comparator * @see Comparator
*/ */
@ -261,15 +248,13 @@ public final class Objects {
} }
/** /**
* Returns {@code true} if the provided reference is {@code null} otherwise * {@return {@code true} if the provided reference is {@code
* returns {@code false}. * null}; {@code false} otherwise}
* *
* @apiNote This method exists to be used as a * @apiNote This method exists to be used as a
* {@link java.util.function.Predicate}, {@code filter(Objects::isNull)} * {@link java.util.function.Predicate}, {@code filter(Objects::isNull)}
* *
* @param obj a reference to be checked against {@code null} * @param obj a reference to be checked against {@code null}
* @return {@code true} if the provided reference is {@code null} otherwise
* {@code false}
* *
* @see java.util.function.Predicate * @see java.util.function.Predicate
* @since 1.8 * @since 1.8
@ -279,15 +264,13 @@ public final class Objects {
} }
/** /**
* Returns {@code true} if the provided reference is non-{@code null} * {@return {@code true} if the provided reference is non-{@code null};
* otherwise returns {@code false}. * {@code false} otherwise}
* *
* @apiNote This method exists to be used as a * @apiNote This method exists to be used as a
* {@link java.util.function.Predicate}, {@code filter(Objects::nonNull)} * {@link java.util.function.Predicate}, {@code filter(Objects::nonNull)}
* *
* @param obj a reference to be checked against {@code null} * @param obj a reference to be checked against {@code null}
* @return {@code true} if the provided reference is non-{@code null}
* otherwise {@code false}
* *
* @see java.util.function.Predicate * @see java.util.function.Predicate
* @since 1.8 * @since 1.8
@ -297,15 +280,13 @@ public final class Objects {
} }
/** /**
* Returns the first argument if it is non-{@code null} and * {@return the first argument if it is non-{@code null} and
* otherwise returns the non-{@code null} second argument. * otherwise the second argument if it is non-{@code null}}
* *
* @param obj an object * @param obj an object
* @param defaultObj a non-{@code null} object to return if the first argument * @param defaultObj a non-{@code null} object to return if the first argument
* is {@code null} * is {@code null}
* @param <T> the type of the reference * @param <T> the type of the reference
* @return the first argument if it is non-{@code null} and
* otherwise the second argument if it is non-{@code null}
* @throws NullPointerException if both {@code obj} is null and * @throws NullPointerException if both {@code obj} is null and
* {@code defaultObj} is {@code null} * {@code defaultObj} is {@code null}
* @since 9 * @since 9
@ -315,15 +296,14 @@ public final class Objects {
} }
/** /**
* Returns the first argument if it is non-{@code null} and otherwise * {@return the first argument if it is non-{@code null} and
* returns the non-{@code null} value of {@code supplier.get()}. * otherwise the value from {@code supplier.get()} if it is
* non-{@code null}}
* *
* @param obj an object * @param obj an object
* @param supplier of a non-{@code null} object to return if the first argument * @param supplier of a non-{@code null} object to return if the first argument
* is {@code null} * is {@code null}
* @param <T> the type of the first argument and return type * @param <T> the type of the first argument and return type
* @return the first argument if it is non-{@code null} and otherwise
* the value from {@code supplier.get()} if it is non-{@code null}
* @throws NullPointerException if both {@code obj} is null and * @throws NullPointerException if both {@code obj} is null and
* either the {@code supplier} is {@code null} or * either the {@code supplier} is {@code null} or
* the {@code supplier.get()} value is {@code null} * the {@code supplier.get()} value is {@code null}