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")); }
canonical example by Tabnine
/** * Add new server */ public final void addServer(Server server) { synchronized (SERVERS) { SERVERS.add(server); } }
private void removeAllCanonicalQueryParameters(String canonicalName) { for (int i = encodedQueryNamesAndValues.size() - 2; i >= 0; i -= 2) { if (canonicalName.equals(encodedQueryNamesAndValues.get(i))) { encodedQueryNamesAndValues.remove(i + 1); encodedQueryNamesAndValues.remove(i); if (encodedQueryNamesAndValues.isEmpty()) { encodedQueryNamesAndValues = null; return; } } } }
@Test public void startWithIterable() { List<String> li = new ArrayList<String>(); li.add("alpha"); li.add("beta"); List<String> values = Observable.just("one", "two").startWith(li).toList().blockingGet(); assertEquals("alpha", values.get(0)); assertEquals("beta", values.get(1)); assertEquals("one", values.get(2)); assertEquals("two", values.get(3)); }
@Override public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException { Handshake handshake = handshake(); if (handshake == null) return null; List<Certificate> result = handshake.peerCertificates(); return !result.isEmpty() ? result.toArray(new Certificate[result.size()]) : null; }
public static <E> MinimalSet<E> ofClassAndContents( Class<? super E> type, E[] emptyArrayForContents, Iterable<? extends E> contents) { List<E> setContents = new ArrayList<E>(); for (E e : contents) { if (!setContents.contains(e)) { setContents.add(e); } } return new MinimalSet<E>(type, setContents.toArray(emptyArrayForContents)); }
/** Returns a snapshot of the calls currently being executed. */ public synchronized List<Call> runningCalls() { List<Call> result = new ArrayList<>(); result.addAll(runningSyncCalls); for (AsyncCall asyncCall : runningAsyncCalls) { result.add(asyncCall.get()); } return Collections.unmodifiableList(result); }
Burst(Throwable error, List<T> items) { if (items.isEmpty()) { throw new IllegalArgumentException("items cannot be empty"); } for (T item : items) { if (item == null) { throw new IllegalArgumentException("items cannot include null"); } } this.error = error; this.items = items; }
/** * Can be used to collect objects from the Iterable. Is a terminating operation. * * @return an option of the last object of the Iterable */ @Override public final Optional<E> last() { List<E> list = last(1).asList(); if (list.isEmpty()) { return Optional.empty(); } return Optional.of(list.get(0)); }
@Test public void merge1AsyncStreamOf1() { TestObserver<Integer> to = new TestObserver<Integer>(); mergeNAsyncStreamsOfN(1, 1).subscribe(to); to.awaitTerminalEvent(); to.assertNoErrors(); assertEquals(1, to.values().size()); }
public static List<String> allSubjectAltNames(X509Certificate certificate) { List<String> altIpaNames = getSubjectAltNames(certificate, ALT_IPA_NAME); List<String> altDnsNames = getSubjectAltNames(certificate, ALT_DNS_NAME); List<String> result = new ArrayList<>(altIpaNames.size() + altDnsNames.size()); result.addAll(altIpaNames); result.addAll(altDnsNames); return result; }
public static void assertContainsAllOf(Iterable<?> actual, Object... expected) { List<Object> expectedList = new ArrayList<>(); expectedList.addAll(Arrays.asList(expected)); for (Object o : actual) { expectedList.remove(o); } if (!expectedList.isEmpty()) { Assert.fail("Not true that " + actual + " contains all of " + Arrays.asList(expected)); } }
public EquivalenceTester<T> addEquivalenceGroup(Iterable<T> group) { delegate.addRelatedGroup(group); items.addAll(ImmutableList.copyOf(group)); return this; }