mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8221921: Implement size() / isEmpty() in immutable collections
Reviewed-by: smarks
This commit is contained in:
parent
15d989faa4
commit
f7fa05ca72
1 changed files with 31 additions and 1 deletions
|
@ -403,6 +403,11 @@ class ImmutableCollections {
|
|||
return e1 != null ? 2 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
if (index == 0) {
|
||||
|
@ -480,7 +485,7 @@ class ImmutableCollections {
|
|||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
return elements.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -578,6 +583,11 @@ class ImmutableCollections {
|
|||
return (e1 == null) ? 1 : 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return o.equals(e0) || o.equals(e1); // implicit nullcheck of o
|
||||
|
@ -705,6 +715,11 @@ class ImmutableCollections {
|
|||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
Objects.requireNonNull(o);
|
||||
|
@ -876,6 +891,16 @@ class ImmutableCollections {
|
|||
return o.equals(v0); // implicit nullcheck of o
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
throw new InvalidObjectException("not serial proxy");
|
||||
}
|
||||
|
@ -993,6 +1018,11 @@ class ImmutableCollections {
|
|||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return size == 0;
|
||||
}
|
||||
|
||||
class MapNIterator implements Iterator<Map.Entry<K,V>> {
|
||||
|
||||
private int remaining;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue