public class SubsetSolution extends Solution
getSelectedIDs()
, getUnselectedIDs()
and
getAllIDs()
to the NavigableSet
subtype.Constructor and Description |
---|
SubsetSolution(Set<Integer> allIDs)
Creates a new subset solution given the set of all IDs, each corresponding to an underlying entity,
from which a subset is to be selected.
|
SubsetSolution(Set<Integer> allIDs,
boolean naturalOrder)
Creates a new subset solution given the set of all IDs, each corresponding to an underlying entity,
from which a subset is to be selected.
|
SubsetSolution(Set<Integer> allIDs,
Comparator<Integer> orderOfIDs)
Creates a new subset solution given the set of all IDs, each corresponding to an underlying entity,
from which a subset is to be selected.
|
SubsetSolution(Set<Integer> allIDs,
Set<Integer> selectedIDs)
Creates a new subset solution given the set of all IDs, and the set of currently selected IDs.
|
SubsetSolution(Set<Integer> allIDs,
Set<Integer> selectedIDs,
boolean naturalOrder)
Creates a new subset solution given the set of all IDs, and the set of currently selected IDs.
|
SubsetSolution(Set<Integer> allIDs,
Set<Integer> selectedIDs,
Comparator<Integer> orderOfIDs)
Creates a new subset solution given the set of all IDs, and the set of currently selected IDs.
|
SubsetSolution(SubsetSolution sol)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
SubsetSolution |
copy()
Create a deep copy of this subset solution, obtained through the copy constructor.
|
boolean |
deselect(int ID)
Deselect the given ID.
|
void |
deselectAll()
Deselect all IDs.
|
boolean |
deselectAll(Collection<Integer> IDs)
Deselect all IDs contained in the given collection.
|
boolean |
equals(Object other)
Checks whether the given other object represents the same subset solution.
|
Set<Integer> |
getAllIDs()
Returns an unmodifiable view of the set of all IDs.
|
int |
getNumSelectedIDs()
Get the number of IDs which are currently selected.
|
int |
getNumUnselectedIDs()
Get the number of IDs which are currently unselected.
|
Comparator<Integer> |
getOrderOfIDs()
Get the comparator according to which the IDs are ordered, as specified at construction.
|
Set<Integer> |
getSelectedIDs()
Returns an unmodifiable view of the set of currently selected IDs.
|
int |
getTotalNumIDs()
Get the total number of IDs.
|
Set<Integer> |
getUnselectedIDs()
Returns an unmodifiable view of the set of currently non selected IDs.
|
int |
hashCode()
Computes a hash code that is consistent with the implementation of
equals(Object) meaning that
the same hash code is returned for equal subset solutions. |
boolean |
select(int ID)
Select the given ID.
|
void |
selectAll()
Select all IDs.
|
boolean |
selectAll(Collection<Integer> IDs)
Select all IDs contained in the given collection.
|
String |
toString()
Creates a formatted string containing the selected IDs.
|
checkedCopy
public SubsetSolution(Set<Integer> allIDs)
allIDs
- set of all IDs from which a subset is to be selectedNullPointerException
- if allIDs
is null
or contains any null
elementsIllegalArgumentException
- if allIDs
is emptypublic SubsetSolution(Set<Integer> allIDs, Set<Integer> selectedIDs)
allIDs
- set of all IDs from which a subset is to be selectedselectedIDs
- set of currently selected IDs (subset of all IDs)NullPointerException
- if allIDs
or selectedIDs
are null
or contain any null
elementsIllegalArgumentException
- if allIDs
is empty or selectedIDs
is not a subset of allIDs
public SubsetSolution(Set<Integer> allIDs, boolean naturalOrder)
naturalOrder
is true
, the sets of selected, unselected and all IDs are represented
as navigable sorted sets ordered according to the natural ordering of integers (ascending); else, no ordering
is imposed.allIDs
- set of all IDs from which a subset is to be selectednaturalOrder
- if naturalOrder
is true
, IDs will be ordered according to
their natural ordering; else, no ordering is imposed on the IDsNullPointerException
- if allIDs
is null
or contains any null
elementsIllegalArgumentException
- if allIDs
is emptypublic SubsetSolution(Set<Integer> allIDs, Set<Integer> selectedIDs, boolean naturalOrder)
naturalOrder
is true
, the sets of selected, unselected and all
IDs are represented as navigable sorted sets ordered according to the natural ordering of integers (ascending);
else, no ordering is imposed.allIDs
- set of all IDs from which a subset is to be selectedselectedIDs
- set of currently selected IDs (subset of all IDs)naturalOrder
- if naturalOrder
is true
, IDs will be ordered according to
their natural ordering; else, no ordering is imposed on the IDsNullPointerException
- if allIDs
or selectedIDs
are null
or contain any null
elementsIllegalArgumentException
- if allIDs
is empty or selectedIDs
is not a subset of allIDs
public SubsetSolution(Set<Integer> allIDs, Comparator<Integer> orderOfIDs)
orderOfIDs
is not null
, the sets of selected, unselected and all IDs are
represented as navigable sorted sets ordered according to this comparator; else, no ordering is imposed.allIDs
- set of all IDs from which a subset is to be selectedorderOfIDs
- comparator according to which IDs are ordered, allowed to be
null
in which case no order is imposedNullPointerException
- if allIDs
is null
or contains any null
elementsIllegalArgumentException
- if allIDs
is emptypublic SubsetSolution(Set<Integer> allIDs, Set<Integer> selectedIDs, Comparator<Integer> orderOfIDs)
orderOfIDs
is not null
, the sets of selected, unselected and
all IDs are represented as navigable sorted sets ordered according to this comparator; else, no ordering is
imposed.allIDs
- set of all IDs from which a subset is to be selectedselectedIDs
- set of currently selected IDs (subset of all IDs)orderOfIDs
- comparator according to which IDs are ordered, allowed to be
null
in which case no order is imposedNullPointerException
- if allIDs
or selectedIDs
are null
or contain any null
elementsIllegalArgumentException
- if allIDs
is empty or selectedIDs
is not a subset of allIDs
public SubsetSolution(SubsetSolution sol)
sol
- solution to copy (deep copy)public SubsetSolution copy()
public Comparator<Integer> getOrderOfIDs()
null
which means that no order has been imposed.null
public boolean select(int ID)
SolutionModificationException
is thrown.
If the ID is currently already selected, the subset solution is not modified and false is returned. Finally,
true is returned if the ID has been successfully selected.ID
- ID to be selectedSolutionModificationException
- if there is no entity with this IDpublic boolean deselect(int ID)
SolutionModificationException
is thrown.
If the ID is currently not selected, the subset solution is not modified and false is returned. Finally,
true is returned if the ID has been successfully deselected.ID
- ID to be deselectedSolutionModificationException
- if there is no entity with this IDpublic boolean selectAll(Collection<Integer> IDs)
IDs
- collection of IDs to be selectedSolutionModificationException
- if the given collection contains at least one ID which does not correspond to an entityNullPointerException
- if null
is passed or the given collection contains at least one null
elementpublic boolean deselectAll(Collection<Integer> IDs)
IDs
- collection of IDs to be deselectedSolutionModificationException
- if the given collection contains at least one ID which does not correspond to an entityNullPointerException
- if null
is passed or the given collection contains at least one null
elementpublic void selectAll()
public void deselectAll()
public Set<Integer> getSelectedIDs()
UnsupportedOperationException
. If
the IDs are ordered (see getOrderOfIDs()
), it is safe to cast the returned
view to the NavigableSet
subtype.public Set<Integer> getUnselectedIDs()
UnsupportedOperationException
. If
the IDs are ordered (see getOrderOfIDs()
), it is safe to cast the returned
view to the NavigableSet
subtype.public Set<Integer> getAllIDs()
UnsupportedOperationException
. If the IDs are ordered (see
getOrderOfIDs()
), it is safe to cast the returned view to the NavigableSet
subtype. This set will always be equal to the union of getSelectedIDs()
and
getUnselectedIDs()
.public int getNumSelectedIDs()
public int getNumUnselectedIDs()
public int getTotalNumIDs()
getNumSelectedIDs()
and getNumUnselectedIDs()
.public boolean equals(Object other)
public int hashCode()
equals(Object)
meaning that
the same hash code is returned for equal subset solutions. The computed hash code is a linear combination
of the hash codes of both the set of selected and unselected IDs, added to a constant.Copyright © 2016. All rights reserved.