本文整理了Java中java.util.Collections.emptyList()
方法的一些代码示例,展示了Collections.emptyList()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.emptyList()
方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:emptyList
[英]Returns a type-safe empty, immutable List.
[中]返回类型安全的空不可变列表。
代码示例来源:origin: square/retrofit
@Override List<? extends Converter.Factory> defaultConverterFactories() {
return Build.VERSION.SDK_INT >= 24
? singletonList(OptionalConverterFactory.INSTANCE)
: Collections.<Converter.Factory>emptyList();
}
代码示例来源:origin: spring-projects/spring-framework
private Object formatLocations() {
if (!this.locationValues.isEmpty()) {
return this.locationValues.stream().collect(Collectors.joining("\", \"", "[\"", "\"]"));
}
else if (!this.locations.isEmpty()) {
return "[" + this.locations + "]";
}
return Collections.emptyList();
}
}
代码示例来源:origin: bumptech/glide
@NonNull
@Override
public List<MediaStoreData> getPreloadItems(int position) {
return data.isEmpty()
? Collections.<MediaStoreData>emptyList()
: Collections.singletonList(data.get(position));
}
代码示例来源:origin: redisson/redisson
/**
* {@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;
}
}
}
}
代码示例来源:origin: dropwizard/dropwizard
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);
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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));
}
}
代码示例来源:origin: spring-projects/spring-framework
@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();
}
代码示例来源:origin: ReactiveX/RxJava
@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));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Iterable<Integer> apply(Integer v) throws Exception {
if ((v & 1) == 0) {
return Collections.emptyList();
}
return Arrays.asList(1, 2);
}
})
代码示例来源:origin: spring-projects/spring-framework
/**
* 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;
}
}
代码示例来源:origin: skylot/jadx
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;
}
代码示例来源:origin: google/guava
public void testPartition_empty() {
List<Integer> source = Collections.emptyList();
List<List<Integer>> partitions = Lists.partition(source, 1);
assertTrue(partitions.isEmpty());
assertEquals(0, partitions.size());
}
代码示例来源:origin: spring-projects/spring-framework
@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"));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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;
}
}
代码示例来源:origin: google/guava
@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]);
}
},
代码示例来源:origin: spring-projects/spring-framework
/**
* 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;
}
}
代码示例来源:origin: ReactiveX/RxJava
@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);
}
代码示例来源:origin: skylot/jadx
public List<LoopInfo> getAllLoopsForBlock(BlockNode block) {
if (loops.isEmpty()) {
return Collections.emptyList();
}
List<LoopInfo> list = new ArrayList<>(loops.size());
for (LoopInfo loop : loops) {
if (loop.getLoopBlocks().contains(block)) {
list.add(loop);
}
}
return list;
}
代码示例来源:origin: jenkinsci/jenkins
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;
}
内容来源于网络,如有侵权,请联系作者删除!