本文整理了Java中cn.hutool.core.util.ObjectUtil.defaultIfNull()
方法的一些代码示例,展示了ObjectUtil.defaultIfNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectUtil.defaultIfNull()
方法的具体详情如下:
包路径:cn.hutool.core.util.ObjectUtil
类名称:ObjectUtil
方法名:defaultIfNull
[英]如果给定对象为 null返回默认值
ObjectUtil.defaultIfNull(null, null) = null
ObjectUtil.defaultIfNull(null, "") = ""
ObjectUtil.defaultIfNull(null, "zz") = "zz"
ObjectUtil.defaultIfNull("abc", *) = "abc"
ObjectUtil.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
[中]
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param engine Thymeleaf的模板对象 {@link TemplateEngine}
* @param template 模板路径或模板内容
* @param charset 编码
*/
public ThymeleafTemplate(TemplateEngine engine, String template, Charset charset) {
this.engine = engine;
this.template = template;
this.charset = ObjectUtil.defaultIfNull(charset, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 获取有效的源图片,首先检查上一次处理的结果图片,如无则使用用户传入的源图片
*
* @return 有效的源图片
*/
private BufferedImage getValidSrcImg() {
return ObjectUtil.defaultIfNull(this.targetImage, this.srcImage);
}
代码示例来源:origin: looly/hutool
/**
* 获取有效的源图片,首先检查上一次处理的结果图片,如无则使用用户传入的源图片
*
* @return 有效的源图片
*/
private BufferedImage getValidSrcImg() {
return ObjectUtil.defaultIfNull(this.targetImage, this.srcImage);
}
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param engine Thymeleaf的模板对象 {@link TemplateEngine}
* @param template 模板路径或模板内容
* @param charset 编码
*/
public ThymeleafTemplate(TemplateEngine engine, String template, Charset charset) {
this.engine = engine;
this.template = template;
this.charset = ObjectUtil.defaultIfNull(charset, CharsetUtil.CHARSET_UTF_8);
}
代码示例来源:origin: looly/hutool
/**
* 构造
* @param url URL,允许为空
* @param name 资源名称
*/
public UrlResource(URL url, String name) {
this.url = url;
this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null);
}
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param writer Writer
* @param config 写出配置,null则使用默认配置
*/
public CsvWriter(Writer writer, CsvWriteConfig config) {
this.writer = (writer instanceof BufferedWriter) ? writer : new BufferedWriter(writer);
this.config = ObjectUtil.defaultIfNull(config, CsvWriteConfig.defaultConfig());
}
// --------------------------------------------------------------------------------------------------- Constructor end
代码示例来源:origin: looly/hutool
/**
* CSV解析器
*
* @param reader Reader
* @param config 配置,null则为默认配置
*/
public CsvParser(final Reader reader, CsvReadConfig config) {
this.reader = Objects.requireNonNull(reader, "reader must not be null");
this.config = ObjectUtil.defaultIfNull(config, CsvReadConfig.defaultConfig());
}
代码示例来源:origin: looly/hutool
/**
* 构造
* @param url URL,允许为空
* @param name 资源名称
*/
public UrlResource(URL url, String name) {
this.url = url;
this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null);
}
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param config 配置项
*/
public CsvReader(CsvReadConfig config) {
this.config = ObjectUtil.defaultIfNull(config, CsvReadConfig.defaultConfig());
}
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param writer Writer
* @param config 写出配置,null则使用默认配置
*/
public CsvWriter(Writer writer, CsvWriteConfig config) {
this.writer = (writer instanceof BufferedWriter) ? writer : new BufferedWriter(writer);
this.config = ObjectUtil.defaultIfNull(config, CsvWriteConfig.defaultConfig());
}
// --------------------------------------------------------------------------------------------------- Constructor end
代码示例来源:origin: looly/hutool
/**
* CSV解析器
*
* @param reader Reader
* @param config 配置,null则为默认配置
*/
public CsvParser(final Reader reader, CsvReadConfig config) {
this.reader = Objects.requireNonNull(reader, "reader must not be null");
this.config = ObjectUtil.defaultIfNull(config, CsvReadConfig.defaultConfig());
}
代码示例来源:origin: looly/hutool
/**
* 构造
*
* @param config 配置项
*/
public CsvReader(CsvReadConfig config) {
this.config = ObjectUtil.defaultIfNull(config, CsvReadConfig.defaultConfig());
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link ExcelWriter},默认写出到第一个sheet,名字为sheet1
*
* @param destFile 目标文件
* @return {@link ExcelWriter}
*/
public static ExcelWriter getWriter(File destFile) {
try {
return new ExcelWriter(destFile);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link BigExcelWriter},默认写出到第一个sheet
*
* @param destFilePath 目标文件路径
* @return {@link BigExcelWriter}
*/
public static BigExcelWriter getBigWriter(String destFilePath) {
try {
return new BigExcelWriter(destFilePath);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link ExcelWriter},默认写出到第一个sheet
*
* @param destFilePath 目标文件路径
* @return {@link ExcelWriter}
*/
public static ExcelWriter getWriter(String destFilePath) {
try {
return new ExcelWriter(destFilePath);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link ExcelWriter},默认写出到第一个sheet,名字为sheet1
*
* @param destFile 目标文件
* @return {@link ExcelWriter}
*/
public static ExcelWriter getWriter(File destFile) {
try {
return new ExcelWriter(destFile);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link BigExcelWriter},默认写出到第一个sheet,名字为sheet1
*
* @param destFile 目标文件
* @return {@link BigExcelWriter}
*/
public static BigExcelWriter getBigWriter(File destFile) {
try {
return new BigExcelWriter(destFile);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link BigExcelWriter},默认写出到第一个sheet,名字为sheet1
*
* @param destFile 目标文件
* @return {@link BigExcelWriter}
*/
public static BigExcelWriter getBigWriter(File destFile) {
try {
return new BigExcelWriter(destFile);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link ExcelWriter},默认写出到第一个sheet
*
* @param destFilePath 目标文件路径
* @return {@link ExcelWriter}
*/
public static ExcelWriter getWriter(String destFilePath) {
try {
return new ExcelWriter(destFilePath);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
代码示例来源:origin: looly/hutool
/**
* 获得{@link BigExcelWriter},默认写出到第一个sheet
*
* @param destFilePath 目标文件路径
* @return {@link BigExcelWriter}
*/
public static BigExcelWriter getBigWriter(String destFilePath) {
try {
return new BigExcelWriter(destFilePath);
} catch (NoClassDefFoundError e) {
throw new DependencyException(ObjectUtil.defaultIfNull(e.getCause(), e), PoiChecker.NO_POI_ERROR_MSG);
}
}
内容来源于网络,如有侵权,请联系作者删除!