com.endeca.portal.data
Class QueryState

java.lang.Object
  extended by com.endeca.portal.data.QueryState
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class QueryState
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

QueryState is an API-agnostic representation of a query that can be executed against an MDEX engine to retrieve results. QueryState instances can be interacted with and altered via their list of QueryFunction instances.

See Also:
DataSource, QueryFunction, Serialized Form

Constructor Summary
QueryState()
          Instantiate a QueryState with empty function list.
QueryState(org.json.JSONArray serializedState)
          Instantiate a QueryState from a serialized representation.
 
Method Summary
 void addFunction(QueryFunction function)
          Deprecated. use addFunction(QueryFunction,SemanticView,Locale) instead TODO: make this method private?
 void addFunction(QueryFunction function, SemanticView semanticView, java.util.Locale currentLocale)
          Add a specified QueryFunction to this QueryState, checking for duplicate multi select attribute refinements and override any single select attribute refinements The attribute keys in the QueryFunctions are substituted with locale-specific attribute keys using semanticView, which is an AttributeKeyConverter.
 void addFunctions(java.util.List<? extends QueryFunction> functions)
          Deprecated. use addFunctions(List, SemanticView, Locale) instead
 void addFunctions(java.util.List<? extends QueryFunction> functions, SemanticView semanticView, java.util.Locale currentLocale)
          Add a list of QueryFunctions to this QueryState The attribute keys in the QueryFunctions are substituted with locale-specific attribute keys using semanticView, which is an AttributeKeyConverter.
 QueryState clone()
           
static java.util.List<QueryFunction> cloneFunctionList(java.util.List<QueryFunction> list)
          Clone a List of QueryFunction instances.
 boolean equivalent(QueryState q)
          Convenience method to check equivalence of query states A QueryState is equivalent to another if they contain the same non-QueryConfig QueryFunctions, in the same order.
 java.util.Map<java.lang.String,java.util.List<AutoAppliedFilter<QueryFilter>>> getAutoAppliedFilters()
           
 java.util.List<QueryFunction> getFunctions()
          Get direct access to the QueryFunction list.
<T extends QueryFunction>
java.util.List<T>
getFunctions(java.lang.Class<T> klass)
          Get a list of all query functions of the specified class (determined using .isInstance) associated with the specified viewKey.
 int getNextQueryFilterId()
          Gets a unique ID value to use on filters contained in this state.
 long getQueryStateVersion()
           
 void removeAllFunctions()
          Clear all query functions from this query state
 void removeFunction(QueryFunction function)
          Remove particular function based on .equals() equality
 void removeFunctions(java.lang.Class<? extends QueryFunction> klass)
          Removes each filter in the list of a given type (determined using .isInstance).
 void removeFunctions(java.util.List<? extends QueryFunction> functions)
          Remove each function in the given list based on .equals() equality
 void setAutoAppliedFilters(java.util.Map<java.lang.String,java.util.List<AutoAppliedFilter<QueryFilter>>> autoAppliedFilters)
           
protected  void setQueryStateVersion(long queryStateVersion)
           
 org.json.JSONArray toJSON()
          Create a JSON representation of this query state and its query functions.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryState

public QueryState()
Instantiate a QueryState with empty function list.


QueryState

public QueryState(org.json.JSONArray serializedState)
Instantiate a QueryState from a serialized representation.

Parameters:
serializedState -
See Also:
toJSON()
Method Detail

addFunction

public void addFunction(QueryFunction function)
Deprecated. use addFunction(QueryFunction,SemanticView,Locale) instead TODO: make this method private?

Add a specified QueryFunction to this QueryState, checking for duplicate multi select attribute refinements and override any single select attribute refinements

Parameters:
function - the function to add

addFunction

public void addFunction(QueryFunction function,
                        SemanticView semanticView,
                        java.util.Locale currentLocale)
Add a specified QueryFunction to this QueryState, checking for duplicate multi select attribute refinements and override any single select attribute refinements The attribute keys in the QueryFunctions are substituted with locale-specific attribute keys using semanticView, which is an AttributeKeyConverter.

Parameters:
function -
semanticView -
currentLocale -

addFunctions

public void addFunctions(java.util.List<? extends QueryFunction> functions)
Deprecated. use addFunctions(List, SemanticView, Locale) instead

Add a list of QueryFunctions to this QueryState

Parameters:
functions - the list of functions to add

addFunctions

public void addFunctions(java.util.List<? extends QueryFunction> functions,
                         SemanticView semanticView,
                         java.util.Locale currentLocale)
Add a list of QueryFunctions to this QueryState The attribute keys in the QueryFunctions are substituted with locale-specific attribute keys using semanticView, which is an AttributeKeyConverter.

Parameters:
functions -
semanticView -
currentLocale -

removeFunction

public void removeFunction(QueryFunction function)
Remove particular function based on .equals() equality

Parameters:
function - The function to remove

removeFunctions

public void removeFunctions(java.util.List<? extends QueryFunction> functions)
Remove each function in the given list based on .equals() equality

Parameters:
functions - The functions to remove

removeFunctions

public void removeFunctions(java.lang.Class<? extends QueryFunction> klass)
Removes each filter in the list of a given type (determined using .isInstance).

Parameters:
klass - The class of filters to remove

removeAllFunctions

public void removeAllFunctions()
Clear all query functions from this query state


getFunctions

public java.util.List<QueryFunction> getFunctions()
Get direct access to the QueryFunction list.

Returns:
the query function list

getFunctions

public <T extends QueryFunction> java.util.List<T> getFunctions(java.lang.Class<T> klass)
Get a list of all query functions of the specified class (determined using .isInstance) associated with the specified viewKey.

Type Parameters:
T -
Parameters:
klass - The class, extending from QueryFunction, to match against
Returns:
The list of query functions

toJSON

public org.json.JSONArray toJSON()
Create a JSON representation of this query state and its query functions.

Returns:
the JSON representation

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public QueryState clone()
Overrides:
clone in class java.lang.Object

cloneFunctionList

public static java.util.List<QueryFunction> cloneFunctionList(java.util.List<QueryFunction> list)
Clone a List of QueryFunction instances.

Parameters:
list - the list to clone
Returns:
a List that is equivalent to the passed in list

equivalent

public boolean equivalent(QueryState q)
Convenience method to check equivalence of query states A QueryState is equivalent to another if they contain the same non-QueryConfig QueryFunctions, in the same order.

Parameters:
q - The query state to compare against
Returns:
true if the query states are equivalent, false otherwise.

getNextQueryFilterId

public int getNextQueryFilterId()
Gets a unique ID value to use on filters contained in this state. Intended to be called only by QueryFilter objects in this package.

Returns:
a unique filter ID integer value

getAutoAppliedFilters

public java.util.Map<java.lang.String,java.util.List<AutoAppliedFilter<QueryFilter>>> getAutoAppliedFilters()

setAutoAppliedFilters

public void setAutoAppliedFilters(java.util.Map<java.lang.String,java.util.List<AutoAppliedFilter<QueryFilter>>> autoAppliedFilters)

getQueryStateVersion

public long getQueryStateVersion()

setQueryStateVersion

protected void setQueryStateVersion(long queryStateVersion)