Package edu.uiuc.ncsa.qdl.variables
Class QDLStem
- java.lang.Object
-
- edu.uiuc.ncsa.qdl.variables.QDLStem
-
- All Implemented Interfaces:
Serializable
,Map<String,Object>
- Direct Known Subclasses:
StemVariable
public class QDLStem extends Object implements Map<String,Object>, Serializable
Created by Jeff Gaynor
on 6/27/22 at 6:33 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QDLStem.KeyRankMap
protected static class
QDLStem.OrderedIndexEntry
class
QDLStem.ValueIterator
-
Field Summary
Fields Modifier and Type Field Description static String
STEM_ENTRY_CONNECTOR
static String
STEM_INDEX_MARKER
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(QDLStem qdlStem)
void
addList(List list)
Adds a list of objects to this stem, giving them indices appropriate indices This is mostly a convenience for people writing in java to create lists programatically.protected QDLStem.KeyRankMap
allKeys2()
QDLStem
almostUnique()
This almost returns all the unique elements.void
clear()
Object
clone()
Make a shallow copy of this stem variable.QDLStem
commonKeys(QDLStem arg2)
boolean
containsKey(Long key)
boolean
containsKey(Object key)
boolean
containsKey(String key)
boolean
containsValue(Object value)
protected QDLStem
convertKeyByRank(List<List> list)
Gets a list of lists, e.g.QDLStem
dim()
Set<Map.Entry<String,Object>>
entrySet()
QDLStem
excludeKeys(QDLStem keyList)
QDLStem
fromJSON(net.sf.json.JSON json)
QDLStem
fromJSON(net.sf.json.JSONArray array, boolean convert, int type)
QDLStem
fromJSON(net.sf.json.JSONObject jsonObject)
QDLStem
fromJSON(net.sf.json.JSONObject jsonObject, boolean convertVars, int type)
Populate this from a JSON object.IndexList
get(IndexList indexList, boolean strictMatching)
Object
get(StemMultiIndex w)
Note that theObject
get(StemPath<StemPathEntry> stemPath)
Object
get(Long key)
Object
get(Object key)
Object
get(String key)
Boolean
getBoolean(Long key)
Boolean
getBoolean(String key)
Object
getByMultiIndex(String index)
This will take a stem with embedded .BigDecimal
getDecimal(Long key)
Object
getDefaultValue()
If this is set, then any get with no key will return this value.Long
getLong(Long key)
Long
getLong(String key)
QDLList
getQDLList()
QDLMap
getQDLMap()
Long
getRank()
QDLStem
getStem(Long key)
QDLStem
getStem(String key)
String
getString(Long key)
String
getString(String key)
boolean
hasDefaultValue()
QDLStem
hasKey(QDLStem keyList)
Modern successor to the deprecatedhasKeys(QDLStem)
.QDLStem
hasKeys(QDLStem keyList)
Takes a stem and returns a boolean list conformable to the argument.boolean
hasValue(Object x)
QDLStem
includeKeys(QDLStem keyList)
QDLStem
indices()
protected void
indices(QDLStem v, List list, QDLStem.KeyRankMap keyRankMap)
QDLStem
indices(Long axis)
String
inputForm()
String
inputForm(int indentFactor)
String
inputForm(int indentFactor, String currentIndent)
boolean
isEmpty()
protected boolean
isIntVar(String var)
boolean
isList()
boolean
isLongIndex(String key)
Does a regex on the index to see if it is really a long.protected boolean
isVar(String var)
StemKeys
keySet()
return an enumeration (set) of ALL keys in order, starting with the list indices then the keys.void
listAdd(Object value)
Add the single object to the list in this stem.void
listAppend(QDLStem stem)
Append the list elements of the stem to this list.void
listCopy(long startIndex, long length, QDLStem target, long insertIndex)
Copies the elements from this list to the target list.void
listInsertAt(long startIndex, long length, QDLStem target, long insertIndex)
Insert the currentQDLStem
listSubset(long startIndex)
Insert the whole argument in to the current stem, re-adjusting indices.QDLStem
listSubset(long startIndex, long length)
QDLStem
mask(QDLStem stem2)
protected void
myPut(Object index, Object value)
IndexList
newGet(IndexList indexList, boolean strictMatching)
Strict matching is used at the last resolution of the stem.QDLStem
newInstance()
QDLStem
newInstance(Long count, Object[] fillList)
Object
put(int index, Object value)
Object
put(Long index, Object value)
Object
put(String key, Object value)
void
putAll(Map<? extends String,?> m)
This does not add the list elements because that causes issues with the contract for maps.void
putLongOrString(Object key, Object value)
boolean
remove(IndexList indexList)
void
remove(StemMultiIndex w)
Object
remove(Long key)
Object
remove(Object key)
Object
remove(String key)
boolean
removeAllByValue(Object c, boolean reorderLists)
boolean
removeAllByValue(Object c, boolean reorderLists, boolean listProcessed)
boolean
removeAllByValues(Collection c, boolean reorderLists)
Removes every value in the collection from everywhere in the stem.void
renameKeys(QDLStem newKeys, boolean overWriteKeys)
void
set(IndexList indexList, Object value)
void
set(StemMultiIndex w, Object value)
void
setDefaultValue(Object defaultValue)
void
setQDLList(QDLList qdlList)
void
setQDLMap(QDLMap qdlMap)
int
size()
net.sf.json.JSON
toJSON()
Converts this to a JSON object.net.sf.json.JSON
toJSON(boolean escapeNames, int type)
String
toString()
String
toString(int indentFactor)
String
toString(int indentFactor, String currentIndent)
QDLStem
union(QDLStem... stemVariables)
This will return a new stem consisting of this stem and the union of all the stem arguments.Collection<Object>
values()
Be aware that this creates an actual set so it reads every item.QDLSet
valueSet()
Iterator
valuesIterator()
A specific iterator for the values of this stem.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
STEM_INDEX_MARKER
public static final String STEM_INDEX_MARKER
- See Also:
- Constant Field Values
-
STEM_ENTRY_CONNECTOR
public static String STEM_ENTRY_CONNECTOR
-
-
Method Detail
-
newInstance
public QDLStem newInstance()
-
getQDLMap
public QDLMap getQDLMap()
-
setQDLMap
public void setQDLMap(QDLMap qdlMap)
-
containsKey
public boolean containsKey(String key)
-
getQDLList
public QDLList getQDLList()
-
setQDLList
public void setQDLList(QDLList qdlList)
-
getDecimal
public BigDecimal getDecimal(Long key)
-
containsKey
public boolean containsKey(Long key)
-
addList
public void addList(List list)
Adds a list of objects to this stem, giving them indices appropriate indices This is mostly a convenience for people writing in java to create lists programatically. Note there is no parameter for this list since that will blow up if there are mixed entries.- Parameters:
list
-
-
listAppend
public void listAppend(QDLStem stem)
Append the list elements of the stem to this list. This integrates the lists but does not affect the maps.- Parameters:
stem
-
-
listAdd
public void listAdd(Object value)
Add the single object to the list in this stem. This allows you to add a stem as a list value, unlikelistAppend(QDLStem)
which appends the elements of the argument's list to the current object's list.- Parameters:
value
-
-
listCopy
public void listCopy(long startIndex, long length, QDLStem target, long insertIndex)
Copies the elements from this list to the target list. Note that this will over-write any elements already in the target. If you need to insert elements, use thelistInsertAt(long, long, QDLStem, long)
method.- Parameters:
startIndex
- first index in the sourcelength
- how many elements to take from the sourcetarget
- that target to get the copyinsertIndex
- where in the target to start copying.
-
listInsertAt
public void listInsertAt(long startIndex, long length, QDLStem target, long insertIndex)
Insert the current- Parameters:
startIndex
-length
-target
-insertIndex
-
-
listSubset
public QDLStem listSubset(long startIndex)
Insert the whole argument in to the current stem, re-adjusting indices.- Parameters:
startIndex
-
-
listSubset
public QDLStem listSubset(long startIndex, long length)
-
isList
public boolean isList()
-
getDefaultValue
public Object getDefaultValue()
If this is set, then any get with no key will return this value. Since the basic unit of QDL is the stem, this gives us a way of basically turning a scalar in to a stem without having to do complicated size and key matching.
Note thatcontainsKey(Object)
still works as usual, so you can ask if a key exists.- Returns:
-
setDefaultValue
public void setDefaultValue(Object defaultValue)
-
hasDefaultValue
public boolean hasDefaultValue()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<String,Object>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<String,Object>
-
clone
public Object clone()
Make a shallow copy of this stem variable.
-
addAll
public void addAll(QDLStem qdlStem)
-
putAll
public void putAll(Map<? extends String,?> m)
This does not add the list elements because that causes issues with the contract for maps. If you are adding all the values of a stem to this one, useaddAll(QDLStem)
.
-
keySet
public StemKeys keySet()
return an enumeration (set) of ALL keys in order, starting with the list indices then the keys.
-
values
public Collection<Object> values()
Be aware that this creates an actual set so it reads every item. If you need to iterate over the elements (so single pass, not potentially multiple passes) consider usingvaluesIterator()
while gets the iterators and manages them.
-
isLongIndex
public boolean isLongIndex(String key)
Does a regex on the index to see if it is really a long. Note that this still is needed since a user can set a.'2' := 3 and this should turn it into a list entry otherwise we get both string and list entries with "the same" key.- Parameters:
key
-- Returns:
-
isVar
protected boolean isVar(String var)
-
isIntVar
protected boolean isIntVar(String var)
-
valueSet
public QDLSet valueSet()
-
almostUnique
public QDLStem almostUnique()
This almost returns all the unique elements. The issue is that if there are deeply nested stems, then do not entirely get made unique before getting added to the result, hence the simplest fix is that in that case is to call this twice. Someday this can be fixed with a careful rewrite of the recursion in stem lists.- Returns:
-
dim
public QDLStem dim()
-
getRank
public Long getRank()
-
get
public Object get(StemPath<StemPathEntry> stemPath)
-
union
public QDLStem union(QDLStem... stemVariables)
This will return a new stem consisting of this stem and the union of all the stem arguments. The effect is to overwrite the current stem values with the argument values. so e.g.{'a':1}~{'a':2,'b':3}~{'b':4,'c':5} {a:2, b:4, c:5}
- Parameters:
stemVariables
-- Returns:
-
valuesIterator
public Iterator valuesIterator()
A specific iterator for the values of this stem. This should be used when traversing all values, such as inWhileLoop
s.- Returns:
-
hasValue
public boolean hasValue(Object x)
-
renameKeys
public void renameKeys(QDLStem newKeys, boolean overWriteKeys)
-
hasKeys
public QDLStem hasKeys(QDLStem keyList)
Takes a stem and returns a boolean list conformable to the argument.- Parameters:
keyList
-- Returns:
-
hasKey
public QDLStem hasKey(QDLStem keyList)
Modern successor to the deprecatedhasKeys(QDLStem)
. This returns a left conformable stem as it should.- Parameters:
keyList
-- Returns:
-
newGet
public IndexList newGet(IndexList indexList, boolean strictMatching)
Strict matching is used at the last resolution of the stem. It means that left over scalars are flagged as errors since there is no stem waiting to resolve them.- Parameters:
indexList
-strictMatching
-- Returns:
-
remove
public boolean remove(IndexList indexList)
-
get
public Object get(StemMultiIndex w)
Note that the- Parameters:
w
-- Returns:
-
set
public void set(StemMultiIndex w, Object value)
-
remove
public void remove(StemMultiIndex w)
-
allKeys2
protected QDLStem.KeyRankMap allKeys2()
-
convertKeyByRank
protected QDLStem convertKeyByRank(List<List> list)
Gets a list of lists, e.g.[[foo, 0], [foo, 1], [foo, 2], [foo, tyu]]
and returns a stem of these.- Parameters:
list
-- Returns:
-
indices
protected void indices(QDLStem v, List list, QDLStem.KeyRankMap keyRankMap)
-
indices
public QDLStem indices()
-
toJSON
public net.sf.json.JSON toJSON()
Converts this to a JSON object. Names of stem components are decoded. So if you have a stem, a., with component $23foo, then a.$23foo yields{"#foo":...}
I.e. the $23 is treated as an escaped name and converted back. If you do not want stem names escaped when converting to JSON, then usetoJSON(boolean, int)
with the argument being false. In that case the outputted JSON would be{"$23foo":...}
- Returns:
-
toJSON
public net.sf.json.JSON toJSON(boolean escapeNames, int type)
-
fromJSON
public QDLStem fromJSON(net.sf.json.JSON json)
-
fromJSON
public QDLStem fromJSON(net.sf.json.JSONObject jsonObject)
-
fromJSON
public QDLStem fromJSON(net.sf.json.JSONObject jsonObject, boolean convertVars, int type)
Populate this from a JSON object. Note that JSON arrays are turned in to stem lists.- Parameters:
jsonObject
- return this object, populated
-
fromJSON
public QDLStem fromJSON(net.sf.json.JSONArray array, boolean convert, int type)
-
toString
public String toString(int indentFactor)
-
inputForm
public String inputForm()
-
inputForm
public String inputForm(int indentFactor)
-
removeAllByValues
public boolean removeAllByValues(Collection c, boolean reorderLists)
Removes every value in the collection from everywhere in the stem. Optionally, lists will be reordered too. Since this a bit more- Parameters:
c
-reorderLists
-- Returns:
-
removeAllByValue
public boolean removeAllByValue(Object c, boolean reorderLists)
-
removeAllByValue
public boolean removeAllByValue(Object c, boolean reorderLists, boolean listProcessed)
-
getByMultiIndex
public Object getByMultiIndex(String index)
This will take a stem with embedded . and return the object at that index.
E.g.
myStem.getByMultiIndex("a.b.c");
would return myStem.a.b.c;
This just calls
get(StemMultiIndex)
.Note
In this call, you pass in the exact index you want, unlike
get(StemMultiIndex)
which accepts the name of the stem as the first argument- Parameters:
index
-- Returns:
-
-