Package com.yahoo.prelude.query
Class CompositeItem
- java.lang.Object
-
- com.yahoo.prelude.query.Item
-
- com.yahoo.prelude.query.CompositeItem
-
- All Implemented Interfaces:
java.lang.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.yahoo.prelude.query.Item
Item.ItemCreator, Item.ItemType
-
-
Field Summary
-
Fields inherited from class com.yahoo.prelude.query.Item
connectedBacklink, connectedItem, connectivity, DEFAULT_WEIGHT, explicitSignificance, significance, uniqueID
-
-
Constructor Summary
Constructors Constructor Description CompositeItem()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
adding(Item item)
void
addItem(int index, Item item)
Inserts the item at a position and increases the index of existing items starting on this position by onevoid
addItem(Item item)
protected void
appendBodyString(java.lang.StringBuilder buffer)
Override to append the item body in the canonical query language of this item.CompositeItem
clone()
Returns a deep copy of this itemvoid
disclose(com.yahoo.prelude.query.textualrepresentation.Discloser discloser)
int
encode(java.nio.ByteBuffer buffer)
protected void
encodeThis(java.nio.ByteBuffer buffer)
Encodes just this item, not it's usual subitems, to the given buffer.protected int
encodingArity()
void
ensureNotInSubtree(CompositeItem item)
boolean
equals(java.lang.Object object)
Returns whether this item is of the same class and contains the same state as the given itemjava.util.Optional<Item>
extractSingleChild()
Will return its single child if itself can safely be omitted.Item
getItem(int index)
Returns a subitemint
getItemCount()
Returns the number of direct children of this itemint
getItemIndex(Item item)
Returns the index of a subitemjava.util.ListIterator<Item>
getItemIterator()
Returns a modifiable list iterator of the immediate children of thisint
getTermCount()
int
hashCode()
boolean
isLocked()
Whether this composite is in a mutable state.java.util.List<Item>
items()
Returns a read only list of the immediate children of thisvoid
lock()
Make composite immutable if this is supported.Item
removeItem(int index)
Removes the item at the given indexboolean
removeItem(Item item)
Removes the given item.void
setIndexName(java.lang.String index)
Sets the index name of all subitems of thisItem
setItem(int index, Item item)
Replaces the item at the given indexprotected boolean
shouldParenthize()
Composite items should be parenthized when not on the top level-
Methods inherited from class com.yahoo.prelude.query.Item
addAnnotation, appendHeadingString, getAnnotation, getBytes, getCode, getCreator, getItemType, getLabel, getLanguage, getName, getParent, getWeight, hasAnnotation, hasConnectivityBackLink, hasUniqueID, isFilter, isFromSpecialToken, isProtected, isRanked, isRoot, putBytes, putString, setCreator, setFilter, setFromSpecialToken, setHasUniqueID, setLabel, setLanguage, setParent, setPositionData, setProtected, setRanked, setWeight, toString, usePositionData
-
-
-
-
Method Detail
-
setIndexName
public void setIndexName(java.lang.String index)
Sets the index name of all subitems of this- Specified by:
setIndexName
in classItem
-
disclose
public void disclose(com.yahoo.prelude.query.textualrepresentation.Discloser discloser)
-
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 replaceitem
- 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
-
encodeThis
protected void encodeThis(java.nio.ByteBuffer buffer)
Encodes just this item, not it's usual subitems, to the given buffer.- Overrides:
encodeThis
in classItem
-
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 classItem
-
shouldParenthize
protected boolean shouldParenthize()
Composite items should be parenthized when not on the top level- Overrides:
shouldParenthize
in classItem
-
clone
public CompositeItem clone()
Returns a deep copy of this 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
-
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 classItem
-
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
-
-