@Override List<? extends Converter.Factory> defaultConverterFactories() { return Build.VERSION.SDK_INT >= 24 ? singletonList(OptionalConverterFactory.INSTANCE) : Collections.<Converter.Factory>emptyList(); }
@NonNull @Override public List<MediaStoreData> getPreloadItems(int position) { return data.isEmpty() ? Collections.<MediaStoreData>emptyList() : Collections.singletonList(data.get(position)); }
/** * {@inheritDoc} */ public Iterable<? extends List<Class<?>>> batch(List<Class<?>> types) { if (types.isEmpty()) { return Collections.emptyList(); } else { List<List<Class<?>>> batches = new ArrayList<List<Class<?>>>(); int size = types.size() / parts, reminder = types.size() % parts; for (int index = reminder; index < types.size(); index += size) { batches.add(new ArrayList<Class<?>>(types.subList(index, index + size))); } if (batches.isEmpty()) { return Collections.singletonList(types); } else { batches.get(0).addAll(0, types.subList(0, reminder)); return batches; } } } }
private List<Pattern> getNonProxyHostPatterns(@Nullable List<String> nonProxyHosts) { if (nonProxyHosts == null) { return Collections.emptyList(); } final List<Pattern> patterns = new ArrayList<>(nonProxyHosts.size()); for (String nonProxyHost : nonProxyHosts) { // Replaces a wildcard to a regular expression patterns.add(Pattern.compile(WILDCARD.matcher(nonProxyHost).replaceAll(REGEX_WILDCARD))); } return Collections.unmodifiableList(patterns); }
@Override protected List<String> getNonOptionArgs() { List<?> argValues = this.source.nonOptionArguments(); List<String> stringArgValues = new ArrayList<>(); for (Object argValue : argValues) { stringArgValues.add(argValue.toString()); } return (stringArgValues.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(stringArgValues)); }
/** * Assert that the listener identified by the specified id has received the * specified events, in that specific order. */ public void assertEvent(String listenerId, Object... events) { List<Object> actual = this.content.getOrDefault(listenerId, Collections.emptyList()); assertEquals("Wrong number of events", events.length, actual.size()); for (int i = 0; i < events.length; i++) { assertEquals("Wrong event at index " + i, events[i], actual.get(i)); } }
@SuppressWarnings("unchecked") static <T> List<T> getAdviceByType(@Nullable List<Object> requestResponseBodyAdvice, Class<T> adviceType) { if (requestResponseBodyAdvice != null) { List<T> result = new ArrayList<>(); for (Object advice : requestResponseBodyAdvice) { Class<?> beanType = (advice instanceof ControllerAdviceBean ? ((ControllerAdviceBean) advice).getBeanType() : advice.getClass()); if (beanType != null && adviceType.isAssignableFrom(beanType)) { result.add((T) advice); } } return result; } return Collections.emptyList(); }
@Test public void mergeBiFunction() throws Exception { MergerBiFunction<Integer> f = new MergerBiFunction<Integer>(Functions.<Integer>naturalComparator()); assertEquals(0, f.apply(Collections.<Integer>emptyList(), Collections.<Integer>emptyList()).size()); assertEquals(Arrays.asList(1, 2), f.apply(Collections.<Integer>emptyList(), Arrays.asList(1, 2))); for (int i = 0; i < 4; i++) { int k = 0; List<Integer> list1 = new ArrayList<Integer>(); for (int j = 0; j < i; j++) { list1.add(k++); } List<Integer> list2 = new ArrayList<Integer>(); for (int j = i; j < 4; j++) { list2.add(k++); } assertEquals(Arrays.asList(0, 1, 2, 3), f.apply(list1, list2)); } }
/** * Parse the given list of (potentially) comma-separated strings into a * list of {@code MediaType} objects. * <p>This method can be used to parse an Accept or Content-Type header. * @param mediaTypes the string to parse * @return the list of media types * @throws InvalidMediaTypeException if the media type value cannot be parsed * @since 4.3.2 */ public static List<MediaType> parseMediaTypes(@Nullable List<String> mediaTypes) { if (CollectionUtils.isEmpty(mediaTypes)) { return Collections.emptyList(); } else if (mediaTypes.size() == 1) { return parseMediaTypes(mediaTypes.get(0)); } else { List<MediaType> result = new ArrayList<>(8); for (String mediaType : mediaTypes) { result.addAll(parseMediaTypes(mediaType)); } return result; } }
public static List<BlockNode> bitSetToBlocks(MethodNode mth, BitSet bs) { int size = bs.cardinality(); if (size == 0) { return Collections.emptyList(); } List<BlockNode> blocks = new ArrayList<>(size); for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { BlockNode block = mth.getBasicBlocks().get(i); blocks.add(block); } return blocks; }
@Test public void path() throws Exception { // basic testPath("/a/b/c", "/a/b/c", Arrays.asList("/", "a", "/", "b", "/", "c")); // root path testPath("/", "/", Collections.singletonList("/")); // empty path testPath("", "", Collections.emptyList()); testPath("%20%20", "%20%20", Collections.singletonList("%20%20")); // trailing slash testPath("/a/b/", "/a/b/", Arrays.asList("/", "a", "/", "b", "/")); testPath("/a/b//", "/a/b//", Arrays.asList("/", "a", "/", "b", "/", "/")); // extra slashes and spaces testPath("/%20", "/%20", Arrays.asList("/", "%20")); testPath("//%20/%20", "//%20/%20", Arrays.asList("/", "/", "%20", "/", "%20")); }
/** * Returns the value of the {@code Sec-WebSocket-Key} header. * @return the value of the header */ public List<String> getSecWebSocketProtocol() { List<String> values = get(SEC_WEBSOCKET_PROTOCOL); if (CollectionUtils.isEmpty(values)) { return Collections.emptyList(); } else if (values.size() == 1) { return getValuesAsList(SEC_WEBSOCKET_PROTOCOL); } else { return values; } }
@SuppressWarnings("unchecked") // dang varargs @Override <T> Scenario<?> mutate(Scenario<T> scenario) { List<Iterable<T>> words = Lists.newArrayList(); words.add(Collections.<T>emptyList()); for (T t : scenario.strictlyOrderedList) { words.add(Arrays.asList(t)); for (T s : scenario.strictlyOrderedList) { words.add(Arrays.asList(t, s)); } } return new Scenario<Iterable<T>>( scenario.ordering.lexicographical(), words, new Iterable[0]); } },
/** * Returns the value of the {@code Sec-WebSocket-Extensions} header. * @return the value of the header */ public List<WebSocketExtension> getSecWebSocketExtensions() { List<String> values = get(SEC_WEBSOCKET_EXTENSIONS); if (CollectionUtils.isEmpty(values)) { return Collections.emptyList(); } else { List<WebSocketExtension> result = new ArrayList<>(values.size()); for (String value : values) { result.addAll(WebSocketExtension.parseExtensions(value)); } return result; } }
@Test public void request() { TestResourceSubscriber<Integer> tc = new TestResourceSubscriber<Integer>() { @Override protected void onStart() { start++; } }; Flowable.just(1).subscribe(tc); assertEquals(1, tc.start); assertEquals(Collections.emptyList(), tc.values); assertTrue(tc.errors.isEmpty()); assertEquals(0, tc.complete); tc.requestMore(1); assertEquals(1, tc.start); assertEquals(1, tc.values.get(0).intValue()); assertTrue(tc.errors.isEmpty()); assertEquals(1, tc.complete); }
private List<AbstractProject> get(Map<AbstractProject, List<DependencyGroup>> map, AbstractProject src, boolean up) { List<DependencyGroup> v = map.get(src); if(v==null) return Collections.emptyList(); List<AbstractProject> result = new ArrayList<AbstractProject>(v.size()); for (DependencyGroup d : v) result.add(up ? d.getUpstreamProject() : d.getDownstreamProject()); return result; }