canonical example by Tabnine
public long getDirectorySize(File file) { if (!file.exists()) { return 0; } if (file.isFile()) { return file.length(); } File[] files; if (!file.isDirectory() || (files = file.listFiles()) == null) { return 0; } return Arrays.stream(files).mapToLong(f -> getDirectorySize(f)).sum(); }
/** * get routed invokers from result of script rule evaluation */ @SuppressWarnings("unchecked") protected <T> List<Invoker<T>> getRoutedInvokers(Object obj) { if (obj instanceof Invoker[]) { return Arrays.asList((Invoker<T>[]) obj); } else if (obj instanceof Object[]) { return Arrays.stream((Object[]) obj).map(item -> (Invoker<T>) item).collect(Collectors.toList()); } else { return (List<Invoker<T>>) obj; } }
public void setCookies(@Nullable Cookie... cookies) { this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies); this.headers.remove(HttpHeaders.COOKIE); if (this.cookies != null) { Arrays.stream(this.cookies) .map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue())) .forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false)); } }
private static Method getSingleApplyMethod(Class lambdaFunctionInterface) { checkCondition(lambdaFunctionInterface.isAnnotationPresent(FunctionalInterface.class), COMPILER_ERROR, "Lambda function interface is required to be annotated with FunctionalInterface"); List<Method> applyMethods = Arrays.stream(lambdaFunctionInterface.getMethods()) .filter(method -> method.getName().equals("apply")) .collect(toImmutableList()); checkCondition(applyMethods.size() == 1, COMPILER_ERROR, "Expect to have exactly 1 method with name 'apply' in interface " + lambdaFunctionInterface.getName()); return applyMethods.get(0); }
/** * get routed invokers from result of script rule evaluation */ @SuppressWarnings("unchecked") protected <T> List<Invoker<T>> getRoutedInvokers(Object obj) { if (obj instanceof Invoker[]) { return Arrays.asList((Invoker<T>[]) obj); } else if (obj instanceof Object[]) { return Arrays.stream((Object[]) obj).map(item -> (Invoker<T>) item).collect(Collectors.toList()); } else { return (List<Invoker<T>>) obj; } }
@Nullable private String getContentCodingKey(HttpServletRequest request) { String header = request.getHeader(HttpHeaders.ACCEPT_ENCODING); if (!StringUtils.hasText(header)) { return null; } return Arrays.stream(StringUtils.tokenizeToStringArray(header, ",")) .map(token -> { int index = token.indexOf(';'); return (index >= 0 ? token.substring(0, index) : token).trim().toLowerCase(); }) .filter(this.contentCodings::contains) .sorted() .collect(Collectors.joining(",")); }
public void setCookies(@Nullable Cookie... cookies) { this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies); this.headers.remove(HttpHeaders.COOKIE); if (this.cookies != null) { Arrays.stream(this.cookies) .map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue())) .forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false)); } }
public List<String> getIndices(ElasticsearchTableDescription tableDescription) { if (tableDescription.getIndexExactMatch()) { return ImmutableList.of(tableDescription.getIndex()); } TransportClient client = clients.get(tableDescription.getClusterName()); verify(client != null, "client is null"); String[] indices = getIndices(client, new GetIndexRequest()); return Arrays.stream(indices) .filter(index -> index.startsWith(tableDescription.getIndex())) .collect(toImmutableList()); }