canonical example by Tabnine
@Override public CacheInvocationParameter[] getAllParameters(Object... values) { if (this.allParameterDetails.size() != values.length) { throw new IllegalStateException("Values mismatch, operation has " + this.allParameterDetails.size() + " parameter(s) but got " + values.length + " value(s)"); } List<CacheInvocationParameter> result = new ArrayList<>(); for (int i = 0; i < this.allParameterDetails.size(); i++) { result.add(this.allParameterDetails.get(i).toCacheInvocationParameter(values[i])); } return result.toArray(new CacheInvocationParameter[0]); }
@Test public void testSkipAndCountGaplessWindows() { Observable<String> subject = Observable.just("one", "two", "three", "four", "five"); Observable<Observable<String>> windowed = subject.window(3, 3); List<List<String>> windows = toLists(windowed); assertEquals(2, windows.size()); assertEquals(list("one", "two", "three"), windows.get(0)); assertEquals(list("four", "five"), windows.get(1)); }
public static List<String> alpnProtocolNames(List<Protocol> protocols) { List<String> names = new ArrayList<>(protocols.size()); for (int i = 0, size = protocols.size(); i < size; i++) { Protocol protocol = protocols.get(i); if (protocol == Protocol.HTTP_1_0) continue; // No HTTP/1.0 for ALPN. names.add(protocol.toString()); } return names; }
static String extractStatusLine(Map<String, List<String>> javaResponseHeaders) throws ProtocolException { List<String> values = javaResponseHeaders.get(null); if (values == null || values.size() == 0) { // The status line is missing. This suggests a badly behaving cache. throw new ProtocolException( "CacheResponse is missing a \'null\' header containing the status line. Headers=" + javaResponseHeaders); } return values.get(0); }
public static String getVerticalFormattedOutput(List<Map<String, Object>> content, String[] titleFields) { List<String[]> printContents = new ArrayList<String[]>(); int maxCol = content.size() > MAX_COL ? MAX_COL : content.size(); for (String titleField : titleFields) { String[] row = new String[maxCol + 1]; row[0] = titleField; for (int j = 0; j < maxCol; j++) { Map<String, Object> sqlStat = content.get(j); Object value = sqlStat.get(titleField); row[j + 1] = handleAndConvert(value, titleField); } printContents.add(row); } return TableFormatter.format(printContents); }
@Test public void sortByQualityUnrelated() { MediaType audioBasic = new MediaType("audio", "basic"); MediaType audioWave = new MediaType("audio", "wave"); MediaType textHtml = new MediaType("text", "html"); List<MediaType> expected = new ArrayList<>(); expected.add(textHtml); expected.add(audioBasic); expected.add(audioWave); List<MediaType> result = new ArrayList<>(expected); MediaType.sortBySpecificity(result); for (int i = 0; i < result.size(); i++) { assertSame("Invalid media type at " + i, expected.get(i), result.get(i)); } }
/** * Return all configured {@link MappedInterceptor MappedInterceptors} as an array. * @return the array of {@link MappedInterceptor MappedInterceptors}, or {@code null} if none */ @Nullable protected final MappedInterceptor[] getMappedInterceptors() { List<MappedInterceptor> mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size()); for (HandlerInterceptor interceptor : this.adaptedInterceptors) { if (interceptor instanceof MappedInterceptor) { mappedInterceptors.add((MappedInterceptor) interceptor); } } return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null); }
private static Profiles merge(String expression, List<Profiles> elements, @Nullable Operator operator) { assertWellFormed(expression, !elements.isEmpty()); if (elements.size() == 1) { return elements.get(0); } Profiles[] profiles = elements.toArray(new Profiles[0]); return (operator == Operator.AND ? and(profiles) : or(profiles)); }
@Ignore // passes under Eclipse, fails under Ant @Test public void classpathStarWithPatternOnFileSystem() throws IOException { Resource[] resources = resolver.getResources("classpath*:org/springframework/core/io/sup*/*.class"); // Have to exclude Clover-generated class files here, // as we might be running as part of a Clover test run. List<Resource> noCloverResources = new ArrayList<>(); for (Resource resource : resources) { if (!resource.getFilename().contains("$__CLOVER_")) { noCloverResources.add(resource); } } resources = noCloverResources.toArray(new Resource[noCloverResources.size()]); assertProtocolAndFilenames(resources, "file", StringUtils.concatenateStringArrays(CLASSES_IN_CORE_IO_SUPPORT, TEST_CLASSES_IN_CORE_IO_SUPPORT)); }
@Test(timeout = 1000) public void testCompositeExceptionFromTwoDuplicateComposites() { List<Throwable> exs = new ArrayList<Throwable>(); exs.add(getNewCompositeExceptionWithEx123()); exs.add(getNewCompositeExceptionWithEx123()); CompositeException cex = new CompositeException(exs); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(3, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@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; }
@Override ImmutableSet<?> create(List<?> list) { Object o1 = list.get(0); Object o2 = list.get(1); Object o3 = list.get(2); Object o4 = list.get(3); Object o5 = list.get(4); Object o6 = list.get(5); Object[] rest = list.subList(6, list.size()).toArray(); return ImmutableSet.of(o1, o2, o3, o4, o5, o6, rest); } },
@Test public void merge10AsyncStreamOf1000() { TestObserver<Integer> to = new TestObserver<Integer>(); mergeNAsyncStreamsOfN(10, 1000).subscribe(to); to.awaitTerminalEvent(); to.assertNoErrors(); assertEquals(10000, to.values().size()); }
static <E> List<List<E>> create(List<? extends List<? extends E>> lists) { ImmutableList.Builder<List<E>> axesBuilder = new ImmutableList.Builder<>(lists.size()); for (List<? extends E> list : lists) { List<E> copy = ImmutableList.copyOf(list); if (copy.isEmpty()) { return ImmutableList.of(); } axesBuilder.add(copy); } return new CartesianList<E>(axesBuilder.build()); }