Java Code Examples for java.util.Objects.requireNonNullElse()

The following are Jave code examples for showing how to use requireNonNullElse() of the java.util.Objects class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: openjdk-jdk10   File:   Source Code and License Vote up 6 votes
 * Initializes a new charset with the given canonical name and alias
 * set.
 * @param  canonicalName
 *         The canonical name of this charset
 * @param  aliases
 *         An array of this charset's aliases, or null if it has no aliases
 * @throws IllegalCharsetNameException
 *         If the canonical name or any of the aliases are illegal
protected Charset(String canonicalName, String[] aliases) {
    String[] as = Objects.requireNonNullElse(aliases, zeroAliases);

    // Skip checks for the standard, built-in Charsets we always load
    // during initialization.
    if (canonicalName != "ISO-8859-1"
            && canonicalName != "US-ASCII"
            && canonicalName != "UTF-8") {
        for (int i = 0; i < as.length; i++) {
    } = canonicalName;
    this.aliases = as;
Example 2
Project: openjdk-jdk10   File:   Source Code and License Vote up 4 votes
public String toString() {
    return "ReducedValue(" + field + "," + minWidth + "," + maxWidth +
            "," + Objects.requireNonNullElse(baseDate, baseValue) + ")";
Example 3
Project: openjdk-jdk10   File:   Source Code and License Vote up 3 votes
 * Obtains an instance of {@code ZoneId} using its ID using a map
 * of aliases to supplement the standard zone IDs.
 * <p>
 * Many users of time-zones use short abbreviations, such as PST for
 * 'Pacific Standard Time' and PDT for 'Pacific Daylight Time'.
 * These abbreviations are not unique, and so cannot be used as IDs.
 * This method allows a map of string to time-zone to be setup and reused
 * within an application.
 * @param zoneId  the time-zone ID, not null
 * @param aliasMap  a map of alias zone IDs (typically abbreviations) to real zone IDs, not null
 * @return the zone ID, not null
 * @throws DateTimeException if the zone ID has an invalid format
 * @throws ZoneRulesException if the zone ID is a region ID that cannot be found
public static ZoneId of(String zoneId, Map<String, String> aliasMap) {
    Objects.requireNonNull(zoneId, "zoneId");
    Objects.requireNonNull(aliasMap, "aliasMap");
    String id = Objects.requireNonNullElse(aliasMap.get(zoneId), zoneId);
    return of(id);
Example 4
Project: openjdk-jdk10   File:   Source Code and License Vote up 2 votes
 * Obtains an instance of {@code Chronology} from a temporal object.
 * <p>
 * This obtains a chronology based on the specified temporal.
 * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 * which this factory converts to an instance of {@code Chronology}.
 * <p>
 * The conversion will obtain the chronology using {@link TemporalQueries#chronology()}.
 * If the specified temporal object does not have a chronology, {@link IsoChronology} is returned.
 * <p>
 * This method matches the signature of the functional interface {@link TemporalQuery}
 * allowing it to be used as a query via method reference, {@code Chronology::from}.
 * @param temporal  the temporal to convert, not null
 * @return the chronology, not null
 * @throws DateTimeException if unable to convert to a {@code Chronology}
static Chronology from(TemporalAccessor temporal) {
    Objects.requireNonNull(temporal, "temporal");
    Chronology obj = temporal.query(TemporalQueries.chronology());
    return Objects.requireNonNullElse(obj, IsoChronology.INSTANCE);