public class TupleMask
extends java.lang.Object
transform(ITuple)
), the signature of the pattern will consist of its
individual substitutions at the given positions, in the exact same order as they appear in indices[].Modifier and Type | Field and Description |
---|---|
int[] |
indices
indices[i] specifies the index of the substitution in the original tuple that occupies the i-th place in the
masked signature.
|
int |
sourceWidth
the size of the tuple this mask is applied to
|
Modifier | Constructor and Description |
---|---|
protected |
TupleMask(int[] indices,
int sourceWidth,
int[] indicesSorted,
java.lang.Boolean isNonrepeating)
Creates a TupleMask instance with the given indices array
|
Modifier and Type | Method and Description |
---|---|
static TupleMask |
append(TupleMask left,
TupleMask right)
Creates a TupleMask instance that selects whatever is selected by left, and appends whatever is selected by
right.
|
Tuple |
combine(Tuple unmasked,
Tuple masked,
boolean useInheritance,
boolean asComplementer)
Combines two substitutions.
|
protected static int[] |
constructLinearSequence(int size)
An array containing the first
size nonnegative integers in order |
static TupleMask |
displace(int from,
int to,
int sourceWidth)
Creates a TupleMask instance that moves an element from one index to other, shifting the others if neccessary.
|
static TupleMask |
empty(int sourceWidth)
Creates a TupleMask instance of the given size that does not emit output.
|
boolean |
equals(java.lang.Object obj) |
static TupleMask |
fromKeepIndicators(boolean[] keep)
Creates a TupleMask instance that selects positions where keep is true
|
static TupleMask |
fromNonNullIndices(ITuple tuple)
Creates a TupleMask instance that selects non-null positions of a given tuple
|
static TupleMask |
fromSelectedIndices(int sourceArity,
java.util.Collection<java.lang.Integer> selectedIndices)
Creates a TupleMask instance that selects given positions.
|
static TupleMask |
fromSelectedIndices(int sourceArity,
int[] selectedIndices)
Creates a TupleMask instance that selects given positions.
|
protected static TupleMask |
fromSelectedIndicesInternal(int[] selectedIndices,
int sourceArity,
int[] indicesSorted,
java.lang.Boolean isNonrepeating)
Creates a TupleMask instance that selects given positions.
|
protected static TupleMask |
fromSelectedMonotonicIndicesInternal(int[] selectedIndices,
int sourceArity)
Creates a TupleMask instance that selects given positions in monotonically increasing order.
|
java.util.OptionalInt |
getFirstOmittedIndex()
Returns the first index of the source that is not selected by the mask, or empty if all indices are selected.
|
java.util.List<java.lang.Integer> |
getIndicesAsList() |
int |
getSize()
Returns the size of the masked tuples described by this mask
|
int |
getSourceWidth()
Returns the size of the original tuples handled by this mask
|
java.lang.Object |
getValue(ITuple original,
int index)
Returns a selected masked value from the selected tuple.
|
int |
hashCode() |
static TupleMask |
identity(int size)
Creates a TupleMask instance of the given size that maps every single element intact
|
static int[] |
integersToIntArray(java.util.Collection<java.lang.Integer> selectedIndices) |
boolean |
isIdentity() |
boolean |
isNonrepeating() |
Tuple |
keepSelectedIndices(ITuple original)
Returns a tuple `result`, same arity as the original tuple, that satisfies
`this.transform(result).equals(this.transform(tuple))`.
|
static TupleMask |
linear(int size,
int sourceWidth)
Creates a TupleMask instance of the given size that maps the first 'size' elements intact
|
static TupleMask |
omit(int omission,
int sourceWidth)
Creates a TupleMask instance that maps the tuple intact save for a single element at the specified index which is
omitted
|
Tuple |
revertFrom(ITuple masked)
Returns a tuple `result` that satisfies `this.transform(result).equals(masked)`.
|
static TupleMask |
selectSingle(int selected,
int sourceWidth)
Creates a TupleMask instance that selects a single element of the tuple.
|
void |
set(IModifiableTuple tuple,
int index,
java.lang.Object value)
Sets the selected value in the original tuple based on the mask definition
|
java.lang.String |
toString() |
Tuple |
transform(ITuple original)
Generates an immutable, masked view of the original tuple.
|
<T> java.util.List<T> |
transform(java.util.List<T> original)
Generates an immutable, masked view of the original tuple.
|
TupleMask |
transform(TupleMask mask)
Transforms a given mask directly, instead of transforming tuples that were transformed by the other mask.
|
<T> java.util.Set<T> |
transformUnique(java.util.List<T> original)
Transforms the given list by applying the mask and putting all results into a set; keeping only a single element
in case of the mapping result in duplicate values.
|
public final int[] indices
public int sourceWidth
protected TupleMask(int[] indices, int sourceWidth, int[] indicesSorted, java.lang.Boolean isNonrepeating)
indicesSorted and isNonrepeating may be OPTIONALLY given if known.
protected static TupleMask fromSelectedIndicesInternal(int[] selectedIndices, int sourceArity, int[] indicesSorted, java.lang.Boolean isNonrepeating)
indicesSorted and isNonrepeating may be OPTIONALLY given if known.
protected static TupleMask fromSelectedMonotonicIndicesInternal(int[] selectedIndices, int sourceArity)
public static TupleMask linear(int size, int sourceWidth)
protected static int[] constructLinearSequence(int size)
size
nonnegative integers in orderpublic static TupleMask identity(int size)
public static TupleMask empty(int sourceWidth)
public static TupleMask omit(int omission, int sourceWidth)
public static TupleMask fromKeepIndicators(boolean[] keep)
public static TupleMask fromSelectedIndices(int sourceArity, java.util.Collection<java.lang.Integer> selectedIndices)
public static TupleMask fromSelectedIndices(int sourceArity, int[] selectedIndices)
public static TupleMask fromNonNullIndices(ITuple tuple)
public static int[] integersToIntArray(java.util.Collection<java.lang.Integer> selectedIndices)
public static TupleMask displace(int from, int to, int sourceWidth)
public static TupleMask selectSingle(int selected, int sourceWidth)
public static TupleMask append(TupleMask left, TupleMask right)
public java.util.OptionalInt getFirstOmittedIndex()
PRE: mask indices are all different
public java.lang.Object getValue(ITuple original, int index)
public void set(IModifiableTuple tuple, int index, java.lang.Object value)
public Tuple transform(ITuple original)
The new tuple will have arity getSize()
,
and will consist of the elements of the original tuple, at positions indicated by this mask.
public boolean isNonrepeating()
public Tuple revertFrom(ITuple masked)
public Tuple keepSelectedIndices(ITuple original)
In other words, a copy of the original tuple is returned, with null substituted at each position that is not selected by this mask.
public <T> java.util.List<T> transform(java.util.List<T> original)
The list will have arity getSize()
,
and will consist of the elements of the original tuple, at positions indicated by this mask.
public TupleMask transform(TupleMask mask)
public Tuple combine(Tuple unmasked, Tuple masked, boolean useInheritance, boolean asComplementer)
unmasked
- primary pattern substitution that is left intact.masked
- secondary pattern substitution that is transformed to the end of the result.useInheritance
- whether to use inheritance or copy umasked into result instead.asComplementer
- whether this mask maps from the masked Tuple to the tail of the result or to the unmasked one.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int getSize()
public int getSourceWidth()
public boolean isIdentity()
public <T> java.util.Set<T> transformUnique(java.util.List<T> original)
public java.util.List<java.lang.Integer> getIndicesAsList()