T
- the type of sequence elements (tokens) the implementing decorator works withU
- the type of sequence elements (tokens) the underlying model works withpublic abstract class AbstractTokenReplacementAlignmentModelDecorator<T,U> extends AbstractAlignmentModelDecorator<T,U>
AlignmentModelView
that simply replace a set
of tokens by other tokens of the same type. It delegates all methods to the underlying model
except #getTokenAt(int, int)
which calls the abstract method #convertToken(Object)
to perform the actual translation.
It is still possible to write tokens that are translated to the underlying data source. Note that
in that case #getTokenAt(int, int)
would return a different token than the one passed to a
previously call of #setTokenAt(int, int, Object)
or #insertTokenAt(int, int, Object)
or similar methods called with the same index value.
Note that classes inherited from this class are not meant to apply length changes. Most methods will not work correctly or throw exceptions, if index conversion is used.
Inherited classes that add or hide sequences from or to the underlying model, will need to overwrite
getMaxSequenceLength()
. Classes that hide sequences will have to overwrite no additional methods,
classes adding sequences, will need to overwrite all methods with a sequence ID as parameter to handle
additional sequence not present in the underlying model.
Constructor and Description |
---|
AbstractTokenReplacementAlignmentModelDecorator(TokenSet<T> tokenSet,
AlignmentModel<U> underlyingModel)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
void |
appendToken(java.lang.String sequenceID,
T token)
Appends a token at the end of the sequence.
|
void |
appendTokens(java.lang.String sequenceID,
java.util.Collection<? extends T> tokens)
Appends a sequence of tokens starting at the end of the current sequence.
|
protected abstract U |
convertDecoratedToken(java.lang.String viewedSequenceID,
int viewedIndex,
T decoratedToken)
Inherited classes should perform the token translation from a viewed to an underlying token
by implementing this method.
|
protected java.util.Collection<? extends U> |
convertDecoratedTokens(java.lang.String viewedSequenceID,
int viewedIndex,
java.util.Collection<? extends T> viewedTokens) |
protected java.lang.Iterable<TokenChangeEvent<T>> |
convertTokenChangeEvent(TokenChangeEvent<U> event)
Converts a token change event from the underlying (decorated) model to a collection of according change
events to be used with this decorator.
|
protected abstract T |
convertUnderlyingToken(java.lang.String underlyingSequenceID,
int underlyingIndex,
U underlyingToken)
Inherited classes should perform the token translation from an underlying to a viewed token
by implementing this method.
|
protected java.util.Collection<? extends T> |
convertUnderlyingTokens(java.lang.String underlyingSequenceID,
int underlyingIndex,
java.util.Collection<? extends U> underlyingTokens) |
java.util.Set<AlignmentModelChangeListener> |
getChangeListeners()
Returns all change listeners currently attached to this object.
|
int |
getMaxSequenceLength()
This default implementation delegates to the underlying model.
|
int |
getSequenceLength(java.lang.String sequenceID)
Returns the length of the specified sequence.
|
T |
getTokenAt(java.lang.String sequenceID,
int index)
Returns the token at the specified position.
|
AlignmentModelWriteType |
getWriteType()
Returns a value that specifies if whole sequences or single tokens can be edited in the underlying
data source.
|
void |
insertTokenAt(java.lang.String sequenceID,
int index,
T token)
Inserts a token at the specified position.
|
void |
insertTokensAt(java.lang.String sequenceID,
int beginIndex,
java.util.Collection<? extends T> tokens)
Inserts a sequence of tokens starting at the specified position.
|
boolean |
isTokensReadOnly()
Checks of tokens can be changed in the underlying data source
|
void |
removeTokenAt(java.lang.String sequenceID,
int index)
Removes the token at the specified position from the underlying data source.
|
void |
removeTokensAt(java.lang.String sequenceID,
int beginIndex,
int endIndex)
Removes the token inside the specified interval from the underlying data source.
|
java.lang.String |
renameSequence(java.lang.String sequenceID,
java.lang.String newSequenceName)
Renames a sequence in the underlying data source.
|
void |
setTokenAt(java.lang.String sequenceID,
int index,
T token)
Replaces the token at the specified position by the passed token.
|
void |
setTokensAt(java.lang.String sequenceID,
int beginIndex,
java.util.Collection<? extends T> tokens)
Replaces a sequence of tokens starting at the specified position.
|
addSequence, addSequence, containsSequence, convertDecoratedSequenceID, convertDecoratedTokenIndex, convertSequenceChangeEvent, convertSequenceRenamedEvent, convertUnderlyingSequenceID, convertUnderlyingTokenIndex, getSequenceCount, getTokenSet, getUnderlyingModel, isSequencesReadOnly, removeSequence, sequenceIDIterator, sequenceIDsByName, sequenceNameByID, setTokenSet, setUnderlyingModel
fireAfterSequenceChange, fireAfterSequenceRenamed, fireAfterTokenChange, getID, getLabel, setID, setLabel
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getID, getLabel, setID, setLabel
public AbstractTokenReplacementAlignmentModelDecorator(TokenSet<T> tokenSet, AlignmentModel<U> underlyingModel)
tokenSet
- the token set to be used by the decoratorunderlyingModel
- the underlying model to be decoratedprotected abstract T convertUnderlyingToken(java.lang.String underlyingSequenceID, int underlyingIndex, U underlyingToken)
underlyingSequenceID
- the ID of the sequence in the underlying model containing the token to be convertedunderlyingIndex
- the column index of the token to be converted in the underlying modelunderlyingToken
- the token stored in (or shown by) the underlying providerprotected abstract U convertDecoratedToken(java.lang.String viewedSequenceID, int viewedIndex, T decoratedToken)
viewedSequenceID
- the ID of the sequence in this decorator containing the token to be convertedviewedIndex
- the column index of the token to be converted in this view (Note that this index may be behind
current end of the sequence, of this method is used to elongate a sequence.)decoratedToken
- the token shown in the view instanceprotected java.lang.Iterable<TokenChangeEvent<T>> convertTokenChangeEvent(TokenChangeEvent<U> event)
AbstractAlignmentModelDecorator
Depending on which columns are added or hidden by the decorator implementation, an empty collection or
a collection containing more than one event may be returned. (null
is not a valid return value.)
convertTokenChangeEvent
in class AbstractAlignmentModelDecorator<T,U>
event
- the event fired by the underlying modelprotected java.util.Collection<? extends T> convertUnderlyingTokens(java.lang.String underlyingSequenceID, int underlyingIndex, java.util.Collection<? extends U> underlyingTokens)
protected java.util.Collection<? extends U> convertDecoratedTokens(java.lang.String viewedSequenceID, int viewedIndex, java.util.Collection<? extends T> viewedTokens)
public T getTokenAt(java.lang.String sequenceID, int index)
AlignmentModel
sequenceID
- the identifier the sequence where the token is containedindex
- the index of the element contained in the specified sequence (The first element has the index 0.)public void setTokenAt(java.lang.String sequenceID, int index, T token) throws AlignmentSourceNotWritableException
AlignmentModel
sequenceID
- the identifier the sequence where the token is containedindex
- the index of the element to be replaced (The first element has the index 0.)token
- the new token for the specified positionAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokenspublic void setTokensAt(java.lang.String sequenceID, int beginIndex, java.util.Collection<? extends T> tokens) throws AlignmentSourceNotWritableException
AlignmentModel
sequenceID
- the identifier the sequence where the token is containedbeginIndex
- the index of the first element to be replaced
(The first element in the sequence has the index 0.)tokens
- the new tokens for the specified positionAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensAlignmentModelUtils.charSequenceToTokenList(CharSequence, TokenSet)
public void appendToken(java.lang.String sequenceID, T token) throws AlignmentSourceNotWritableException
AlignmentModel
sequenceID
- the identifier the sequence in the alignmenttoken
- the token to be insertedAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokenspublic void appendTokens(java.lang.String sequenceID, java.util.Collection<? extends T> tokens) throws AlignmentSourceNotWritableException
AlignmentModel
sequenceID
- the identifier the sequence where the token is containedtokens
- the new tokens for the specified positionAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensAlignmentModelUtils.charSequenceToTokenList(CharSequence, TokenSet)
public void insertTokenAt(java.lang.String sequenceID, int index, T token) throws AlignmentSourceNotWritableException
AlignmentModel
sequenceID
- the identifier the sequence in the alignmentindex
- the new index the inserted element will have
(0 <= elementIndex < sequenceLength
)token
- the token to be insertedAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokenspublic void insertTokensAt(java.lang.String sequenceID, int beginIndex, java.util.Collection<? extends T> tokens) throws AlignmentSourceNotWritableException
AlignmentModel
tokens
.sequenceID
- the identifier the sequence where the token is containedbeginIndex
- the index of the first element to be replaced
(The first element in the sequence has the index 0.)tokens
- the new tokens for the specified positionAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokensAlignmentModelUtils.charSequenceToTokenList(CharSequence, TokenSet)
public void removeTokenAt(java.lang.String sequenceID, int index) throws AlignmentSourceNotWritableException
AlignmentModel
sequenceID
- the identifier the sequence in the alignmentindex
- the index of the element to be removed (The first element has the index 0.)AlignmentSourceNotWritableException
- if the underlying data source is not writable for tokenspublic void removeTokensAt(java.lang.String sequenceID, int beginIndex, int endIndex) throws AlignmentSourceNotWritableException
AlignmentModel
beginIndex
and extends to the
token at index endIndex - 1). Thus the length of the subsequence is {@code endIndex - beginIndex}.sequenceID
- the identifier the sequence in the alignmentbeginIndex
- the beginning index, inclusiveendIndex
- the ending index, exclusiveAlignmentSourceNotWritableException
- if the underlying data source is not writable for tokenspublic int getSequenceLength(java.lang.String sequenceID)
AlignmentModel
sequenceID
- the identifier the sequence in the alignment-1
if no sequence with the specified name existspublic int getMaxSequenceLength()
Inherited classes that change the sequence set (add or hide sequences) must overwrite this method in order to consider only relevant sequences when calculating the maximum.
0
if there are not sequences contained
in the underlying data sourcepublic AlignmentModelWriteType getWriteType()
AlignmentModel
public boolean isTokensReadOnly()
AlignmentModel
true
if token can be written or removed, false
otherwisepublic java.lang.String renameSequence(java.lang.String sequenceID, java.lang.String newSequenceName) throws AlignmentSourceNotWritableException, SequenceNotFoundException
AlignmentModel
sequenceID
- the ID of the sequence to be renamednewSequenceName
- the new name the sequence shall haveAlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencesSequenceNotFoundException
- if a sequence with the specified ID is not present the underlying
data sourcepublic java.util.Set<AlignmentModelChangeListener> getChangeListeners()
AlignmentModel
This method returns the same object in every call. Therefore changes made to different references always affect all references.
getChangeListeners
in interface AlignmentModel<T>
getChangeListeners
in class AbstractAlignmentModel<T>