當前位置: 首頁>>代碼示例>>Java>>正文


Java Objects.requireNonNullElse方法代碼示例

本文整理匯總了Java中java.util.Objects.requireNonNullElse方法的典型用法代碼示例。如果您正苦於以下問題:Java Objects.requireNonNullElse方法的具體用法?Java Objects.requireNonNullElse怎麽用?Java Objects.requireNonNullElse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Objects的用法示例。


在下文中一共展示了Objects.requireNonNullElse方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Charset

import java.util.Objects; //導入方法依賴的package包/類
/**
 * 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") {
        checkName(canonicalName);
        for (int i = 0; i < as.length; i++) {
            checkName(as[i]);
        }
    }
    this.name = canonicalName;
    this.aliases = as;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:Charset.java

示例2: toString

import java.util.Objects; //導入方法依賴的package包/類
@Override
public String toString() {
    return "ReducedValue(" + field + "," + minWidth + "," + maxWidth +
            "," + Objects.requireNonNullElse(baseDate, baseValue) + ")";
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:DateTimeFormatterBuilder.java

示例3: of

import java.util.Objects; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:ZoneId.java

示例4: from

import java.util.Objects; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:Chronology.java


注:本文中的java.util.Objects.requireNonNullElse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。