public interface FunctionWithException<T, R, E extends Throwable> { /** * Calls this function. * * @param value The argument to the function. * @return The result of thus supplier. * @throws E This function may throw an exception. */ R apply(T value) throws E; }
2024.10.20 最佳开源项目🔝:googleapis - 知乎 (zhihu.com)
使用
private FileSystem getFileSystem( org.apache.hadoop.fs.Path path, FunctionWithException<org.apache.hadoop.fs.Path, FileSystem, IOException> creator) throws IOException { if (fsMap == null) { synchronized (this) { if (fsMap == null) { fsMap = new ConcurrentHashMap<>(); } } } Map<Pair<String, String>, FileSystem> map = fsMap; URI uri = path.toUri(); String scheme = uri.getScheme(); String authority = uri.getAuthority(); Pair<String, String> key = Pair.of(scheme, authority); FileSystem fs = map.get(key); if (fs == null) { fs = creator.apply(path); map.put(key, fs); } return fs; }
集合中验证重复出现的数据
final Set<String> duplicates = fieldNames.stream() .filter(n -> Collections.frequency(fieldNames, n) > 1) .collect(Collectors.toSet());