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,
                       QDLValue[] fillList)
        Initialize a QDL stem with count elements form the fillList. This returns a simple list. See QDLList(long, QDLValue[]) for the contract.
        Parameters:
        count -
        fillList -
    • Method Detail

      • newInstance

        public QDLStem newInstance()
      • getQDLMap

        public QDLMap getQDLMap()
      • setQDLMap

        public void setQDLMap​(QDLMap qdlMap)
      • getLong

        public Long getLong​(Long key)
      • setQDLList

        public void setQDLList​(QDLList qdlList)
      • getBoolean

        public Boolean getBoolean​(Long key)
        Used in unit tests only.
        Parameters:
        key -
        Returns:
      • getString

        public String getString​(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​(QDLValue 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 QDLValue 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​(QDLValue defaultValue)
      • setDefaultValue

        public void setDefaultValue​(Object defaultValue)
        Do conversion to QDLValue.
        Parameters:
        defaultValue -
      • hasDefaultValue

        public boolean hasDefaultValue()
      • size

        public long size​(int axis)
        Return count down to a given axis. This accepts ProcessStemAxisRestriction.ALL_AXES as well, which gives the count of every entry, i.e., the cardinality of the stem.
        Parameters:
        axis -
        Returns:
      • clone

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

        public QDLValue get​(QDLKey key)
        Convenience setter to put an object. If it is not a QDLValue it will be converted to one.
        Parameters:
        key -
      • addAll

        public void addAll​(QDLStem qdlStem)
      • 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<QDLKey,​QDLValue>
        Returns:
      • values

        public QDLSet<QDLValue> 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<QDLKey,​QDLValue>
        Returns:
      • isLongIndex

        public static 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.

        The logic of doing this with a regex vs. one of Java's parse methods (e.g. Long.parseLong(String) is that the latter would throw an exception and exception handling in Java slows dramatically as the stack size increases. It is better for performance to use a regex.

        Parameters:
        key -
        Returns:
      • isVar

        protected boolean isVar​(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​(QDLValue 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)
      • keysByAxis

        public QDLStem keysByAxis​(Long axis)
        Get by axis. So if axis is 0, top level keys only, axis == 1 yields rank 2 keys
        Parameters:
        axis -
        Returns:
      • indicesByRank

        public QDLStem indicesByRank​(Long rank)
        Return the indices of a given rank for this stem.
        Parameters:
        rank -
        Returns:
      • 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:
      • indicesByRank

        public QDLStem indicesByRank()
        Returns a flat list of all indices at a given rank. Each element is a stem. Special case is rank of 0 returns the same as rank == 1, except the elements are scalars, not stems with a single element.
        Returns:
      • 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 codecType)
      • 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)
        Used as a utility, this prints with an indent relative to a current indent.
        Parameters:
        indentFactor -
        currentIndent -
        Returns:
      • toString

        public String toString​(int indentFactor)
      • toString

        protected String toString​(boolean showDefaultValues)
        Whether or not to show default values. This shows the top level, but not any embedded stems, or the output becomes huge and unreadable fast.
        Parameters:
        showDefaultValues -
        Returns:
      • inputForm

        public String inputForm()
      • inputForm

        public String inputForm​(int indentFactor)
      • inputForm

        public String inputForm​(int indentFactor,
                                String currentIndent)
      • removeAllByValues

        public boolean removeAllByValues​(Collection<QDLValue> 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​(QDLValue c,
                                        boolean reorderLists)
      • removeAllByValue

        public boolean removeAllByValue​(QDLValue c,
                                        boolean reorderLists,
                                        boolean listProcessed)
      • getByMultiIndex

        public QDLValue 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:
      • put

        public QDLValue put​(QDLKey qdlKey,
                            Object object)
        Convenience method that converts second argument to a QDLValue as needed.
        Parameters:
        qdlKey -
        object -
        Returns:
      • putAll

        public void putAll​(Map<? extends QDLKey,​? extends QDLValue> map)
        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<QDLKey,​QDLValue>
        Parameters:
        map -