Class CompositeItem

java.lang.Object
com.yahoo.prelude.query.Item
com.yahoo.prelude.query.CompositeItem
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
AndItem, CompositeTaggableItem, NearItem, NonReducibleCompositeItem, NotItem, OrItem, QueryTree, RankItem, SegmentItem

public abstract class CompositeItem extends Item
Superclass of expressions which contains a collection of sub-expressions
Author:
bratseth
  • Constructor Details

    • CompositeItem

      public CompositeItem()
  • Method Details

    • setIndexName

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

      public void disclose(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:
      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:
      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:
      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:
      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 ListIterator<Item> getItemIterator()
      Returns a modifiable list iterator of the immediate children of this
    • items

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

      public int encode(ByteBuffer buffer)
      Specified by:
      encode in class Item
    • encodeThis

      protected void encodeThis(ByteBuffer buffer)
      Encodes just this item, not its regular subitems, to the given buffer.
      Overrides:
      encodeThis in class Item
    • encodingArity

      protected int encodingArity()
    • appendBodyString

      protected void appendBodyString(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
    • shouldParenthesize

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

      public CompositeItem clone()
      Returns a deep copy of this item
      Overrides:
      clone in class Item
    • hashCode

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

      public boolean equals(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 Optional<Item> extractSingleChild()
      Returns the single child of this, if this can be omitted without changes to recall semantics.
    • acceptsItemsOfType

      public boolean acceptsItemsOfType(Item.ItemType itemType)