当前位置: 首页>>代码示例>>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;未经允许,请勿转载。