Class QDLStem

    • Constructor Detail

      • QDLStem

        public QDLStem()
      • QDLStem

        public QDLStem​(QDLList list)
        Initialize a QDL stem with a list
        Parameters:
        list -
      • QDLStem

        public QDLStem​(Long count,
                       Object[] fillList)
    • Method Detail

      • newInstance

        public QDLStem newInstance()
      • getQDLMap

        public QDLMap getQDLMap()
      • setQDLMap

        public void setQDLMap​(QDLMap qdlMap)
      • getLong

        public Long getLong​(Long key)
      • containsKey

        public boolean containsKey​(String key)
      • getQDLList

        public QDLList getQDLList()
      • setQDLList

        public void setQDLList​(QDLList qdlList)
      • getString

        public String getString​(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, unlike listAppend(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 the listInsertAt(long, long, QDLStem, long) method.
        Parameters:
        startIndex - first index in the source
        length - how many elements to take from the source
        target - that target to get the copy
        insertIndex - 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 that containsKey(Object) still works as usual, so you can ask if a key exists.
        Returns:
      • setDefaultValue

        public void setDefaultValue​(Object defaultValue)
      • hasDefaultValue

        public boolean hasDefaultValue()
      • clone

        public Object clone()
        Make a shallow copy of this stem variable.
        Overrides:
        clone in class Object
        Returns:
      • putLongOrString

        public void putLongOrString​(Object key,
                                    Object value)
      • 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, use addAll(QDLStem).
        Specified by:
        putAll in interface Map<String,​Object>
        Parameters:
        m -
      • keySet

        public StemKeys keySet()
        return an enumeration (set) of ALL keys in order, starting with the list indices then the keys.
        Specified by:
        keySet in interface Map<String,​Object>
        Returns:
      • 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 using valuesIterator() while gets the iterators and manages them.
        Specified by:
        values in interface Map<String,​Object>
        Returns:
      • 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:
      • getRank

        public Long getRank()
      • 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 in WhileLoops.
        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 deprecated hasKeys(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)
      • myPut

        protected void myPut​(Object index,
                             Object value)
      • 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

        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 use toJSON(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,
                               String currentIndent)
      • toString

        public String toString​(int indentFactor)
      • inputForm

        public String inputForm()
      • inputForm

        public String inputForm​(int indentFactor)
      • inputForm

        public String inputForm​(int indentFactor,
                                String currentIndent)
      • 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: