public class Partition extends Object
Constructor and Description |
---|
Partition()
Creates a new, empty partition with no cells.
|
Partition(int[][] cellData)
Constructor to make a partition from an array of int arrays.
|
Partition(Partition other)
Copy constructor to make one partition from another.
|
Modifier and Type | Method and Description |
---|---|
void |
addCell(Collection<Integer> elements)
Adds a new cell to the end of the partition.
|
void |
addCell(int... elements)
Adds a new cell to the end of the partition containing these elements.
|
void |
addSingletonCell(int element)
Add a new singleton cell to the end of the partition containing only
this element.
|
void |
addToCell(int index,
int element)
Add an element to a particular cell.
|
SortedSet<Integer> |
copyBlock(int cellIndex)
Creates and returns a copy of the cell at cell index.
|
boolean |
equals(Object o) |
static Partition |
fromString(String strForm)
Parse a string like "[0,2|1,3]" to form the partition; cells are
separated by '|' characters and elements within the cell by commas.
|
SortedSet<Integer> |
getCell(int cellIndex)
Gets the cell at this index.
|
int |
getFirstInCell(int cellIndex)
Gets the first element in the specified cell.
|
int |
getIndexOfFirstNonDiscreteCell()
Gets the index of the first cell in the partition that is discrete.
|
int |
hashCode() |
boolean |
inOrder()
Check whether the cells are ordered such that for cells i and j,
first(j) > first(i) and last(j) > last(i).
|
boolean |
inSameCell(int elementI,
int elementJ)
Check that two elements are in the same cell of the partition.
|
void |
insertCell(int index,
SortedSet<Integer> cell)
Insert a cell into the partition at the specified index.
|
boolean |
isDiscrete()
Checks that all the cells are singletons - that is, they only have one
element.
|
boolean |
isDiscreteCell(int cellIndex)
Check to see if the cell at
cellIndex is discrete - that is,
it only has one element. |
int |
numberOfElements()
Calculate the size of the partition as the sum of the sizes of the cells.
|
void |
order()
Sort the cells in increasing order.
|
void |
removeCell(int index)
Removes the cell at the specified index.
|
Permutation |
setAsPermutation(int upTo)
Fill the elements of a permutation from the first element of each
cell, up to the point
upTo . |
int |
size()
Gets the size of the partition, in terms of the number of cells.
|
Partition |
splitAfter(int cellIndex,
int splitElement)
Splits this partition by taking the cell at cellIndex and making two
new cells - the first with the the rest of the elements from that cell
and the second with the singleton splitElement.
|
Partition |
splitBefore(int cellIndex,
int splitElement)
Splits this partition by taking the cell at cellIndex and making two
new cells - the first with the singleton splitElement and the second
with the rest of the elements from that cell.
|
Permutation |
toPermutation()
Converts the whole partition into a permutation.
|
String |
toString() |
static Partition |
unit(int size)
Create a unit partition - in other words, the coarsest possible partition
where all the elements are in one cell.
|
public Partition()
public Partition(Partition other)
other
- the partition to copypublic Partition(int[][] cellData)
cellData
- the partition to copypublic static Partition unit(int size)
size
- the number of elementspublic int size()
public int numberOfElements()
public boolean isDiscrete()
public Permutation toPermutation()
public boolean inOrder()
public int getFirstInCell(int cellIndex)
cellIndex
- the cell to usepublic SortedSet<Integer> getCell(int cellIndex)
cellIndex
- the index of the cell to returnpublic Partition splitBefore(int cellIndex, int splitElement)
cellIndex
- the index of the cell to split onsplitElement
- the element to put in its own cellpublic Partition splitAfter(int cellIndex, int splitElement)
cellIndex
- the index of the cell to split onsplitElement
- the element to put in its own cellpublic Permutation setAsPermutation(int upTo)
upTo
.upTo
- take values from cells up to this onepublic boolean isDiscreteCell(int cellIndex)
cellIndex
is discrete - that is,
it only has one element.cellIndex
- the index of the cell to checkpublic int getIndexOfFirstNonDiscreteCell()
public void addSingletonCell(int element)
element
- the element to add in its own cellpublic void removeCell(int index)
index
- the index of the cell to removepublic void addCell(int... elements)
elements
- the elements to add in a new cellpublic void addCell(Collection<Integer> elements)
elements
- the collection of elements to put in the cellpublic void addToCell(int index, int element)
index
- the index of the cell to add toelement
- the element to addpublic void insertCell(int index, SortedSet<Integer> cell)
index
- the index of the cell to addcell
- the cell to addpublic SortedSet<Integer> copyBlock(int cellIndex)
cellIndex
- the cell to copypublic void order()
public boolean inSameCell(int elementI, int elementJ)
elementI
- an element in the partitionelementJ
- an element in the partitionpublic static Partition fromString(String strForm)
strForm
- the partition in string formIllegalArgumentException
- thrown if the provided strFrom is
null or emptyCopyright © 2021. All rights reserved.