Class TupleMask
java.lang.Object
tools.refinery.interpreter.matchers.tuple.TupleMask
- Direct Known Subclasses:
TupleMask0
,TupleMaskIdentity
Specifies select indices of a tuple. If viewed through this mask (see
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[].-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal int[]
indices[i] specifies the index of the substitution in the original tuple that occupies the i-th place in the masked signature.int
the size of the tuple this mask is applied to -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TupleMask
Creates a TupleMask instance that selects whatever is selected by left, and appends whatever is selected by right.Combines two substitutions.protected static int[]
constructLinearSequence
(int size) An array containing the firstinvalid reference
size
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
static TupleMask
fromKeepIndicators
(boolean[] keep) Creates a TupleMask instance that selects positions where keep is truestatic TupleMask
fromNonNullIndices
(ITuple tuple) Creates a TupleMask instance that selects non-null positions of a given tuplestatic TupleMask
fromSelectedIndices
(int sourceArity, int[] selectedIndices) Creates a TupleMask instance that selects given positions.static TupleMask
fromSelectedIndices
(int sourceArity, Collection<Integer> selectedIndices) Creates a TupleMask instance that selects given positions.protected static TupleMask
fromSelectedIndicesInternal
(int[] selectedIndices, int sourceArity, int[] indicesSorted, 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.Returns the first index of the source that is not selected by the mask, or empty if all indices are selected.int
getSize()
Returns the size of the masked tuples described by this maskint
Returns the size of the original tuples handled by this maskReturns 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 intactstatic int[]
integersToIntArray
(Collection<Integer> selectedIndices) boolean
boolean
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 intactstatic 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 omittedrevertFrom
(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, Object value) Sets the selected value in the original tuple based on the mask definitiontoString()
<T> List
<T> Generates an immutable, masked view of the original tuple.Generates an immutable, masked view of the original tuple.Transforms a given mask directly, instead of transforming tuples that were transformed by the other mask.<T> Set
<T> transformUnique
(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.
-
Field Details
-
indices
public final int[] indicesindices[i] specifies the index of the substitution in the original tuple that occupies the i-th place in the masked signature. -
sourceWidth
public int sourceWidththe size of the tuple this mask is applied to
-
-
Constructor Details
-
TupleMask
Creates a TupleMask instance with the given indices arrayindicesSorted and isNonrepeating may be OPTIONALLY given if known.
- Since:
- 2.0
-
-
Method Details
-
fromSelectedIndicesInternal
protected static TupleMask fromSelectedIndicesInternal(int[] selectedIndices, int sourceArity, int[] indicesSorted, Boolean isNonrepeating) Creates a TupleMask instance that selects given positions. The mask takes ownership of the array selectedIndices, the client must not modify it afterwards.indicesSorted and isNonrepeating may be OPTIONALLY given if known.
- Since:
- 2.0
-
fromSelectedMonotonicIndicesInternal
protected static TupleMask fromSelectedMonotonicIndicesInternal(int[] selectedIndices, int sourceArity) Creates a TupleMask instance that selects given positions in monotonically increasing order. The mask takes ownership of the array selectedIndices, the client must not modify it afterwards.- Since:
- 2.0
-
linear
Creates a TupleMask instance of the given size that maps the first 'size' elements intact -
constructLinearSequence
protected static int[] constructLinearSequence(int size) An array containing the firstinvalid reference
size
- Since:
- 2.0
-
identity
Creates a TupleMask instance of the given size that maps every single element intact -
empty
Creates a TupleMask instance of the given size that does not emit output. -
omit
Creates a TupleMask instance that maps the tuple intact save for a single element at the specified index which is omitted -
fromKeepIndicators
Creates a TupleMask instance that selects positions where keep is true- Since:
- 1.7
-
fromSelectedIndices
Creates a TupleMask instance that selects given positions.- Since:
- 1.7
-
fromSelectedIndices
Creates a TupleMask instance that selects given positions.- Since:
- 1.7
-
fromNonNullIndices
Creates a TupleMask instance that selects non-null positions of a given tuple- Since:
- 1.7
-
integersToIntArray
- Since:
- 1.7
-
displace
Creates a TupleMask instance that moves an element from one index to other, shifting the others if neccessary. -
selectSingle
Creates a TupleMask instance that selects a single element of the tuple. -
append
Creates a TupleMask instance that selects whatever is selected by left, and appends whatever is selected by right. PRE: left and right have the same sourcewidth -
getFirstOmittedIndex
Returns the first index of the source that is not selected by the mask, or empty if all indices are selected.PRE: mask indices are all different
- Since:
- 2.0
-
getValue
Returns a selected masked value from the selected tuple.- Since:
- 1.7
-
set
Sets the selected value in the original tuple based on the mask definition- Since:
- 1.7
-
transform
Generates an immutable, masked view of the original tuple.The new tuple will have arity
getSize()
, and will consist of the elements of the original tuple, at positions indicated by this mask.- Since:
- 1.7
-
isNonrepeating
public boolean isNonrepeating()- Returns:
- true iff no two selected indices are the same
- Since:
- 2.0
-
revertFrom
Returns a tuple `result` that satisfies `this.transform(result).equals(masked)`. Positions of the result tuple that are not determined this way will be filled with null.- Since:
- 1.7
-
keepSelectedIndices
Returns a tuple `result`, same arity as the original tuple, that satisfies `this.transform(result).equals(this.transform(tuple))`. Positions of the result tuple that are not determined this way will be filled with null.In other words, a copy of the original tuple is returned, with null substituted at each position that is not selected by this mask.
- Since:
- 2.1
-
transform
Generates an immutable, masked view of the original tuple.The list will have arity
getSize()
, and will consist of the elements of the original tuple, at positions indicated by this mask. -
transform
Transforms a given mask directly, instead of transforming tuples that were transformed by the other mask.- Returns:
- a mask that cascades the effects this mask after the mask provided as parameter.
-
combine
Combines two substitutions. The new pattern will contain all substitutions of masked and unmasked, assuming that the elements of masked indicated by this mask are already matched against unmasked. POST: the result will start with an exact copy of unmasked- Parameters:
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.- Returns:
- new pattern that is a combination of unmasked and masked.
-
hashCode
public int hashCode() -
equals
-
toString
-
getSize
public int getSize()Returns the size of the masked tuples described by this mask- Since:
- 1.7
-
getSourceWidth
public int getSourceWidth()Returns the size of the original tuples handled by this mask- Since:
- 1.7
-
isIdentity
public boolean isIdentity()- Returns:
- true iff this mask is a no-op
- Since:
- 2.0
-
transformUnique
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.- Since:
- 1.7
-
getIndicesAsList
- Returns:
- the list of selected indices
- Since:
- 2.1
-