diff options
Diffstat (limited to 'guava/src/com/google/common/collect/SingletonImmutableList.java')
-rw-r--r-- | guava/src/com/google/common/collect/SingletonImmutableList.java | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/guava/src/com/google/common/collect/SingletonImmutableList.java b/guava/src/com/google/common/collect/SingletonImmutableList.java index 2e20c41..e546d2b 100644 --- a/guava/src/com/google/common/collect/SingletonImmutableList.java +++ b/guava/src/com/google/common/collect/SingletonImmutableList.java @@ -22,6 +22,7 @@ import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; import java.util.List; +import java.util.NoSuchElementException; import javax.annotation.Nullable; @@ -55,7 +56,47 @@ final class SingletonImmutableList<E> extends ImmutableList<E> { } @Override public int lastIndexOf(@Nullable Object object) { - return indexOf(object); + return element.equals(object) ? 0 : -1; + } + + @Override public UnmodifiableListIterator<E> listIterator(final int start) { + Preconditions.checkPositionIndex(start, 1); + return new UnmodifiableListIterator<E>() { + + boolean hasNext = start == 0; + + @Override public boolean hasNext() { + return hasNext; + } + + @Override public boolean hasPrevious() { + return !hasNext; + } + + @Override public E next() { + if (!hasNext) { + throw new NoSuchElementException(); + } + hasNext = false; + return element; + } + + @Override public int nextIndex() { + return hasNext ? 0 : 1; + } + + @Override public E previous() { + if (hasNext) { + throw new NoSuchElementException(); + } + hasNext = true; + return element; + } + + @Override public int previousIndex() { + return hasNext ? -1 : 0; + } + }; } @Override @@ -76,7 +117,7 @@ final class SingletonImmutableList<E> extends ImmutableList<E> { return element.equals(object); } - @Override public boolean equals(@Nullable Object object) { + @Override public boolean equals(Object object) { if (object == this) { return true; } |