Type
- public class IndexMultiTable<Key extends java.lang.Comparable<Key>,Type> extends IndexMultiTable_Table<Key,Type> implements java.util.Map<Key,Type>, java.lang.Iterable<Type>
TreeMap
.
In opposite to a TreeMap
the key need not be unique for all values.
More as one value can have the same key. The method get(Object)
defined in
Map
searches the first Object with the given key.
The method put(Comparable, Object)
replaces an existing value with the same key like defined in Map
where the methods add(Comparable, Object)
, addBefore(Comparable, Object, Object)
and append(Comparable, Object)
puts the new value with an existing key beside the last existing one.
iterator(Comparable)
which starts on the first occurrence of the search key
or after that key which is one lesser as the key.
It iterates both to the end or backward of the whole collection. The user can check the key in the returned Map.Entry
whether the key is proper. In this kind a sorted view of a part of the content can be done.
Table
contains the table of objects and the table of key of type Comparable.
The tables are simple arrays of a fix size.
Modifier and Type | Class and Description |
---|---|
protected class |
IndexMultiTable.Entry |
protected class |
IndexMultiTable.EntrySetIterator |
(package private) class |
IndexMultiTable.IndexBox |
private static class |
IndexMultiTable.IteratorHelper<Key extends java.lang.Comparable<Key>,Type>
This class contains the data for a
IndexMultiTable.IteratorImpl
for one table. |
protected class |
IndexMultiTable.IteratorImpl
This class is the Iterator for the outer class.
|
(package private) static class |
IndexMultiTable.KindofAdd |
static interface |
IndexMultiTable.Provide<Key>
This interface is necessary to provide tables and the minimum and maximum value for any user specific type.
|
private static class |
IndexMultiTable.XXXTable<Key extends java.lang.Comparable<Key>,Type>
One table contains keys and values in two array lists in sorted order.
|
Modifier and Type | Field and Description |
---|---|
(package private) java.util.Set<java.util.Map.Entry<Key,Type>> |
entrySet |
(package private) Key |
maxKey__ |
(package private) Key |
minKey__ |
private int |
modcount
modification access counter for Iterator.
|
(package private) IndexMultiTable.Provide<Key> |
provider |
static IndexMultiTable.Provide<java.lang.String> |
providerString
Provider for String keys.
|
(package private) boolean |
shouldCheck |
static java.lang.String |
sVersion
Version, history and license.
|
aKeys, aValues, identParent, identParent_, isHyperBlock, ixInParent, maxBlock, parent, rootIdxTable, sizeAll, sizeBlock
Constructor and Description |
---|
IndexMultiTable(IndexMultiTable.Provide<Key> provider)
constructs an empty instance without data.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Key key,
Type value)
Adds the (key - value) pair to the container.
|
void |
addBefore(Key key,
Type value,
Type valueNext)
Adds the (key - value) pair to the container.
|
void |
append(Key key,
Type obj)
Appends the (key - value) pair to the container.
|
int |
checkIndex()
Executes a consistency check.
|
void |
checkTable()
Checks the consistency of the table.
|
void |
clear()
Delete all content.
|
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object arg0) |
java.util.Set<java.util.Map.Entry<Key,Type>> |
entrySet() |
Type |
get(java.lang.Object keyArg) |
boolean |
isEmpty() |
java.util.ListIterator<Type> |
iterator()
Returns an iterator over the table.
|
java.util.ListIterator<Type> |
iterator(Key fromKey)
Creates an iterator which is placed in the occurrence of the given key.
|
java.util.Set<Key> |
keySet() |
Type |
put(Key key,
Type value)
Puts the (key - value) pair to the container.
|
void |
putAll(java.util.Map<? extends Key,? extends Type> m) |
Type |
remove(java.lang.Object keyArg) |
Type |
search(Key key)
Searches the object with exact this key or the object which's key is the nearest lesser one.
|
Type |
search(Key keyArg,
boolean exact,
boolean[] retFound)
Searches the key in the tables.
|
void |
shouldCheck(boolean val)
Enables or disables a check.
|
int |
size() |
(package private) void |
stop() |
java.lang.String |
toString() |
java.util.Collection<Type> |
values() |
binarySearchFirstKey, check, checkTable, clearRestArray, compare, delete, movein, putOrAdd, searchAndSortin, searchbackAndSortin, searchInTables, searchLastAndSortin, sortin
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public static final java.lang.String sVersion
IndexMultiTable.IteratorImpl
has start from the next table instead hyper table with lesser key. Presume it was never tested well.
IndexMultiTable
, a value in IndexMultiTable_Table.aValues
which is type of IndexMultiTable
has failed. It was recognized as a sub table with the simple check
tableStart.aValues[idx] instanceof IndexMultiTable_Table
etc. Now it is checked whether the value is not an instance of IndexMultitable itself.
The root table is not the point of quest but a sub table. That is not an instance of IndexMultiTable.
On the other hand a sub table is never a user value because IndexMultiTable_Table
is package private and not free for usage.
IndexMultiTable.super
works in Oracle-Java version 8.102, but not in a lesser version.
To save compatibility it is avoided. Sometimes a typed meta variable is the better solution in any case.
IndexMultiTable_Table
class.
Some delegate methods are overridden now (clear), therefore super.clear() is called, to prevent circular invocation.
No functional changes.
put(Comparable, Object)
fails in a constellation where insertion in the first child table,
Table#splitIntoSibling(int, Comparable, Object)
with ix=0. The key was not updated in the parent table.
fix: Using Table#setKeyValue(int, Comparable, Object)
with check whether it is ix=0 and the parent key should be updated.
Table#sizeAll
was faulty. Table#check()
improved,
it checks the sizeAll and checks all child tables. Calculation of sizeAll improved.
Table
is an own instance. Improved and simplified.
ListIterator.hasPrevious()
etc.
The advantage and usage: Set the iterator to a expected point with iterator(Comparable)
and traverse back- and forward.
There are some changes in algorithm.
IndexMultiTable_Table.sortin(int, Comparable, Object)
new Algorithm
remove(Object)
was missing, #searchInTables(Comparable, boolean, IndexBox)
restructured. It returns the table and index, able to use for internal searching.
IndexMultiTable_Table.delete(int)
and IndexMultiTable.EntrySetIterator.remove()
.
search(Comparable, boolean, boolean[])
.
put(Comparable, Object)
should not create more as one object
with the same key. Use add to do so.
IndexMultiTableInteger
.
final IndexMultiTable.Provide<Key extends java.lang.Comparable<Key>> provider
boolean shouldCheck
private int modcount
public static final IndexMultiTable.Provide<java.lang.String> providerString
IndexMultiTable(Provide)
.public IndexMultiTable(IndexMultiTable.Provide<Key> provider)
public void clear()
public Type put(Key key, Type value)
add(Comparable, Object)
and append(Comparable, Object)
.public void add(Key key, Type value)
put(Comparable, Object)
and append(Comparable, Object)
.key
- value
- public boolean containsKey(java.lang.Object key)
public void shouldCheck(boolean val)
IndexMultiTable_Table.check()
(package private) is called whenever a changing operation is done, before and after the operation.
It checks the consistency of the table. Because this operation needs calculation time, the flag shouldCheck(boolean)
can be set or reset. If the check fails there is a bug in this algorithm.
For bugfix in development it is proper to program a check of the current key before the operation
and step with the debugger.val
- true enables, false disables the ckeck.public int checkIndex()
public void append(Key key, Type obj)
put(Comparable, Object)
and append(Comparable, Object)
.key
- value
- public void addBefore(Key key, Type value, Type valueNext)
put(Comparable, Object)
, add(Comparable, Object)
and append(Comparable, Object)
.key
- value
- public boolean containsValue(java.lang.Object arg0)
public Type get(java.lang.Object keyArg)
public Type search(Key key)
key
- public Type search(Key keyArg, boolean exact, boolean[] retFound)
keyArg
- The keyexact
- if true then returns null and retFound[0] = false if the key was not found
if false then returns the first value at or after the key, see search(Comparable)
.retFound
- If null then not used. If not null then it must initialized with new boolean[1].
retFound[0] is set to true or false if the key was found or not.
Note: If the key is found and the value for this key is null, retFound[0] is set to true.
Only with this the containsKey(Object)
works probably.public boolean isEmpty()
public java.util.Set<Key> keySet()
public int size()
public java.util.Collection<Type> values()
public java.util.ListIterator<Type> iterator()
iterator
in interface java.lang.Iterable<Type>
Iterable.iterator()
public java.util.ListIterator<Type> iterator(Key fromKey)
ListIterator.previous()
is lesser or equal and the ListIterator.next()
is greater or equal. If a lesser or greater element is not found then the ListIterator.hasPrevious()
and ListIterator.hasNext()
returns false.
Note: The code which uses the iterator may be crimped by a synchronized(...){...}
because the table should not be changed.fromKey
- The start key.public Type remove(java.lang.Object keyArg)
void stop()
public void checkTable()
IndexMultiTable_Table.ixInParent
and IndexMultiTable_Table.parent
of a child hyper table.
IndexMultiTable_Table.aKeys
[ixInParent] in the parent and IndexMultiTable_Table.aKeys
[0] in the child hyper table.
IndexMultiTable_Table.aKeys
should have the IndexMultiTable.Provide.getMaxSortKey()
and all not used entries in IndexMultiTable_Table.aValues
should have null.
public java.lang.String toString()
toString
in class IndexMultiTable_Table<Key extends java.lang.Comparable<Key>,Type>