mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ContainerUtil.unmodifiableOrEmpty* methods optimized for 1-element collections
This commit is contained in:
@@ -212,6 +212,9 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
if (size == 0) {
|
||||
return emptyList();
|
||||
}
|
||||
if (size == 1) {
|
||||
return Collections.singletonList(original.iterator().next());
|
||||
}
|
||||
else {
|
||||
return Collections.unmodifiableCollection(original);
|
||||
}
|
||||
@@ -224,6 +227,9 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
if (size == 0) {
|
||||
return emptyList();
|
||||
}
|
||||
if (size == 1) {
|
||||
return Collections.singletonList(original.iterator().next());
|
||||
}
|
||||
else {
|
||||
return Collections.unmodifiableList(original);
|
||||
}
|
||||
@@ -236,6 +242,9 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
if (size == 0) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if (size == 1) {
|
||||
return Collections.singleton(original.iterator().next());
|
||||
}
|
||||
else {
|
||||
return Collections.unmodifiableSet(original);
|
||||
}
|
||||
@@ -248,6 +257,10 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
if (size == 0) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
if (size == 1) {
|
||||
Map.Entry<? extends K, ? extends V> entry = original.entrySet().iterator().next();
|
||||
return Collections.singletonMap(entry.getKey(), entry.getValue());
|
||||
}
|
||||
else {
|
||||
return Collections.unmodifiableMap(original);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user