MCPcopy Create free account
hub / github.com/davidgiven/luje / SingletonSet

Class SingletonSet

lib/java/util/Collections.java:237–279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

235 }
236
237 private static final class SingletonSet<E> extends AbstractSet<E> implements
238 Serializable {
239 private static final long serialVersionUID = 3193687207550431679L;
240
241 final E element;
242
243 SingletonSet(E object) {
244 element = object;
245 }
246
247 @Override
248 public boolean contains(Object object) {
249 return element == null ? object == null : element.equals(object);
250 }
251
252 @Override
253 public int size() {
254 return 1;
255 }
256
257 @Override
258 public Iterator<E> iterator() {
259 return new Iterator<E>() {
260 boolean hasNext = true;
261
262 public boolean hasNext() {
263 return hasNext;
264 }
265
266 public E next() {
267 if (hasNext) {
268 hasNext = false;
269 return element;
270 }
271 throw new NoSuchElementException();
272 }
273
274 public void remove() {
275 throw new UnsupportedOperationException();
276 }
277 };
278 }
279 }
280
281 private static final class SingletonList<E> extends AbstractList<E>
282 implements Serializable {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected