Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.vaadin.addons.lazyquerycontainer;
- import java.util.AbstractList;
- import java.util.RandomAccess;
- public class NaturalNumbersList extends AbstractList<Integer> implements
- RandomAccess, java.io.Serializable {
- private static final long serialVersionUID = -2764017481108945198L;
- private final int size;
- public NaturalNumbersList(int size) {
- this.size = size;
- }
- public int size() {
- return size;
- }
- public Integer[] toArray() {
- Integer[] array = new Integer[size];
- for (int i=0; i<size; i++)
- array[i] = i;
- return array;
- }
- @SuppressWarnings("unchecked")
- public <T> T[] toArray(T[] a) {
- if (a.length < size)
- a = (T[]) new Integer[size];
- for (int i=0; i<size; i++)
- a[i] = (T)Integer.valueOf(i);
- if (a.length > size)
- a[size] = null;
- return a;
- }
- public Integer get(int index) {
- if (index<0 || index>=size)
- throw new IndexOutOfBoundsException();
- return index;
- }
- public Integer set(int index, Integer element) {
- throw new UnsupportedOperationException();
- }
- public int indexOf(Object o) {
- if (o == null)
- return -1;
- if (o instanceof Integer){
- int i = (Integer) o;
- if (i<0 || i>= size)
- return -1;
- return i;
- }
- return -1;
- }
- public boolean contains(Object o) {
- return indexOf(o) != -1;
- }
- }
Add Comment
Please, Sign In to add comment