com.jalios.jcms
Class QueryResultSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet<Publication>
              extended by com.jalios.jcms.QueryResultSet
All Implemented Interfaces:
Serializable, Cloneable, Iterable<Publication>, Collection<Publication>, Set<Publication>

public class QueryResultSet
extends HashSet<Publication>

This class holds results of a query.
It keeps tracks of all results (Publication) from a query and their scores.

Since:
jcms-5.5.0
Version:
$Revision: 48646 $
Author:
Olivier Jaquemet
See Also:
Serialized Form

Nested Class Summary
static class QueryResultSet.ScoreComparator<T extends Publication>
          This Comparator compares two Objects using a score retrieved from a map of Object to float.
 
Field Summary
static String REVISION
           
 
Constructor Summary
QueryResultSet()
           
 
Method Summary
 boolean add(Publication pub, float score)
          Adds the given Publication and its score to this QueryResultSet.
 boolean addAll(Collection<? extends Publication> coll)
          Overrides AbstractCollection.addAll(Collection) to call when addAll(QueryResultSet) if the specified collection is a QueryResultSet.
 boolean addAll(Collection<? extends Publication> coll, float score)
          Adds all the Publication in the specified collection to this QueryResultSet.
 boolean addAll(PageResult<Publication> pr)
          Adds the given PageResult to this QueryResultSet.
 boolean addAll(QueryResultSet resultSet)
          Adds all the Publication in the specified result Set to this QueryResultSet.
 void clear()
          Clear all Object from this result set (also remove associated score).
 SortedSet<Publication> getAsSortedSet()
          Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) using the ScoreComparator.
 SortedSet<Publication> getAsSortedSet(Class<? extends Publication> typeClazz, String comparatorName, boolean reverse)
          Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) retrieving the appropriate Comparator through ComparatorManager.
 SortedSet<Publication> getAsSortedSet(Comparator comparator)
          Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) using the given Comparator or none if null.
 SortedSet<Publication> getAsSortedSet(String comparatorName, boolean reverse)
          Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) retrieving the appropriate Comparator through ComparatorManager.
 Object getAttribute(String name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 Map<String,Object> getAttributeMap()
          Returns a java.util.Map of the attributes of this results.
 float getMaxScore()
          Retrieve the maximum score value available in this QueryResultSet.
 int getResultSize()
           
 float getScore(Object obj)
          Deprecated. use getScore(Publication)
 float getScore(Publication pub)
          Retrieve score of the specified Publication.
static Comparator getScoreComparator(QueryResultSet resultSet, Comparator parentComparator)
          Gets a new instance of a ScoreComparator for relevance sorting of the given QueryResultSet.
 PageResult.Status getStatus()
           
 int getTotalSize()
          Returns the total size of this QueryResultSet (it may be much larger than getResultSize().size() with DB query).
 boolean isHybrid()
           
 Iterator<Publication> iterator()
          Overrides HashSet.iterator() to wrap the native Iterator instance returned by the Java API with a custom one making sure the max score is updated on removal.
 boolean remove(Object o)
          Remove the given Object from this result set (also remove associated score).
 Object removeAttribute(String name)
          Removes an attribute from this result.
 boolean retainAll(Collection<?> coll)
          Overrides AbstractCollection.retainAll(Collection) to call when retainAll(QueryResultSet) if the specified collection is a QueryResultSet.
 boolean retainAll(QueryResultSet resultSet)
          Retains only the elements in this QueryResultSet that are contained in the specified QueryResultSet.
 Object setAttribute(String name, Object obj)
          Stores an attribute in this result.
 void setHybrid(boolean isHybrid)
           
 void setStatus(PageResult.Status status)
           
 void setTotalSize(int totalSize)
          Assigns the totla size of this QueryResultSet.
 
Methods inherited from class java.util.HashSet
add, clone, contains, isEmpty, size
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
containsAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll, toArray, toArray
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

QueryResultSet

public QueryResultSet()
Method Detail

setAttribute

public Object setAttribute(String name,
                           Object obj)
Stores an attribute in this result.
If the object passed in is null, the effect is the same as calling removeAttribute(java.lang.String).

Parameters:
name - a String specifying the name of the attribute
obj - the Object to be stored
Returns:
previous value associated with specified name, or null if there was no mapping for name. A null return can also indicate that null was associated with the specified name.

removeAttribute

public Object removeAttribute(String name)
Removes an attribute from this result.

Parameters:
name - a String specifying
Returns:
previous value associated with specified name, or null if there was no mapping for name. A null return can also indicate that null was associated with the specified name.

getAttribute

public Object getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

getAttributeMap

public Map<String,Object> getAttributeMap()
Returns a java.util.Map of the attributes of this results.

Returns:
the internal Map used by this results, modify with care.

add

public boolean add(Publication pub,
                   float score)
Adds the given Publication and its score to this QueryResultSet.
If a score for the given Object was already in this QueryResultSet for a given element, its score is replaced.

Parameters:
pub - the Publication to add.
score - the new score of the Publication
Returns:
true if the set did not already contain the specified element.
Since:
jcms-5.5.0

addAll

public boolean addAll(Collection<? extends Publication> coll,
                      float score)
Adds all the Publication in the specified collection to this QueryResultSet.
If a score was already in the Collection for a given element, its score is replaced.

Parameters:
coll - collection whose elements are to be added to this collection.
score - the score of the Publication in the Collection (should be between 0.0f and 1.0f)
Returns:
true if this collection changed as a result of the call.
Since:
jcms-5.5.0

addAll

public boolean addAll(QueryResultSet resultSet)
Adds all the Publication in the specified result Set to this QueryResultSet. Also puts all attribute of the specified QueryResultSet into this QueryResultSet.
If a Publication was already in this QueryResultSet, it is replaced with its score in the given QueryResultSet.

Parameters:
resultSet - QueryResultSet whose elements are to be added to this QueryResultSet.
Returns:
true if this collection changed as a result of the call.
Since:
jcms-5.5.0

retainAll

public boolean retainAll(QueryResultSet resultSet)
Retains only the elements in this QueryResultSet that are contained in the specified QueryResultSet. In other words, removes from this QueryResultSet all of its elements that are not contained in the specified QueryResultSet.

Also updates scores of elements kept in this QueryResultSet if their existing score are below the score of the specified QueryResultSet.

Parameters:
resultSet - elements to be retained in this collection.
Returns:
true if this QueryResultSet changed as a result of the call.
Since:
jcms-5.7.0

iterator

public Iterator<Publication> iterator()
Overrides HashSet.iterator() to wrap the native Iterator instance returned by the Java API with a custom one making sure the max score is updated on removal.

Needed for bug fix JCMS-3368.

Specified by:
iterator in interface Iterable<Publication>
Specified by:
iterator in interface Collection<Publication>
Specified by:
iterator in interface Set<Publication>
Overrides:
iterator in class HashSet<Publication>
Since:
jcms-5.7.0
See Also:
HashSet.iterator()

addAll

public boolean addAll(Collection<? extends Publication> coll)
Overrides AbstractCollection.addAll(Collection) to call when addAll(QueryResultSet) if the specified collection is a QueryResultSet.

Specified by:
addAll in interface Collection<Publication>
Specified by:
addAll in interface Set<Publication>
Overrides:
addAll in class AbstractCollection<Publication>
Since:
jcms-5.7.0
See Also:
addAll(QueryResultSet), AbstractCollection.addAll(Collection)

retainAll

public boolean retainAll(Collection<?> coll)
Overrides AbstractCollection.retainAll(Collection) to call when retainAll(QueryResultSet) if the specified collection is a QueryResultSet.

Specified by:
retainAll in interface Collection<Publication>
Specified by:
retainAll in interface Set<Publication>
Overrides:
retainAll in class AbstractCollection<Publication>
Since:
jcms-5.7.0
See Also:
retainAll(QueryResultSet), AbstractCollection.retainAll(Collection)

addAll

public boolean addAll(PageResult<Publication> pr)
Adds the given PageResult to this QueryResultSet.

Parameters:
pr - the PageResult
Returns:
true if this QueryResultSet changed as a result of the call.
Since:
jcms-7.0.1

remove

public boolean remove(Object o)
Remove the given Object from this result set (also remove associated score).

Specified by:
remove in interface Collection<Publication>
Specified by:
remove in interface Set<Publication>
Overrides:
remove in class HashSet<Publication>
Since:
jcms-5.5.0
See Also:
HashSet.remove(java.lang.Object)

clear

public void clear()
Clear all Object from this result set (also remove associated score).

Specified by:
clear in interface Collection<Publication>
Specified by:
clear in interface Set<Publication>
Overrides:
clear in class HashSet<Publication>
Since:
jcms-5.5.0
See Also:
HashSet.clear()

getScore

@Deprecated
public float getScore(Object obj)
Deprecated. use getScore(Publication)

Retrieve score of the given Object (a Publication).

Parameters:
obj - the Object (a Publication) from which to retrieve the score.
Returns:
score associated with given obj or 0.0f if no score is available for this Object.
Since:
jcms-5.5.0

getScore

public float getScore(Publication pub)
Retrieve score of the specified Publication.

Parameters:
pub - the Publication from which to retrieve the score.
Returns:
score associated with given obj or 0.0f if no score is available for this Publication.
Since:
jcms-6.0.0

getMaxScore

public float getMaxScore()
Retrieve the maximum score value available in this QueryResultSet.

Returns:
a float with the maximum score value.

getAsSortedSet

public SortedSet<Publication> getAsSortedSet()
Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) using the ScoreComparator. Because this method sort all the result in a new TreeSet, this method is expensive, be careful when using it.

Returns:
a new SortedSet (a TreeSet) using ScoreComparator.
Since:
jcms-5.5.0
See Also:
QueryResultSet.ScoreComparator

getAsSortedSet

public SortedSet<Publication> getAsSortedSet(Comparator comparator)
Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) using the given Comparator or none if null.

Because this method sort all the result in a new TreeSet, this method is expensive, be careful when using it.

Parameters:
comparator - the Comparator to use in the SortedSet, can be null to sort using natural order.
Returns:
a new SortedSet (a TreeSet) using ScoreComparator.
Since:
jcms-5.5.0
See Also:
QueryResultSet.ScoreComparator

getAsSortedSet

public SortedSet<Publication> getAsSortedSet(String comparatorName,
                                             boolean reverse)
Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) retrieving the appropriate Comparator through ComparatorManager.

Because this method sort all the result in a new TreeSet, this method is expensive, be careful when using it.

Parameters:
comparatorName - the name of the Comparator to use in the SortedSet, as available through ComparatorManager.
reverse - a boolean indicating whether the comparator should have its behavior reversed (true) or unchanged (false)
Returns:
a new SortedSet
Since:
jcms-7.1.0

getAsSortedSet

public SortedSet<Publication> getAsSortedSet(Class<? extends Publication> typeClazz,
                                             String comparatorName,
                                             boolean reverse)
Gets all the results contained in this QueryResultSet as a SortedSet (a TreeSet) retrieving the appropriate Comparator through ComparatorManager.

Because this method sort all the result in a new TreeSet, this method is expensive, be careful when using it.

Parameters:
typeClazz - the Class of Publication to sort
comparatorName - the name of the Comparator to use in the SortedSet, as available through ComparatorManager.
reverse - a boolean indicating whether the comparator should have its behavior reversed (true) or unchanged (false)
Returns:
a new SortedSet
Since:
jcms-7.1.0

getScoreComparator

public static Comparator getScoreComparator(QueryResultSet resultSet,
                                            Comparator parentComparator)
Gets a new instance of a ScoreComparator for relevance sorting of the given QueryResultSet.

Parameters:
resultSet - the QueryResultSet from which to retrieve score of each Publication.
parentComparator - the Comparator to use when score of compared Object are identical.
Returns:
parentComparator is resultSet is null, new instance of ScoreComparator using the given parent Comparator.
See Also:
QueryResultSet.ScoreComparator

getTotalSize

public int getTotalSize()
Returns the total size of this QueryResultSet (it may be much larger than getResultSize().size() with DB query).

Returns:
the total size of this QueryResultSet.
Since:
jcms-7.0.1

setTotalSize

public void setTotalSize(int totalSize)
Assigns the totla size of this QueryResultSet.

Parameters:
totalSize - the new total size.
Since:
jcms-7.0.1

getResultSize

public int getResultSize()

isHybrid

public boolean isHybrid()

setHybrid

public void setHybrid(boolean isHybrid)

setStatus

public void setStatus(PageResult.Status status)

getStatus

public PageResult.Status getStatus()


Copyright © 2001-2010 Jalios SA. All Rights Reserved.