canonical example by Tabnine
private void mappingWordsLength(List<String> wordsList) { Map<Integer, Set<String>> mapping = new HashMap<>(); for (String word : wordsList) { mapping.computeIfAbsent(word.length(), HashSet::new).add(word); } List<Integer> lengths = new LinkedList<>(mapping.keySet()); Collections.sort(lengths); lengths.forEach(n -> System.out.println(mapping.get(n).size() + " words with " + n + " chars")); }
@Override public Iterable<Integer> apply(Integer v) throws Exception { return Collections.<Integer>emptyList(); } })
@Override public List<T> apply(List<T> v) { Collections.sort(v, comparator); return v; } }
@Override List<? extends Converter.Factory> defaultConverterFactories() { return Build.VERSION.SDK_INT >= 24 ? singletonList(OptionalConverterFactory.INSTANCE) : Collections.<Converter.Factory>emptyList(); }
private static <K, V> Map<K, V> unmodifiableMap(Map<K, ? extends V> map) { if (map instanceof SortedMap) { return Collections.unmodifiableSortedMap((SortedMap<K, ? extends V>) map); } else { return Collections.unmodifiableMap(map); } }
private static Iterable<File> fileTreeChildren(File file) { // check isDirectory() just because it may be faster than listFiles() on a non-directory if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { return Collections.unmodifiableList(Arrays.asList(files)); } } return Collections.emptyList(); }
List<? extends CallAdapter.Factory> defaultCallAdapterFactories( @Nullable Executor callbackExecutor) { if (callbackExecutor != null) { return singletonList(new ExecutorCallAdapterFactory(callbackExecutor)); } return singletonList(DefaultCallAdapterFactory.INSTANCE); }
/** Trusted constructor assumes ownership of {@code arguments}. */ Invocation(Method method, List<?> arguments) { this.method = method; this.arguments = Collections.unmodifiableList(arguments); }
Builder(Request request) { this.url = request.url; this.method = request.method; this.body = request.body; this.tags = request.tags.isEmpty() ? Collections.emptyMap() : new LinkedHashMap<>(request.tags); this.headers = request.headers.newBuilder(); }
@Override public Map<Object, Object> apply(Map<Object, Object> input) { return Collections.unmodifiableMap(input); } };
/** Returns an immutable copy of {@code map}. */ public static <K, V> Map<K, V> immutableMap(Map<K, V> map) { return map.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(new LinkedHashMap<>(map)); }
public void testPartition_singleton1() { Iterable<Integer> source = Collections.singleton(1); Iterable<List<Integer>> partitions = Iterables.partition(source, 1); assertEquals(1, Iterables.size(partitions)); assertEquals(Collections.singletonList(1), partitions.iterator().next()); }
@Override public List<String> order(List<String> insertionOrder) { Collections.sort(insertionOrder, Collections.reverseOrder()); return insertionOrder; } }
public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod> supportedMethods) { super(HttpStatus.METHOD_NOT_ALLOWED, "Request method '" + method + "' not supported"); Assert.notNull(method, "'method' is required"); if (supportedMethods == null) { supportedMethods = Collections.emptySet(); } this.method = method; this.supportedMethods = Collections.unmodifiableSet(new HashSet<>(supportedMethods)); }
@Override public List<String> create(String[] elements) { List<String> innerList = new ArrayList<>(); Collections.addAll(innerList, elements); return Collections.unmodifiableList(innerList); } })
@Override public Iterable<Integer> apply(Object v) throws Exception { return Collections.singleton(1); } }));
@Override public Set<K> keySet() { Set<K> result = keySet; if (result == null) { keySet = result = Collections.unmodifiableSet(delegate.keySet()); } return result; }
@Override public Set<Feature<? super Void>> getImpliedFeatures() { return Collections.emptySet(); } }