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 SummaryNested Classes Modifier and Type Class Description classQDLList.MyDescendingIteratorstatic classQDLList.MyIteratorThis iterates over the elements of this QDL list.static classQDLList.seGapException
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, QDLValue element)booleanadd(Integer o)booleanadd(SparseEntry sparseEntry)booleanadd(QDLValue qdlValue)booleanaddAll(int index, Collection c)booleanaddAll(Collection c)Add every element in a collection to this list.voidappend(Object obj)Find the largest element of this list and append the given object to the end of it.voidappend(QDLSet<QDLValue> set)voidappendAll(List objects)Appends all elements in a list.intarraySize()voidclear()booleancontains(Object o)booleancontainsAll(Collection c)booleancontainsKey(Object o)Checks if this key (as a string or long) is an index in this list.IteratordescendingIterator(boolean objectsOnly)QDLListdim()Get the dimension list for this object.SparseEntryfirst()Kget(int index)Kget(long index)protected QDLValuegetAbsoluteAddress(long index)ArrayList<QDLValue>getArrayList()LonggetRank()protected KgetRelativeAddress(long originalIndex)Used in cases where the index < 0 and we have to compute it relative to the other indices.TreeSet<SparseEntry>getSparseEntries()booleanhasArrayList()booleanhasIndex(long index)booleanhasSparseEntries()intindexOf(Object o)StringinputForm()StringinputForm(int indent)StringinputForm(int indentFactor, String currentIndent)booleanisEmpty()Iteratoriterator()Now we can do for-each loop constructs.Iteratoriterator(boolean objectsOnly)Iterator over values.SparseEntrylast()intlastIndexOf(Object o)voidlistCopyFrom(long startIndex, long length, QDLList source, long insertIndex)voidlistInsertFrom(long startIndex, long length, QDLList source, long insertIndex)ListIteratorlistIterator()ListIteratorlistIterator(int index)protected voidnormalizeIndices()StemKeysorderedKeys()Get the keys in a linked hash set.protected StringotherToString()Keep this! It is not used by QDL though and won't show up in any searches of methods used.QDLStempermuteEntries(List<QDLValue> permutation)A very specific utility, used in the transpose function.Kremove(int index)booleanremove(Object o)Remove by value from top level only.booleanremove(Collection c)booleanremove(SparseEntry sparseEntry)booleanremove(QDLValue qdlValue)booleanremoveAll(Collection c)removes every element by value.booleanremoveAllByValue(Collection<QDLValue> c, boolean reorderLists)Fulfills QDL's contract to remove all elements by value.protected booleanremoveAllByValue(QDLValue qdlValue, boolean reorderLists)removes a single object from everywhere in this List.booleanremoveByIndex(long index)Remove is a bit different than a java list remove.booleanretainAll(Collection c)QDLValueset(int index, QDLValue element)This is mostly used when hot-rodding performance.voidset(long index, QDLValue element)voidset(SparseEntry sparseEntry)Add an element in a sparse entry.protected voidsetAbsoluteIndex(long index, QDLValue element)voidsetArrayList(ArrayList<QDLValue> arrayList)protected voidsetRelativeIndex(long originalIndex, QDLValue element)Set a relative value.voidsetSparseEntries(TreeSet<SparseEntry> sparseEntries)intsize()ListsubList(int fromIndex, int toIndex)QDLListsubList(long startIndex, boolean includeStartIndex, long endIndex, boolean includeEndIndex)QDLListsubListNEW(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)QDLListsubsetBasicCase(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)QDLListsubsetEndOfList(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex)QDLListsubsetEndOfListFromEnd(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.JSONArraytoJSON()This exports the current list as aJSONArray.net.sf.json.JSONArraytoJSON(boolean escapeNames, int conversionAlgorithm)Converts to JSON elements.StringtoString()StringtoString(int indentFactor)StringtoString(int indentFactor, String currentIndent)String[]toStringArray()Convenience method.List<String>toStringList()QDLListunique()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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.util.CollectionparallelStream, removeIf, stream, toArray
 - 
Methods inherited from interface java.util.Listequals, hashCode, replaceAll, sort, spliterator
 
- 
 
- 
- 
- 
Constructor Detail- 
QDLListpublic QDLList() 
 - 
QDLListpublic QDLList(long size) 
 - 
QDLListpublic 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- 
isEmptypublic boolean isEmpty() 
 - 
hasArrayListpublic boolean hasArrayList() 
 - 
getSparseEntriespublic TreeSet<SparseEntry> getSparseEntries() 
 - 
setSparseEntriespublic void setSparseEntries(TreeSet<SparseEntry> sparseEntries) 
 - 
hasSparseEntriespublic boolean hasSparseEntries() 
 - 
subListpublic QDLList subList(long startIndex, boolean includeStartIndex, long endIndex, boolean includeEndIndex) 
 - 
subListNEWpublic QDLList subListNEW(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex) - Parameters:
- startIndex- - negative means start from end
- includeStartIndex-
- count- - negative means rest of list from start index
- includeEndIndex-
- Returns:
 
 - 
subsetEndOfListFromEndpublic QDLList subsetEndOfListFromEnd(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex) 
 - 
subsetBasicCasepublic QDLList subsetBasicCase(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex) 
 - 
subsetEndOfListpublic QDLList subsetEndOfList(long startIndex, boolean includeStartIndex, long count, boolean includeEndIndex) 
 - 
uniquepublic 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:
 
 - 
getpublic K get(long index) 
 - 
getRelativeAddressprotected 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 wayTreeSetis implemented.- Parameters:
- originalIndex-
- Returns:
 
 - 
getAbsoluteAddressprotected QDLValue getAbsoluteAddress(long index) 
 - 
removeByIndexpublic 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:
 
 - 
appendpublic 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-
 
 - 
appendAllpublic void appendAll(List objects) Appends all elements in a list. Converts elements as needed- Parameters:
- objects-
 
 - 
toStringpublic String toString(int indentFactor) 
 - 
toJSONpublic 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:
 
 - 
toJSONpublic net.sf.json.JSONArray toJSON(boolean escapeNames, int conversionAlgorithm)Converts to JSON elements.- Parameters:
- escapeNames-
- conversionAlgorithm-
- Returns:
 
 - 
inputFormpublic String inputForm(int indent) 
 - 
inputFormpublic String inputForm() 
 - 
toArraypublic 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 gap
- allowStems- - if true, hitting a stem throws an exception.
- Returns:
 
 - 
dimpublic 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:
 
 - 
getRankpublic Long getRank() 
 - 
valuespublic List<? extends QDLValue> values() Return all values for this list, including sparse values- Returns:
 
 - 
sizepublic int size() 
 - 
arraySizepublic int arraySize() 
 - 
orderedKeyspublic StemKeys orderedKeys() Get the keys in a linked hash set. This is specifically for cases where stems have to get them for loops.- Returns:
 
 - 
addAllpublic boolean addAll(Collection c) Add every element in a collection to this list. It will NOT attempt to convert values, it just appends them.
 - 
hasIndexpublic boolean hasIndex(long index) 
 - 
setpublic 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-
 
 - 
setpublic void set(long index, QDLValue element)
 - 
setRelativeIndexprotected 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-
 
 - 
setAbsoluteIndexprotected void setAbsoluteIndex(long index, QDLValue element)
 - 
listInsertFrompublic void listInsertFrom(long startIndex, long length, QDLList source, long insertIndex)
 - 
normalizeIndicesprotected void normalizeIndices() 
 - 
listCopyFrompublic void listCopyFrom(long startIndex, long length, QDLList source, long insertIndex)
 - 
iteratorpublic Iterator iterator(boolean objectsOnly) Iterator over values. This is overloaded, so that if objectsOnly is true, justQDLValues are returned, otherwise, this will return a mix of values and sparse entries.- Parameters:
- objectsOnly-
- Returns:
 
 - 
iteratorpublic Iterator iterator() Now we can do for-each loop constructs. SeeQDLList.MyIterator.
 - 
containsKeypublic boolean containsKey(Object o) Checks if this key (as a string or long) is an index in this list.- Parameters:
- o-
- Returns:
 
 - 
containspublic boolean contains(Object o) 
 - 
toArraypublic Object[] toArray() 
 - 
toStringArraypublic String[] toStringArray() Convenience method. This takes the elements of thisQDLListand 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:
 
 - 
addpublic boolean add(Integer o) 
 - 
addpublic boolean add(SparseEntry sparseEntry) 
 - 
addpublic boolean add(QDLValue qdlValue) 
 - 
removepublic boolean remove(QDLValue qdlValue) 
 - 
removepublic boolean remove(SparseEntry sparseEntry) 
 - 
removepublic 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.
 - 
removepublic boolean remove(Collection c) 
 - 
removeAllByValuepublic boolean removeAllByValue(Collection<QDLValue> c, boolean reorderLists) Fulfills QDL's contract to remove all elements by value.- Parameters:
- c-
- reorderLists-
- Returns:
 
 - 
removeAllByValueprotected boolean removeAllByValue(QDLValue qdlValue, boolean reorderLists) removes a single object from everywhere in this List.- Parameters:
- qdlValue-
- Returns:
 
 - 
containsAllpublic boolean containsAll(Collection c) - Specified by:
- containsAllin interface- Collection<K extends QDLValue>
- Specified by:
- containsAllin interface- List<K extends QDLValue>
 
 - 
addAllpublic boolean addAll(int index, Collection c)
 - 
removeAllpublic boolean removeAll(Collection c) removes every element by value. The collection should be a collection ofQDLValues, but the signature does not allow for that.
 - 
retainAllpublic boolean retainAll(Collection c) 
 - 
clearpublic void clear() 
 - 
setpublic 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.
 - 
addpublic void add(int index, QDLValue element)
 - 
lastIndexOfpublic int lastIndexOf(Object o) - Specified by:
- lastIndexOfin interface- List<K extends QDLValue>
 
 - 
listIteratorpublic ListIterator listIterator() - Specified by:
- listIteratorin interface- List<K extends QDLValue>
 
 - 
listIteratorpublic ListIterator listIterator(int index) - Specified by:
- listIteratorin interface- List<K extends QDLValue>
 
 - 
subListpublic List subList(int fromIndex, int toIndex) 
 - 
lastpublic SparseEntry last() 
 - 
firstpublic SparseEntry first() 
 - 
descendingIteratorpublic Iterator descendingIterator(boolean objectsOnly) 
 - 
otherToStringprotected 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.
 - 
permuteEntriespublic 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
 QDLStemhas 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:
 
 
- 
 
-