Created
November 30, 2010 13:28
-
-
Save HRE/721672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119,123c119,120 | |
< ArrayList<Integer> ids=new ArrayList<Integer>(size()); | |
< for(int i=0;i<size();i++) { | |
< ids.add(i); | |
< } | |
< return ids; | |
--- | |
> | |
> return new NaturalNumbersList(size()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment