Class CompositeItem

    • Constructor Detail

      • CompositeItem

        public CompositeItem()
    • Method Detail

      • setIndexName

        public void setIndexName​(java.lang.String index)
        Sets the index name of all subitems of this
        Specified by:
        setIndexName in class Item
      • disclose

        public void disclose​(com.yahoo.prelude.query.textualrepresentation.Discloser discloser)
        Overrides:
        disclose in class Item
      • ensureNotInSubtree

        public void ensureNotInSubtree​(CompositeItem item)
      • addItem

        public void addItem​(Item item)
      • adding

        protected void adding​(Item item)
      • addItem

        public void addItem​(int index,
                            Item item)
        Inserts the item at a position and increases the index of existing items starting on this position by one
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of range
      • getItem

        public Item getItem​(int index)
        Returns a subitem
        Parameters:
        index - the (0-base) index of the item to return
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no subitem at index
      • setItem

        public Item setItem​(int index,
                            Item item)
        Replaces the item at the given index
        Parameters:
        index - the (0-base) index of the item to replace
        item - the new item
        Returns:
        the old item at this position. The parent of the old item is not cleared
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no item at this index
      • getItemIndex

        public int getItemIndex​(Item item)
        Returns the index of a subitem
        Parameters:
        item - The child item to find the index of
        Returns:
        the 0-base index of the child or -1 if there is no such child
      • removeItem

        public Item removeItem​(int index)
        Removes the item at the given index
        Parameters:
        index - the index of the item to remove
        Returns:
        the removed item
        Throws:
        java.lang.IndexOutOfBoundsException - if there is no item at the given index
      • removeItem

        public boolean removeItem​(Item item)
        Removes the given item. Does nothing if the item is not present.
        Parameters:
        item - the item to remove
        Returns:
        whether the item was removed
      • getItemCount

        public int getItemCount()
        Returns the number of direct children of this item
      • getItemIterator

        public java.util.ListIterator<Item> getItemIterator()
        Returns a modifiable list iterator of the immediate children of this
      • items

        public java.util.List<Item> items()
        Returns a read only list of the immediate children of this
      • encode

        public int encode​(java.nio.ByteBuffer buffer)
        Specified by:
        encode in class Item
      • encodeThis

        protected void encodeThis​(java.nio.ByteBuffer buffer)
        Encodes just this item, not it's usual subitems, to the given buffer.
        Overrides:
        encodeThis in class Item
      • encodingArity

        protected int encodingArity()
      • appendBodyString

        protected void appendBodyString​(java.lang.StringBuilder buffer)
        Description copied from class: Item
        Override to append the item body in the canonical query language of this item. An item is usually represented by the string
         ([itemName] [body])
         
        The body must be appended appended by this method.
        Specified by:
        appendBodyString in class Item
      • shouldParenthize

        protected boolean shouldParenthize()
        Composite items should be parenthized when not on the top level
        Overrides:
        shouldParenthize in class Item
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Item
      • equals

        public boolean equals​(java.lang.Object object)
        Returns whether this item is of the same class and contains the same state as the given item
        Overrides:
        equals in class Item
      • lock

        public void lock()
        Make composite immutable if this is supported.
      • isLocked

        public boolean isLocked()
        Whether this composite is in a mutable state.
      • getTermCount

        public int getTermCount()
        Specified by:
        getTermCount in class Item
      • extractSingleChild

        public java.util.Optional<Item> extractSingleChild()
        Will return its single child if itself can safely be omitted.
        Returns:
        a valid Item or empty Optional if it can not be done