com.facetmap.simple
Class SelectionData

java.lang.Object
  extended by com.facetmap.simple.SelectionData
All Implemented Interfaces:
Selection

public class SelectionData
extends java.lang.Object
implements Selection

A class intended for storage of Selection state. There's very little logic in here; it just accepts data and spits it out on request. It will do a bit of dynamic allocation when you set its facetmap, and it does have a rudimentary system to encode and decode its own ref.

Consider adding an equals() implementation and other basics.


Field Summary
 Facetmap facetmap
           
 java.util.Set[] headingSets
          Array of Sets of Headings, one Set per facet
static Logger logger
           
 java.util.Properties properties
           
 RefCodec refCodec
           
 int resultCount
           
 int resultLimit
           
 java.util.ArrayList results
           
 java.util.List[] subsets
          Array of Lists of Selections, one List per facet
 java.util.List[] supersets
          Array of Lists of Selections, one List per facet
 
Constructor Summary
SelectionData()
          Construct a SelectionData with no state defined at all.
SelectionData(Facetmap facetmap)
          Create a SelectionData with default or null values.
SelectionData(Selection selection)
          Selectively copy a Selection from another Selection.
 
Method Summary
 boolean containsAnyResources()
           
 void decodeRef(java.lang.String refCode)
          Sets the Headings of this Selection according to the given ref.
 java.util.Iterator getBackwardSelections(Facet facet)
          An Enumeration of the Selections that represent "backtracking" in navigation along the given dimension of facetspace.
 java.util.Iterator getBackwardSelections(int index)
          An array-oriented version of Selection.getHeadings(Facet) .
 int getFacetCount()
           
 Facetmap getFacetmap()
           
 java.util.Iterator getForwardSelections(Facet facet)
          An Enumeration of the Selections that are the possible "next steps" in navigation along the given dimension of facetspace.
 java.util.Iterator getForwardSelections(int index)
          An array-oriented version of Selection.getHeadings(Facet) .
 Heading[] getHeadings()
           
 Heading[] getHeadings(Facet facet)
          Returns the Heading(s) of this selection in a specified facet.
 Heading[] getHeadings(int index)
          Returns the Heading along the given dimension of facetspace.
 java.util.Properties getProperties()
          The properties that were used in the creation of this Selection.
 java.lang.String getRef()
          Returns a String ID (known as a reference or "ref") that uniquely identifies the Headings used to construct this Selection.
 int getResourceCount()
          The number of Resources specified by the Headings in this Selection (regardless of any maximum specified by property com.facetmap.Selection.resultLimit).
 SelectedResourceIterator getResources()
          Return an Iterator containing all Resources specified by this Selection, or the first N Resources specified by this Selection where N is the value of com.facetmap.Selection.resultLimit .
 java.util.Collection getSubset(int facetIndex)
           
 java.util.Collection getSuperset(int facetIndex)
           
 boolean isMasterRoot()
          Returns true if each of this Selection's Headings is the Root of its Facet.
static Heading[] replaceHeadings(Heading[] headings, Selection selection)
          Create a list of Headings by combining the two input arguments.
 Heading[] serializeHeadings(java.util.Set[] headingSets)
          Inverse of sortHeadings() , but imposes some order: headings are ordered according to their facet index (ascending).
 void setHeadings(Heading[] headings)
          Sets the given Headings as all the Headings of this Selection.
 void setHeadings(int index, Heading[] headings)
          Sets the given Headings as the Headings in a particular Facet of this Selection.
 void setHeadings(java.util.Set[] headingSets)
          Sets the given Headings as all the Headings of this Selection.
 java.util.Set[] sortHeadings(Heading[] headings)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static final Logger logger

properties

public java.util.Properties properties

headingSets

public java.util.Set[] headingSets
Array of Sets of Headings, one Set per facet


supersets

public java.util.List[] supersets
Array of Lists of Selections, one List per facet


subsets

public java.util.List[] subsets
Array of Lists of Selections, one List per facet


resultCount

public int resultCount

resultLimit

public int resultLimit

results

public java.util.ArrayList results

facetmap

public Facetmap facetmap

refCodec

public RefCodec refCodec
Constructor Detail

SelectionData

public SelectionData()
Construct a SelectionData with no state defined at all. May be unstable. For low-level operations only. Not too useful unless a Selection is being built at the same time as its facetmap.


SelectionData

public SelectionData(Facetmap facetmap)
Create a SelectionData with default or null values.


SelectionData

public SelectionData(Selection selection)
Selectively copy a Selection from another Selection. Only the facetmap and headings are copied; otherwise this is equivalent to SelectionData(Facetmap) .

Method Detail

getSuperset

public java.util.Collection getSuperset(int facetIndex)

getSubset

public java.util.Collection getSubset(int facetIndex)

getHeadings

public Heading[] getHeadings(int index)
                      throws java.lang.ArrayIndexOutOfBoundsException
Returns the Heading along the given dimension of facetspace.

Specified by:
getHeadings in interface Selection
Throws:
java.lang.ArrayIndexOutOfBoundsException

getHeadings

public Heading[] getHeadings()

setHeadings

public void setHeadings(int index,
                        Heading[] headings)
                 throws java.lang.IllegalArgumentException
Sets the given Headings as the Headings in a particular Facet of this Selection. Headings in other facets are unaffected.

Throws:
java.lang.IllegalArgumentException

setHeadings

public void setHeadings(Heading[] headings)
                 throws java.lang.IllegalArgumentException
Sets the given Headings as all the Headings of this Selection. Headings need not be in facet order; this method sorts Headings by facet for internal purposes.

Throws:
java.lang.IllegalArgumentException

setHeadings

public void setHeadings(java.util.Set[] headingSets)
Sets the given Headings as all the Headings of this Selection. Headings are assumed to be sorted already into array elements according to facet index.


isMasterRoot

public boolean isMasterRoot()
Returns true if each of this Selection's Headings is the Root of its Facet.

Specified by:
isMasterRoot in interface Selection
See Also:
Facet.getRootHeading()

getRef

public java.lang.String getRef()
Description copied from interface: Selection
Returns a String ID (known as a reference or "ref") that uniquely identifies the Headings used to construct this Selection. Consumers may use this ref string to implement their own serialization.

The reference does not contain information about the Properties used in this selection. If desired, those must be serialized separately.

Specified by:
getRef in interface Selection

decodeRef

public void decodeRef(java.lang.String refCode)
               throws UnknownReferenceException
Sets the Headings of this Selection according to the given ref.

Throws:
UnknownReferenceException

containsAnyResources

public boolean containsAnyResources()
                             throws InternalException
Throws:
InternalException

getForwardSelections

public java.util.Iterator getForwardSelections(int index)
                                        throws InternalException,
                                               java.lang.ArrayIndexOutOfBoundsException
Description copied from interface: Selection
An array-oriented version of Selection.getHeadings(Facet) . Provide the ordinal index number of the Facet within the FacetSpace, instead of the Facet itself.

Specified by:
getForwardSelections in interface Selection
Throws:
InternalException
java.lang.ArrayIndexOutOfBoundsException

getBackwardSelections

public java.util.Iterator getBackwardSelections(int index)
                                         throws InternalException,
                                                java.lang.ArrayIndexOutOfBoundsException
Description copied from interface: Selection
An array-oriented version of Selection.getHeadings(Facet) . Provide the ordinal index number of the Facet within the FacetSpace, instead of the Facet itself.

Specified by:
getBackwardSelections in interface Selection
Throws:
InternalException
java.lang.ArrayIndexOutOfBoundsException

getFacetCount

public int getFacetCount()
Specified by:
getFacetCount in interface Selection

getFacetmap

public Facetmap getFacetmap()
Specified by:
getFacetmap in interface Selection

getProperties

public java.util.Properties getProperties()
Description copied from interface: Selection
The properties that were used in the creation of this Selection. This set of properties can be different from the set that was specified in Facetmap.getSelection() because the facetmap may not recognize or honor all properties; see that method for details.

Specified by:
getProperties in interface Selection
See Also:
Facetmap.getSelection(Heading[], Properties)

getResourceCount

public int getResourceCount()
                     throws InternalException
Description copied from interface: Selection
The number of Resources specified by the Headings in this Selection (regardless of any maximum specified by property com.facetmap.Selection.resultLimit).

This could be regarded as just a special case of getResourceWeight() , but of course it's by far the most common and we want a method that returns an int.

Specified by:
getResourceCount in interface Selection
Throws:
InternalException

getResources

public SelectedResourceIterator getResources()
                                      throws InternalException
Description copied from interface: Selection
Return an Iterator containing all Resources specified by this Selection, or the first N Resources specified by this Selection where N is the value of com.facetmap.Selection.resultLimit .

Specified by:
getResources in interface Selection
Throws:
InternalException

getBackwardSelections

public java.util.Iterator getBackwardSelections(Facet facet)
                                         throws InternalException,
                                                java.lang.ArrayIndexOutOfBoundsException
Description copied from interface: Selection
An Enumeration of the Selections that represent "backtracking" in navigation along the given dimension of facetspace. Exactly what "backtracking" entails is a little dependent on the type of Facet used in this dimension. It is never required that a returned Selection be a Selection already visited by the user; see the notes on directionality in Facet.

Specified by:
getBackwardSelections in interface Selection
Throws:
InternalException
java.lang.ArrayIndexOutOfBoundsException
See Also:
Facet

getForwardSelections

public java.util.Iterator getForwardSelections(Facet facet)
                                        throws InternalException,
                                               java.lang.ArrayIndexOutOfBoundsException
Description copied from interface: Selection
An Enumeration of the Selections that are the possible "next steps" in navigation along the given dimension of facetspace.

If property com.facetmap.Selection.autoSelectOnlyChild is set true, then this method may not return exactly one Selection (an "only child"). If it would ordinarily return an only child, it must return the forward selections of that child (and act recursively until the size of the result set is not one).

If property com.facetmap.Selection.showEmptySelections is set true, this method will return all possible forward Selections in the Facet, even those that contain no resources (as defined by getContainedResources). Otherwise, Selections with no contained resources must not appear in the result.

Specified by:
getForwardSelections in interface Selection
Throws:
InternalException
java.lang.ArrayIndexOutOfBoundsException

getHeadings

public Heading[] getHeadings(Facet facet)
                      throws java.lang.ArrayIndexOutOfBoundsException
Description copied from interface: Selection
Returns the Heading(s) of this selection in a specified facet. The returned array always contains at least one Heading -- if no Heading from the specified facet was used to create this Selection, then the root Heading is returned. In other words, it's always safe to reference getHeading(facet)[0] as a non-null Heading.

Note that the return value, because it is an array, can be modified. However, modifying it does not change the state of this underlying Selection. Implementors of Selection should take care that this rule is enforced.

Specified by:
getHeadings in interface Selection
Throws:
java.lang.ArrayIndexOutOfBoundsException

sortHeadings

public java.util.Set[] sortHeadings(Heading[] headings)

serializeHeadings

public Heading[] serializeHeadings(java.util.Set[] headingSets)
Inverse of sortHeadings() , but imposes some order: headings are ordered according to their facet index (ascending). No order is guaranteed within a facet.


replaceHeadings

public static Heading[] replaceHeadings(Heading[] headings,
                                        Selection selection)
Create a list of Headings by combining the two input arguments. For each facet represented in headings, headings are copied from headings ; for all other facets, headings are copied from selection .


toString

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