T
- the type of token to be stored in this setpublic abstract class AbstractTokenSet<T> extends java.util.HashSet<T> implements TokenSet<T>
TokenSet
that provides a TreeMap
used to map key characters
to tokens and inherits from HashSet
so also tokens that do not implement Comparable
are
supported.
Since the implemented functionality of this class assumes discrete token values, #isContinuous()
always returns false
.
Constructor and Description |
---|
AbstractTokenSet(CharacterStateSetType type)
Creates a new empty instance of this class.
|
AbstractTokenSet(CharacterStateSetType type,
AbstractTokenSet<T> source)
Copy constructor that copies all elements the contents of the key map from source to the new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addSpaceKeyForGaps() |
abstract AbstractTokenSet<T> |
clone()
Inherited classes have to overwrite this method and create a deep copy of
getKeyMap() . |
T |
getGapToken()
Returns the default object that represents a gap in this token set.
|
protected java.util.Map<javax.swing.KeyStroke,T> |
getKeyMap()
Returns the mapping from key characters to tokens.
|
CharacterSymbolMeaning |
getMeaning(T token)
Returns the meaning of the specified symbol.
|
T |
getMissingInformationToken()
Returns the default object that represents an unknown position in this token set.
|
CharacterSymbolType |
getSymbolType(T token)
This default implementation returns
CharacterSymbolType.UNCERTAIN for all missing information tokens. |
CharacterStateSetType |
getType()
Determines the type of tokens that are defined by this instance.
|
boolean |
isGapToken(T token)
Default implementation that tests of the string representation of the specified token is equal to
"".
|
boolean |
isMissingInformationToken(T token)
Tests if the specified token represents an unknown position (usually '?').
|
boolean |
isSpaceForGap()
Determines whether
TokenSet.tokenByKeyStroke(KeyStroke) shall return the gap token, if the space bar is
pressed, even if that key stroke is not associated with that token. |
void |
setSpaceForGap(boolean spaceForGap)
Allows to specify whether
TokenSet.tokenByKeyStroke(KeyStroke) shall return the gap token, if the space
bar is pressed, even if that key stroke is not associated with that token. |
T |
tokenByKeyStroke(javax.swing.KeyStroke key)
Returns the token from this set that is associated with the specified key stroke.
|
add, clear, contains, isEmpty, iterator, remove, size, spliterator
addAll, containsAll, retainAll, toArray, toArray, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
descriptionByToken, maxRepresentationLength, representationByToken, representationLengthEqual, tokenByRepresentation
public AbstractTokenSet(CharacterStateSetType type)
public AbstractTokenSet(CharacterStateSetType type, AbstractTokenSet<T> source)
type
- the token type of the new instance (Only a discrete type would make sense for this class.)source
- the source instance to be clonedpublic CharacterStateSetType getType()
TokenSet
public T tokenByKeyStroke(javax.swing.KeyStroke key)
TokenSet
AlignmentArea
.
Note that the key character is only used by AlignmentArea
if it does not collide with a default
keyboard action. (Usually the key character can be any lower or upper case letter or digit.)
tokenByKeyStroke
in interface TokenSet<T>
key
- the key stroke (key code and shift mask) the user can press to insert the returned token
into an AlignmentArea
null
if none is definedprotected java.util.Map<javax.swing.KeyStroke,T> getKeyMap()
TreeMap
in the current implementation (Note that this might change in
future versions.)public boolean isGapToken(T token)
isGapToken
in interface TokenSet<T>
token
- the token to be testedtrue
if the specified token is recognized as a gap, false
otherwise.TokenSet.isGapToken(java.lang.Object)
public T getGapToken()
TokenSet
getGapToken
in interface TokenSet<T>
public boolean isSpaceForGap()
TokenSet
TokenSet.tokenByKeyStroke(KeyStroke)
shall return the gap token, if the space bar is
pressed, even if that key stroke is not associated with that token.isSpaceForGap
in interface TokenSet<T>
true
if the gap token shall always be returned, false
otherwise.public void setSpaceForGap(boolean spaceForGap)
TokenSet
TokenSet.tokenByKeyStroke(KeyStroke)
shall return the gap token, if the space
bar is pressed, even if that key stroke is not associated with that token.setSpaceForGap
in interface TokenSet<T>
spaceForGap
- Specify true
here, if the gap token shall always be returned, false
otherwise.public boolean isMissingInformationToken(T token)
TokenSet
Note that it's legal to have multiple tokens to be considered as unknown symbols, but one of them must be defined as the default. When alignments are written to files, some formats may accept only one
isMissingInformationToken
in interface TokenSet<T>
token
- the token to be testedtrue
if the specified token is recognized as an unknown position, false
otherwise.public T getMissingInformationToken()
TokenSet
getMissingInformationToken
in interface TokenSet<T>
public CharacterSymbolType getSymbolType(T token)
CharacterSymbolType.UNCERTAIN
for all missing information tokens.
If getType()
specifies a nucleotide or amino acid token set, CharacterSymbolType.UNCERTAIN
is returned
for all tokens which have a IUPAC ambiguity code string representation (as returned by
TokenSet.representationByToken(Object)
). In all other cases CharacterSymbolType.ATOMIC_STATE
is returned.
Inherited classes should overwrite this method, if other uncertain or any polymorphic tokens are present.
getSymbolType
in interface TokenSet<T>
token
- the symbol to be testedpublic CharacterSymbolMeaning getMeaning(T token)
TokenSet
getMeaning
in interface TokenSet<T>
token
- the token to determine the meaning frompublic abstract AbstractTokenSet<T> clone()
getKeyMap()
.protected void addSpaceKeyForGaps()