Package org.qdl_lang.variables
Class QDLList<K extends QDLValue>
- java.lang.Object
-
- org.qdl_lang.variables.QDLList<K>
-
- All Implemented Interfaces:
Serializable
,Iterable<K>
,Collection<K>
,List<K>
public class QDLList<K extends QDLValue> extends Object implements List<K>, Serializable
This is used internally by a stem to store its entries that have integer indices.Created by Jeff Gaynor
on 2/20/20 at 8:39 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
QDLList.MyDescendingIterator
static class
QDLList.MyIterator
This iterates over the elements of this QDL list.static class
QDLList.seGapException
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, QDLValue element)
boolean
add(Integer o)
boolean
add(SparseEntry sparseEntry)
boolean
add(QDLValue qdlValue)
boolean
addAll(int index, Collection c)
boolean
addAll(Collection c)
Add every element in a collection to this list.void
append(Object obj)
Find the largest element of this list and append the given object to the end of it.void
append(QDLSet<QDLValue> set)
void
appendAll(List<QDLValue> objects)
Appends all elements in a list.int
arraySize()
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection c)
boolean
containsKey(Object o)
Checks if this key (as a string or long) is an index in this list.Iterator
descendingIterator(boolean objectsOnly)
QDLList
dim()
Get the dimension list for this object.SparseEntry
first()
K
get(int index)
K
get(long index)
protected QDLValue
getAbsoluteAddress(long index)
ArrayList<QDLValue>
getArrayList()
Long
getRank()
protected K
getRelativeAddress(long originalIndex)
Used in cases where the index < 0 and we have to compute it relative to the other indices.TreeSet<SparseEntry>
getSparseEntries()
boolean
hasArrayList()
boolean
hasIndex(long index)
boolean
hasSparseEntries()
int
indexOf(Object o)
String
inputForm()
String
inputForm(int indent)
String
inputForm(int indentFactor, String currentIndent)
boolean
isEmpty()
Iterator
iterator()
Now we can do for-each loop constructs.Iterator
iterator(boolean objectsOnly)
Iterator over values.SparseEntry
last()
int
lastIndexOf(Object o)
void
listCopyFrom(long startIndex, long length, QDLList source, long insertIndex)
void
listInsertFrom(long startIndex, long length, QDLList source, long insertIndex)
ListIterator
listIterator()
ListIterator
listIterator(int index)
protected void
normalizeIndices()
StemKeys
orderedKeys()
Get the keys in a linked hash set.protected String
otherToString()
Keep this! It is not used by QDL though and won't show up in any searches of methods used.QDLStem
permuteEntries(List<QDLValue> permutation)
A very specific utility, used in the transpose function.K
remove(int index)
boolean
remove(Object o)
Remove by value from top level only.boolean
remove(Collection c)
boolean
remove(SparseEntry sparseEntry)
boolean
remove(QDLValue qdlValue)
boolean
removeAll(Collection c)
removes every element by value.boolean
removeAllByValue(Collection<QDLValue> c, boolean reorderLists)
Fulfills QDL's contract to remove all elements by value.protected boolean
removeAllByValue(QDLValue qdlValue, boolean reorderLists)
removes a single object from everywhere in this List.boolean
removeByIndex(long index)
Remove is a bit different than a java list remove.boolean
retainAll(Collection c)
QDLValue
set(int index, QDLValue element)
This is mostly used when hot-rodding performance.void
set(long index, QDLValue element)
void
set(SparseEntry sparseEntry)
Add an element in a sparse entry.protected void
setAbsoluteIndex(long index, QDLValue element)
void
setArrayList(ArrayList<QDLValue> arrayList)
protected void
setRelativeIndex(long originalIndex, QDLValue element)
Set a relative value.void
setSparseEntries(TreeSet<SparseEntry> sparseEntries)
int
size()
List
subList(int fromIndex, int toIndex)
QDLList
subList(long startIndex, boolean includeStartIndex, long endIndex, boolean includeEndIndex)
QDLList
subListNEW(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
QDLList
subsetBasicCase(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
QDLList
subsetEndOfList(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
QDLList
subsetEndOfListFromEnd(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
Object[]
toArray()
QDLValue[]
toArray(boolean noGaps, boolean allowStems)
Convert this to an array of objects.Object[]
toArray(Object[] a)
net.sf.json.JSONArray
toJSON()
This exports the current list as aJSONArray
.net.sf.json.JSONArray
toJSON(boolean escapeNames, int conversionAlgorithm)
Converts to JSON elements.String
toString()
String
toString(int indentFactor)
String
toString(int indentFactor, String currentIndent)
String[]
toStringArray()
Convenience method.List<String>
toStringList()
QDLList
unique()
Runs over every entry in the stem list (including danglers).List<? extends QDLValue>
values()
Return all values for this list, including sparse values-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
-
-
-
Constructor Detail
-
QDLList
public QDLList()
-
QDLList
public QDLList(long size)
-
QDLList
public QDLList(long size, QDLValue[] fill)
Fill this list with size elements from the fill array. If sizelength(fill), the elements of fill are cyclically resused. - Parameters:
size
-fill
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
-
hasArrayList
public boolean hasArrayList()
-
getSparseEntries
public TreeSet<SparseEntry> getSparseEntries()
-
setSparseEntries
public void setSparseEntries(TreeSet<SparseEntry> sparseEntries)
-
hasSparseEntries
public boolean hasSparseEntries()
-
subList
public QDLList subList(long startIndex, boolean includeStartIndex, long endIndex, boolean includeEndIndex)
-
subListNEW
public QDLList subListNEW(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
- Parameters:
startIndex
- - negative means start from endincludeStartIndex
-count
- - negative means rest of list from start indexincludeEndIndex
-- Returns:
-
subsetEndOfListFromEnd
public QDLList subsetEndOfListFromEnd(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
-
subsetBasicCase
public QDLList subsetBasicCase(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
-
subsetEndOfList
public QDLList subsetEndOfList(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)
-
unique
public QDLList unique()
Runs over every entry in the stem list (including danglers). result is a standard list (starts at 0, no gaps) of unique elements.- Returns:
-
get
public K get(long index)
-
getRelativeAddress
protected K getRelativeAddress(long originalIndex)
Used in cases where the index < 0 and we have to compute it relative to the other indices. Note that for sparse entries, this can be expensive, so a few special cases are handled directly. Searching a sparse list for a relative address will be at worst linear because of the wayTreeSet
is implemented.- Parameters:
originalIndex
-- Returns:
-
getAbsoluteAddress
protected QDLValue getAbsoluteAddress(long index)
-
removeByIndex
public boolean removeByIndex(long index)
Remove is a bit different than a java list remove. We allow for gaps and sparse arrays, so in Java [0,1,2,3,4] remove index 2 yields [0,1,3,4] -- still has index 2. QDL would have a result of [0,1]~{3:3,4;4}- Parameters:
index
-- Returns:
-
append
public void append(Object obj)
Find the largest element of this list and append the given object to the end of it. This is also used internally to append sparse entries, so it accepts an Object- Parameters:
obj
-
-
appendAll
public void appendAll(List<QDLValue> objects)
Appends all elements in a list. Terrifically inefficient. Optimize. Someday. Maybe.- Parameters:
objects
-
-
toString
public String toString(int indentFactor)
-
toJSON
public net.sf.json.JSONArray toJSON()
This exports the current list as aJSONArray
. Note that there is no analog for importing one -- use theQDLStem.fromJSON(JSONObject)
to do that, since the result will in general be a stem (if one element of the array is a JSONObject, then the index has to make it a stem -- this is just how the bookkeeping is done).- Returns:
-
toJSON
public net.sf.json.JSONArray toJSON(boolean escapeNames, int conversionAlgorithm)
Converts to JSON elements.- Parameters:
escapeNames
-conversionAlgorithm
-- Returns:
-
inputForm
public String inputForm(int indent)
-
inputForm
public String inputForm()
-
toArray
public QDLValue[] toArray(boolean noGaps, boolean allowStems)
Convert this to an array of objects. Note that there may be gaps filled in with null values if this is sparse.- Parameters:
noGaps
- - if true, truncates array at first encountered gapallowStems
- - if true, hitting a stem throws an exception.- Returns:
-
dim
public QDLList dim()
Get the dimension list for this object. dim(n(3,4,5)) == [3,4,5]
This is very simple minded and assumes rectangular arrays.- Returns:
-
getRank
public Long getRank()
-
values
public List<? extends QDLValue> values()
Return all values for this list, including sparse values- Returns:
-
size
public int size()
-
arraySize
public int arraySize()
-
orderedKeys
public StemKeys orderedKeys()
Get the keys in a linked hash set. This is specifically for cases where stems have to get them for loops.- Returns:
-
addAll
public boolean addAll(Collection c)
Add every element in a collection to this list. It will NOT attempt to convert values, it just appends them.
-
hasIndex
public boolean hasIndex(long index)
-
set
public void set(SparseEntry sparseEntry)
Add an element in a sparse entry. This puts it in the right place and might adjust indices accordingly.- Parameters:
sparseEntry
-
-
set
public void set(long index, QDLValue element)
-
setRelativeIndex
protected void setRelativeIndex(long originalIndex, QDLValue element)
Set a relative value. Note that unlike absolute addresses, relative ones must exist prior to being set. So a.42 can always be set (may result in a sparse entry) but a.(-42) requires there be at least 42 elements- Parameters:
originalIndex
-element
-
-
setAbsoluteIndex
protected void setAbsoluteIndex(long index, QDLValue element)
-
listInsertFrom
public void listInsertFrom(long startIndex, long length, QDLList source, long insertIndex)
-
normalizeIndices
protected void normalizeIndices()
-
listCopyFrom
public void listCopyFrom(long startIndex, long length, QDLList source, long insertIndex)
-
iterator
public Iterator iterator(boolean objectsOnly)
Iterator over values. This is overloaded, so that if objectsOnly is true, justQDLValue
s are returned, otherwise, this will return a mix of values and sparse entries.- Parameters:
objectsOnly
-- Returns:
-
iterator
public Iterator iterator()
Now we can do for-each loop constructs. SeeQDLList.MyIterator
.
-
containsKey
public boolean containsKey(Object o)
Checks if this key (as a string or long) is an index in this list.- Parameters:
o
-- Returns:
-
contains
public boolean contains(Object o)
-
toArray
public Object[] toArray()
-
toStringArray
public String[] toStringArray()
Convenience method. This takes the elements of thisQDLList
and either returns their value as a string or invokes the standardObject.toString()
method. It is intended to allow for passing values to non_-QDL code. Since Java has no concept of sparse entries, these are just appended in order to the end of the array.- Returns:
-
add
public boolean add(Integer o)
-
add
public boolean add(SparseEntry sparseEntry)
-
add
public boolean add(QDLValue qdlValue)
-
remove
public boolean remove(QDLValue qdlValue)
-
remove
public boolean remove(SparseEntry sparseEntry)
-
remove
public boolean remove(Object o)
Remove by value from top level only. This fulfills Java's contract for lists/collections, which removes the first instance of this object only. To fulfill QDL's contract, useremoveAllByValue(QDLValue, boolean)
This might pass in sparse entries, so those have to be taken into account.
-
remove
public boolean remove(Collection c)
-
removeAllByValue
public boolean removeAllByValue(Collection<QDLValue> c, boolean reorderLists)
Fulfills QDL's contract to remove all elements by value.- Parameters:
c
-reorderLists
-- Returns:
-
removeAllByValue
protected boolean removeAllByValue(QDLValue qdlValue, boolean reorderLists)
removes a single object from everywhere in this List.- Parameters:
qdlValue
-- Returns:
-
containsAll
public boolean containsAll(Collection c)
- Specified by:
containsAll
in interfaceCollection<K extends QDLValue>
- Specified by:
containsAll
in interfaceList<K extends QDLValue>
-
addAll
public boolean addAll(int index, Collection c)
-
removeAll
public boolean removeAll(Collection c)
removes every element by value. The collection should be a collection ofQDLValue
s, but the signature does not allow for that.
-
retainAll
public boolean retainAll(Collection c)
-
clear
public void clear()
-
set
public QDLValue set(int index, QDLValue element)
This is mostly used when hot-rodding performance. It only updates the array list backing this object, not any sparse entries. Generally only call it if you have a well-articulated need to do so.
-
add
public void add(int index, QDLValue element)
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOf
in interfaceList<K extends QDLValue>
-
listIterator
public ListIterator listIterator()
- Specified by:
listIterator
in interfaceList<K extends QDLValue>
-
listIterator
public ListIterator listIterator(int index)
- Specified by:
listIterator
in interfaceList<K extends QDLValue>
-
subList
public List subList(int fromIndex, int toIndex)
-
last
public SparseEntry last()
-
first
public SparseEntry first()
-
descendingIterator
public Iterator descendingIterator(boolean objectsOnly)
-
otherToString
protected String otherToString()
Keep this! It is not used by QDL though and won't show up in any searches of methods used. This is an internal method used by the IDE for debugging. Supremely useful in that context.
-
permuteEntries
public QDLStem permuteEntries(List<QDLValue> permutation)
A very specific utility, used in the transpose function. The assumptions are- This list consists entirely indices to a stem, so all entries are longs
- All the indices are the same length
- The permutation will be applied to every entry
- No sparse entries
QDLStem
has the indices in it and we need to permute all of them for a transpose or other operation. This can be very slow and clunky using QDL standard calls, so this is a backdoor for speed to grab the entries directly and remap them. It is not a generally applicable function.- Parameters:
permutation
-- Returns:
-
-