|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection<E> java.util.AbstractList<E> java.util.ArrayList<TableList.Fields> org.knowceans.util.TableList
public class TableList
TableList handles parallel lists whose elements with same index can be accessed, sorted, filtered etc. simultaneously. Internally, each element of the list is a list on its own, representing the fields of the list. The contract is that these element lists are of equal size when manipulating single elements. Filtering operations are provided via the filter method and Filter interface as well as the indices() methods.
This class is optimised for coding rather than runtime efficiency. Particularly, manipulating the structure of the fields (columns) is expensive as it iterates through all rows. Sorting, shuffling etc. are provided by the static Collections methods. To find rows of large lists, first sort and then do binary search via the collections interface.
Nested Class Summary | |
---|---|
class |
TableList.FieldBetween
FieldBetween checks if the field is between low and high value. |
class |
TableList.FieldComparator
FieldSorter sorts fields according to a numeric field. |
class |
TableList.FieldEquals
FieldEquals is an equals condition |
class |
TableList.FieldGreaterThan
FieldLargerThan checks if field larger than value. |
class |
TableList.FieldLessThan
FieldLessThan checks if field less than. |
class |
TableList.FieldRegexFind
FieldRegexFind matches field with the regular expression. |
class |
TableList.Fields
Fields extends an array list by a comparison capability over the map list. |
static interface |
TableList.Filter
Filter allows to filter entries by calling filter with an implementation of this interface. |
class |
TableList.SingleFieldFilter
SingleFieldFilter represents the common case of filtering according to the value of one field. |
Constructor Summary | |
---|---|
TableList()
|
|
TableList(int initialCapacity)
|
|
TableList(java.util.List<TableList.Fields> list,
java.util.List<java.lang.String> fields)
Initialise the parallel list with an existing list. |
|
TableList(TableList list)
Copy constructor. |
Method Summary | |
---|---|
void |
addIndexList(java.lang.String field)
Add an index plus to the list. |
void |
addIndexList(java.lang.String field,
int offset)
Adds an index plus an offset to the list. |
void |
addList(java.lang.String field,
java.util.List<? extends java.lang.Object> a)
Add a list to the internal maps. |
void |
addMap(java.lang.String keyfield,
java.lang.String valfield,
java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
Add the keys and values of the map to this table list, in the order that the map iterator provides. |
int |
binarySearch(java.lang.String field,
java.lang.Object key)
Perform a binary search on the field. |
int |
binarySearch(java.lang.String field,
java.lang.Object key,
TableList.FieldComparator comp)
Perform a binary search, specifying the condition with a Comparator. |
TableList |
filter(TableList.Filter filt)
Get a sublist of this list according to the filter criterion. |
java.lang.Object |
get(int field,
int index)
Get one element of the list with the specified key. |
java.lang.Object |
get(java.lang.String field,
int index)
Get one element of the list with the specified key. |
java.lang.String |
getField(int field)
Get key of field index. |
int |
getField(java.lang.String field)
Get field index of key. |
java.util.List<java.lang.String> |
getFields()
Get the field names of the table list. |
java.util.ArrayList<?> |
getList(int index)
Get the list with the specified key. |
java.util.ArrayList<?> |
getList(java.lang.String field)
Get the list with the specified key. |
void |
getMap(java.lang.String keyfield,
java.lang.String valfield,
java.util.Map map)
Get a map representation of the keys and values fields. |
TableList |
getSubList(int fromIndex,
int toIndex)
Get a sublist of this list according to the indices of the current sorting, as a copy. |
int |
indexOf(java.lang.String field,
java.lang.Object key)
Find the first index the field matches with key. |
int |
indexOf(TableList.Filter filt)
Find the first index valid for the filter. |
int[] |
indicesOf(java.lang.String field,
java.lang.Object key)
Find all indices that the field matches with key. |
int[] |
indicesOf(TableList.Filter filt)
Find all indices that are valid for the filter. |
int |
lastIndexOf(java.lang.String field,
java.lang.Object key)
Find the last index the field matches with key. |
int |
lastIndexOf(TableList.Filter filt)
Find the last index that is valid for the filter. |
static TableList |
load(java.lang.String file)
Initialise the table list from the file. |
static void |
main(java.lang.String[] args)
|
void |
removeList(java.lang.String field)
Remove the list with key from the internal maps. |
void |
save(java.lang.String file)
Save the table list to a file. |
void |
set(int field,
int index,
java.lang.Object value)
Set the field at the index with the value. |
void |
set(java.lang.String field,
int index,
java.lang.Object value)
Set the field at the index with the value. |
TableList |
sort(java.util.Comparator<TableList.Fields> comp)
Sort the table with the specific comparator given. |
TableList |
sort(java.lang.String field,
boolean reverse)
Sort the table list by the specified field. |
TableList[] |
split(TableList.Filter filt)
Get two sublists of this list according to the filter criterion. |
java.lang.Object[] |
toArray(java.lang.String field)
Get an object array of the field. |
Methods inherited from class java.util.ArrayList |
---|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, set, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
---|
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, removeAll, retainAll, toString |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList |
Constructor Detail |
---|
public TableList()
public TableList(int initialCapacity)
initialCapacity
- public TableList(java.util.List<TableList.Fields> list, java.util.List<java.lang.String> fields)
list
- field
- public TableList(TableList list)
list
- Method Detail |
---|
public static void main(java.lang.String[] args)
args
- public static TableList load(java.lang.String file)
file
-
java.lang.ClassNotFoundException
java.io.IOException
public void save(java.lang.String file)
file
- public void addList(java.lang.String field, java.util.List<? extends java.lang.Object> a)
a
- public void addIndexList(java.lang.String field, int offset)
field
- public void addIndexList(java.lang.String field)
field
- public void addMap(java.lang.String keyfield, java.lang.String valfield, java.util.Map<? extends java.lang.Object,? extends java.lang.Object> map)
keyfield
- name of the field for the keysvalfield
- name of the field for the values.map
- public void getMap(java.lang.String keyfield, java.lang.String valfield, java.util.Map map)
keyfield
- valfield
- public void removeList(java.lang.String field)
field
- public java.util.ArrayList<?> getList(java.lang.String field)
index
- public java.util.ArrayList<?> getList(int index)
index
- public java.lang.Object get(int field, int index)
field
- index
-
public java.lang.Object get(java.lang.String field, int index)
field
- index
-
public void set(int field, int index, java.lang.Object value)
field
- index
- value
- public void set(java.lang.String field, int index, java.lang.Object value)
field
- index
- value
- public TableList getSubList(int fromIndex, int toIndex)
filt
-
public java.lang.Object[] toArray(java.lang.String field)
field
-
public TableList filter(TableList.Filter filt)
filt
-
public TableList[] split(TableList.Filter filt)
filt
-
public int[] indicesOf(java.lang.String field, java.lang.Object key)
field
- key
-
public int[] indicesOf(TableList.Filter filt)
filt
-
public int indexOf(java.lang.String field, java.lang.Object key)
field
- key
-
public int indexOf(TableList.Filter filt)
filt
-
public int lastIndexOf(java.lang.String field, java.lang.Object key)
field
- key
-
public int lastIndexOf(TableList.Filter filt)
key
- filt
-
public int binarySearch(java.lang.String field, java.lang.Object key)
field
- key
-
public int binarySearch(java.lang.String field, java.lang.Object key, TableList.FieldComparator comp)
comparator
-
public TableList sort(java.lang.String field, boolean reverse)
field
- reverse
-
public TableList sort(java.util.Comparator<TableList.Fields> comp)
comp
-
public int getField(java.lang.String field)
field
-
public java.lang.String getField(int field)
field
-
public java.util.List<java.lang.String> getFields()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |