49 |
|
import java.util.LinkedHashSet; |
50 |
|
import java.util.LinkedList; |
51 |
|
import java.util.List; |
52 |
+ |
import java.util.ListIterator; |
53 |
|
import java.util.Map; |
54 |
|
import java.util.PriorityQueue; |
55 |
+ |
import java.util.RandomAccess; |
56 |
|
import java.util.Set; |
57 |
|
import java.util.SortedSet; |
58 |
|
import java.util.Spliterator; |
381 |
|
|
382 |
|
db.addList(Vector::new); |
383 |
|
|
384 |
+ |
class AbstractRandomAccessListImpl extends AbstractList<Integer> implements RandomAccess { |
385 |
+ |
Integer[] ia; |
386 |
+ |
|
387 |
+ |
AbstractRandomAccessListImpl(Collection<Integer> c) { |
388 |
+ |
this.ia = c.toArray(new Integer[c.size()]); |
389 |
+ |
} |
390 |
+ |
|
391 |
+ |
@Override |
392 |
+ |
public Integer get(int index) { |
393 |
+ |
return ia[index]; |
394 |
+ |
} |
395 |
+ |
|
396 |
+ |
@Override |
397 |
+ |
public int size() { |
398 |
+ |
return ia.length; |
399 |
+ |
} |
400 |
+ |
} |
401 |
+ |
db.addList(AbstractRandomAccessListImpl::new); |
402 |
+ |
|
403 |
+ |
class RandomAccessListImpl implements List<Integer>, RandomAccess { |
404 |
+ |
Integer[] ia; |
405 |
+ |
List<Integer> l; |
406 |
+ |
|
407 |
+ |
RandomAccessListImpl(Collection<Integer> c) { |
408 |
+ |
this.ia = c.toArray(new Integer[c.size()]); |
409 |
+ |
this.l = Arrays.asList(ia); |
410 |
+ |
} |
411 |
+ |
|
412 |
+ |
@Override |
413 |
+ |
public Integer get(int index) { |
414 |
+ |
return ia[index]; |
415 |
+ |
} |
416 |
+ |
|
417 |
+ |
@Override |
418 |
+ |
public Integer set(int index, Integer element) { |
419 |
+ |
throw new UnsupportedOperationException(); |
420 |
+ |
} |
421 |
+ |
|
422 |
+ |
@Override |
423 |
+ |
public void add(int index, Integer element) { |
424 |
+ |
throw new UnsupportedOperationException(); |
425 |
+ |
} |
426 |
+ |
|
427 |
+ |
@Override |
428 |
+ |
public Integer remove(int index) { |
429 |
+ |
throw new UnsupportedOperationException(); |
430 |
+ |
} |
431 |
+ |
|
432 |
+ |
@Override |
433 |
+ |
public int indexOf(Object o) { |
434 |
+ |
return l.indexOf(o); |
435 |
+ |
} |
436 |
+ |
|
437 |
+ |
@Override |
438 |
+ |
public int lastIndexOf(Object o) { |
439 |
+ |
return Arrays.asList(ia).lastIndexOf(o); |
440 |
+ |
} |
441 |
+ |
|
442 |
+ |
@Override |
443 |
+ |
public ListIterator<Integer> listIterator() { |
444 |
+ |
return l.listIterator(); |
445 |
+ |
} |
446 |
+ |
|
447 |
+ |
@Override |
448 |
+ |
public ListIterator<Integer> listIterator(int index) { |
449 |
+ |
return l.listIterator(index); |
450 |
+ |
} |
451 |
+ |
|
452 |
+ |
@Override |
453 |
+ |
public List<Integer> subList(int fromIndex, int toIndex) { |
454 |
+ |
return l.subList(fromIndex, toIndex); |
455 |
+ |
} |
456 |
+ |
|
457 |
+ |
@Override |
458 |
+ |
public int size() { |
459 |
+ |
return ia.length; |
460 |
+ |
} |
461 |
+ |
|
462 |
+ |
@Override |
463 |
+ |
public boolean isEmpty() { |
464 |
+ |
return size() != 0; |
465 |
+ |
} |
466 |
+ |
|
467 |
+ |
@Override |
468 |
+ |
public boolean contains(Object o) { |
469 |
+ |
return l.contains(o); |
470 |
+ |
} |
471 |
+ |
|
472 |
+ |
@Override |
473 |
+ |
public Iterator<Integer> iterator() { |
474 |
+ |
return l.iterator(); |
475 |
+ |
} |
476 |
+ |
|
477 |
+ |
@Override |
478 |
+ |
public Object[] toArray() { |
479 |
+ |
return l.toArray(); |
480 |
+ |
} |
481 |
+ |
|
482 |
+ |
@Override |
483 |
+ |
public <T> T[] toArray(T[] a) { |
484 |
+ |
return l.toArray(a); |
485 |
+ |
} |
486 |
+ |
|
487 |
+ |
@Override |
488 |
+ |
public boolean add(Integer integer) { |
489 |
+ |
throw new UnsupportedOperationException(); |
490 |
+ |
} |
491 |
+ |
|
492 |
+ |
@Override |
493 |
+ |
public boolean remove(Object o) { |
494 |
+ |
throw new UnsupportedOperationException(); |
495 |
+ |
} |
496 |
+ |
|
497 |
+ |
@Override |
498 |
+ |
public boolean containsAll(Collection<?> c) { |
499 |
+ |
return l.containsAll(c); |
500 |
+ |
} |
501 |
+ |
|
502 |
+ |
@Override |
503 |
+ |
public boolean addAll(Collection<? extends Integer> c) { |
504 |
+ |
throw new UnsupportedOperationException(); |
505 |
+ |
} |
506 |
+ |
|
507 |
+ |
@Override |
508 |
+ |
public boolean addAll(int index, Collection<? extends Integer> c) { |
509 |
+ |
throw new UnsupportedOperationException(); |
510 |
+ |
} |
511 |
+ |
|
512 |
+ |
@Override |
513 |
+ |
public boolean removeAll(Collection<?> c) { |
514 |
+ |
throw new UnsupportedOperationException(); |
515 |
+ |
} |
516 |
+ |
|
517 |
+ |
@Override |
518 |
+ |
public boolean retainAll(Collection<?> c) { |
519 |
+ |
throw new UnsupportedOperationException(); |
520 |
+ |
} |
521 |
+ |
|
522 |
+ |
@Override |
523 |
+ |
public void clear() { |
524 |
+ |
throw new UnsupportedOperationException(); |
525 |
+ |
} |
526 |
+ |
} |
527 |
+ |
db.addList(RandomAccessListImpl::new); |
528 |
|
|
529 |
|
db.addCollection(HashSet::new); |
530 |
|
|