com.im.df.api 5.8

com.im.df.api.support
Class SelectionDescription

java.lang.Object
  extended by com.im.df.api.support.SelectionDescription
All Implemented Interfaces:
Iterable<Integer>

public final class SelectionDescription
extends Object
implements Iterable<Integer>

Generic description of selection. Each selection can be in one of the following (disjunct) states:

SelectionDescription is an immutable object - once it is created it cannot be changed. You need to create a new one if you want to change the selection.

SelectionDescription implements Iterable interface which iterates through selected indices of the instance. Note that this allows SelectionDescription instance to be used in foreach loop:

  SelectionDescription selection = ...;
  for (Integer selectedIndex : selection) {
      // do something with selectedIndex
  }
 

Selection have a subselection which is represented as another SelectionDescription instance and can be obatined with getSubSelection() method. Subselection contains a subset of indexes of its main selection. E.g.:

   Selection: {100, 101, ..., 110}
   Subselection: {102, 105, 106}
 

To get a relative subselection, i.e. indexes into main selection, use getRelativeSubSelection() method. There are several other methods to work with subselection. See Javadoc of individual methods for details.


Field Summary
static SelectionDescription EMPTY
          Empty selection
 
Method Summary
static SelectionDescription complement(SelectionDescription sd1, SelectionDescription sd2)
          Returns selection description containing relative complement of sd2 in sd1.
static SelectionDescription convertToAbsoluteSubSelection(SelectionDescription selection, Collection<? extends Integer> relativeSubselection)
          Takes relative subselection in form of a Collection and converts it to absolute subselection within the given selection.
static SelectionDescription convertToAbsoluteSubSelection(SelectionDescription selection, ListSelectionModel relativeSubselection)
          Takes relative subselection in form of a ListSelectionModel and converts it to absolute subselection within the given selection.
static SelectionDescription create(int singleRowIndex)
          Creates the single row selection
static SelectionDescription create(int minIndex, int maxIndex)
          Create selection for a single interval [min,max].
static SelectionDescription create(List<? extends Integer> indexes)
          Crete a new selection based on the given indexes.
static SelectionDescription create(ListSelectionModel listSelectionModel)
          Returns a new selection from a ListSelectionModel with empty subselection.
static SelectionDescription create(ListSelectionModel listSelectionModel, SelectionDescription subSelection)
          Returns a new selection having main selection corresponding to a given ListSelectionModel with subselection set to given subSelection parameter.
static SelectionDescription create(SelectionDescription oldSel, List<? extends Comparable<?>> oldIds, List<? extends Comparable<?>> newIds)
          This method can be used when ids are reordered or completely changed and you want to recalculate the selection.
static SelectionDescription create(SelectionDescription selection, ListSelectionModel listSubSelectionModel)
          Returns a new selection having main selection same as a given selection and subselection corresponding to a given ListSelectionModel.
static SelectionDescription create(SelectionDescription selection, SelectionDescription subSelection)
          Create selection for a single interval [min,max].
 boolean equals(Object obj)
           
 int getMaxSelectionIndex()
          Returns the last selected index or -1 if the selection is empty.
 int getMinSelectionIndex()
          Returns the first selected index or -1 if the selection is empty.
 SelectionDescription getRelativeSubSelection()
          Returns subselection of this selection but with indexes relative to this selection.
 int getSelectedRowsCount()
          Get count of rows represented by this selection.
 SelectionDescription getSubSelection()
          Returns subselection within this selection.
 int hashCode()
           
static SelectionDescription intersection(SelectionDescription sd1, SelectionDescription sd2)
          Returns intersection of the given selection descriptions.
 boolean isEmpty()
          Is the selection empty?
 boolean isMultiInterval()
          Does this selection represent more intervals?
 boolean isSelectedIndex(int index)
          Returns true if the specified index is selected.
 boolean isSingleInterval()
          Does this selection represent a single interval?
 boolean isSingleRow()
          Does this selection represent a single row?
 Iterator<Integer> iterator()
           
static SelectionDescription move(SelectionDescription origSelection, int delta, int rowCount)
          Create a new moved selection based on original one.
 String toString()
           
 String toStringSimple(boolean startFromRowOne)
          Return only selected rows indexes.
static SelectionDescription union(SelectionDescription sd1, SelectionDescription sd2)
          Returns union of the given selection descriptions.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final SelectionDescription EMPTY
Empty selection

Method Detail

create

public static SelectionDescription create(SelectionDescription oldSel,
                                          List<? extends Comparable<?>> oldIds,
                                          List<? extends Comparable<?>> newIds)
This method can be used when ids are reordered or completely changed and you want to recalculate the selection. SelectionDescription object works with indexes and never with real values. It means when IDs (primary key values) are for example reordered, the new selection indexes must be recalculated. You must provide both (original and a new) lists of IDS and of course the original selection. New selection is computed from these objects.

New selection contains obviously only those values which are present in newIds list. It means new selection will contain the same or less selected rows. In extreme case new selection can be EMPTY (if no originally selected value is present in newIds).

Parameters:
oldSel - The original selection
oldIds - The original list of ids (usually primary key values)
newIds - The new list of ids (can contain the same or completely different values)
Returns:
The new SelectionDescription

union

public static SelectionDescription union(SelectionDescription sd1,
                                         SelectionDescription sd2)
Returns union of the given selection descriptions. I.e. all indices selected either in sd1 or in sd2.


intersection

public static SelectionDescription intersection(SelectionDescription sd1,
                                                SelectionDescription sd2)
Returns intersection of the given selection descriptions. I.e. all indices selected both - sd1 and sd2.


complement

public static SelectionDescription complement(SelectionDescription sd1,
                                              SelectionDescription sd2)
Returns selection description containing relative complement of sd2 in sd1. I.e. indices which are selected in sd1 but not in sd2.


create

public static SelectionDescription create(List<? extends Integer> indexes)
Crete a new selection based on the given indexes.

Parameters:
indexes - indexes to be selected.
Returns:
a new selection description

create

public static SelectionDescription create(int singleRowIndex)
Creates the single row selection


create

public static SelectionDescription create(ListSelectionModel listSelectionModel,
                                          SelectionDescription subSelection)
Returns a new selection having main selection corresponding to a given ListSelectionModel with subselection set to given subSelection parameter.

Parameters:
listSelectionModel - main selection
subSelection - subselection
Returns:
new selection

create

public static SelectionDescription create(SelectionDescription selection,
                                          ListSelectionModel listSubSelectionModel)
Returns a new selection having main selection same as a given selection and subselection corresponding to a given ListSelectionModel.

Parameters:
selection - main selection
listSubSelectionModel - subselection
Returns:
new selection

create

public static SelectionDescription create(ListSelectionModel listSelectionModel)
Returns a new selection from a ListSelectionModel with empty subselection.

Parameters:
listSelectionModel - main selection
Returns:
new selection

create

public static SelectionDescription create(int minIndex,
                                          int maxIndex)
Create selection for a single interval [min,max]. All values inside the interval (including min and max) are selected.


create

public static SelectionDescription create(SelectionDescription selection,
                                          SelectionDescription subSelection)
Create selection for a single interval [min,max]. All values inside the interval (including min and max) are selected.


move

public static SelectionDescription move(SelectionDescription origSelection,
                                        int delta,
                                        int rowCount)
Create a new moved selection based on original one.

Parameters:
origSelection - Original selection to be moved
delta - The number of rows to move the selection. Can be either positive or negative number.
rowCount - The total number of rows in the table. This parameter is here because of overflow prevention. New selection will respect this table size and won't go over it.

convertToAbsoluteSubSelection

public static SelectionDescription convertToAbsoluteSubSelection(SelectionDescription selection,
                                                                 ListSelectionModel relativeSubselection)
Takes relative subselection in form of a ListSelectionModel and converts it to absolute subselection within the given selection. I.e. if range of the given selection is <100, 110> and given relativeSubselection contains (3, 4, 5, 8) the result is a new SelectionDescription instance with (103, 104, 105, 108) indices.

Parameters:
selection - main selection
relativeSubselection - relative subselection within the given selection
Returns:
absolute subselection within the given selection

convertToAbsoluteSubSelection

public static SelectionDescription convertToAbsoluteSubSelection(SelectionDescription selection,
                                                                 Collection<? extends Integer> relativeSubselection)
Takes relative subselection in form of a Collection and converts it to absolute subselection within the given selection. I.e. if range of the given selection is <100, 110> and given relativeSubselection contains (3, 4, 5, 8) the result is a new SelectionDescription instance with (103, 104, 105, 108) indices.

Parameters:
selection - main selection
relativeSubselection - relative subselection within the given selection
Returns:
absolute subselection within the given selection

getRelativeSubSelection

public SelectionDescription getRelativeSubSelection()
Returns subselection of this selection but with indexes relative to this selection. I.e. if the selection represents range <100, 110> and its subselection is (103, 104, 105, 108), the returned selection is (3, 4, 5, 8).

Returns:
subselection of this selection with indexes relative to this selection

getSubSelection

public SelectionDescription getSubSelection()
Returns subselection within this selection.

Returns:
subselection; never null

iterator

public Iterator<Integer> iterator()
Specified by:
iterator in interface Iterable<Integer>

getMinSelectionIndex

public int getMinSelectionIndex()
Returns the first selected index or -1 if the selection is empty.


getMaxSelectionIndex

public int getMaxSelectionIndex()
Returns the last selected index or -1 if the selection is empty.


getSelectedRowsCount

public int getSelectedRowsCount()
Get count of rows represented by this selection.


isSingleRow

public boolean isSingleRow()
Does this selection represent a single row?


isSingleInterval

public boolean isSingleInterval()
Does this selection represent a single interval?


isMultiInterval

public boolean isMultiInterval()
Does this selection represent more intervals?


isEmpty

public boolean isEmpty()
Is the selection empty?


isSelectedIndex

public boolean isSelectedIndex(int index)
Returns true if the specified index is selected.


equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toStringSimple

public String toStringSimple(boolean startFromRowOne)
Return only selected rows indexes. For empty selection returns "", for single row selection returns e.g. "2", for interval returns e.g. "4-6"

Parameters:
startFromRowOne - If true first row has number 1; otherwise 0.

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

com.im.df.api 5.8