/** * 设置失效清理策略 * * @param cleanPolicy 失效清理策略 * @return 构造器 */ public Builder<K, V> cleanPolicy(CleanPolicy cleanPolicy) { Checks.notNull(cleanPolicy, "cleanPolicy can not be null"); this.cleanPolicy = cleanPolicy; return this; }
/** * 设置失效策略 * * @param expiringPolicy 失效策略 * @return 构造器 */ public Builder<K, V> expiringPolicy(ExpiringPolicy expiringPolicy) { Checks.notNull(expiringPolicy, "expiringPolicy can not be null"); this.expiringPolicy = expiringPolicy; return this; }
/** * 非空检查 * * @param obj 校验值 * @param <T> 泛型类 * @return 传入值 */ public static <T> T notNull(T obj) { return notNull(obj, "can not be null"); }
/** * 通过{@link File}创建一个 {@code FileSystemResource} * * @param file 文件 */ public FileSystemResource(File file) { this.file = Checks.notNull(file); }
/** * 校验合法 * * @return conf */ public DataSourceConf validate() { vip.justlive.oxygen.core.util.Checks.notNull(driverClassName, "driverClassName cannot be null"); vip.justlive.oxygen.core.util.Checks.notNull(url, "url cannot be null"); vip.justlive.oxygen.core.util.Checks.notNull(username, "username cannot be null"); return this; }
/** * 增加异步失效监听列表 * * @param listeners 监听 * @return 构造器 */ public Builder<K, V> asyncExpiredListeners(List<ExpiredListener<K, V>> listeners) { Checks.notNull(listeners, "listeners can not be null"); asyncExpiredListeners = listeners; return this; }
/** * 使用{@code URL}创建{@code UrlResource} * * @param url URL */ public UrlResource(URL url) { this.url = Checks.notNull(url); }
/** * Sets the {@link UncaughtExceptionHandler} for new threads created with this ThreadFactory. * * @param uncaughtExceptionHandler the uncaught exception handler for new Threads created with * this ThreadFactory * @return this for the builder pattern */ public ThreadFactoryBuilder setUncaughtExceptionHandler( UncaughtExceptionHandler uncaughtExceptionHandler) { this.uncaughtExceptionHandler = Checks.notNull(uncaughtExceptionHandler); return this; }
/** * Sets the backing {@link ThreadFactory} for new threads created with this ThreadFactory. Threads * will be created by invoking #newThread(Runnable) on this backing {@link ThreadFactory}. * * @param backingThreadFactory the backing {@link ThreadFactory} which will be delegated to during * thread creation. * @return this for the builder pattern */ public ThreadFactoryBuilder setThreadFactory(ThreadFactory backingThreadFactory) { this.backingThreadFactory = Checks.notNull(backingThreadFactory); return this; }
/** * 失败监听,最终失败时触发 * * @param listener 监听 * @return builder */ public RetryBuilder<T> onFinalFail(Consumer<Attempt<T>> listener) { failListeners.add(Checks.notNull(listener)); return this; }
/** * 重试监听,当重试时触发 * * @param listener 监听 * @return builder */ public RetryBuilder<T> onRetry(Consumer<Attempt<T>> listener) { retryListeners.add(Checks.notNull(listener)); return this; }
/** * 通过{@link Path}创建一个 {@code FileSystemResource} * * @param path 路径 */ public FileSystemResource(Path path) { this.path = Checks.notNull(path); this.file = path.toFile(); }
public FixedTimeLimiter(long timeout, TimeUnit timeUnit, ExecutorService executorService) { if (timeout <= 0) { throw new IllegalArgumentException(String.format("timeout must be positive:%s", timeout)); } this.timeout = timeout; this.timeUnit = Checks.notNull(timeUnit); this.executorService = Checks.notNull(executorService); }
/** * 通过文件路径创建一个 {@code FileSystemResource} * * @param filePath 文件路径 */ public FileSystemResource(String filePath) { this.file = new File(Checks.notNull(filePath)); this.filePath = file.toPath().normalize().toString(); }
/** * 替换所有占位格式 {@code ${name}} * * @param value 需要转换的属性 * @param properties 配置集合 * @return 替换后的字符串 */ public String replacePlaceholders(String value, final Properties properties) { Checks.notNull(properties, "'properties' must not be null"); Checks.notNull(value, "'value' must not be null"); return parseStringValue(value, properties, new HashSet<>()); }
/** * 使用{@code ClassLoader}创建{@code ClassPathResource} * * @param path 路径 * @param classLoader 类加载器 */ public ClassPathResource(String path, ClassLoader classLoader) { this.path = this.cutRootPath(Checks.notNull(path)); this.classLoader = classLoader; }
/** * 使用{@code Class}创建{@code ClassPathResource} * * @param path 路径 * @param clazz 类 */ public ClassPathResource(String path, Class<?> clazz) { this.path = this.cutRootPath(Checks.notNull(path)); this.clazz = clazz; }
@SuppressWarnings("unchecked") @Override public ConverterRegistry addConverter(Converter<?, ?> converter) { Checks.notNull(converter); for (ConverterTypePair pair : converter.pairs()) { converters.put(pair, (Converter<Object, Object>) converter); } return this; }
@Override public ConverterRegistry addArrayConverter(ArrayConverter converter) { Checks.notNull(converter); arrayConverters.put(converter.pair(), converter); return this; }
@Override public ConverterRegistry addConverterFactory(ConverterFactory<?, ?> factory) { Checks.notNull(factory); List<Converter<Object, Object>> list = factory.converters(); for (Converter<?, ?> converter : list) { addConverter(converter); } return this; }