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 AbstractAlignmentModelDecorator<T,U> extends AbstractAlignmentModel<T> implements AlignmentModelView<T,U>
AlignmentModelView
which delegates sequence specific methods
(which are independent of the token type) to the underlying model. Inherited classes may
provide modified views of the underlying sequences possibly using a different token set.Constructor and Description |
---|
AbstractAlignmentModelDecorator(TokenSet<T> tokenSet,
AlignmentModel<U> underlyingModel)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addSequence(java.lang.String sequenceName)
Adds a new empty sequence to the underlying data source and generates an ID for it.
|
java.lang.String |
addSequence(java.lang.String sequenceName,
java.lang.String sequenceID)
Adds a new empty sequence to the underlying data source assigning the specified ID to it.
|
boolean |
containsSequence(java.lang.String sequenceID)
Checks if a sequence associated with the specified unique identifier is contained in this model.
|
protected java.lang.String |
convertDecoratedSequenceID(java.lang.String decoratedSequenceID)
Method used to convert a sequence ID used by the decorator to the according sequence ID used by the underlying model.
|
protected int |
convertDecoratedTokenIndex(java.lang.String sequenceID,
int decoratedIndex) |
protected SequenceChangeEvent<T> |
convertSequenceChangeEvent(SequenceChangeEvent<U> event)
Converts a
SequenceChangeEvent event from the decorated instance to an event object compatible
with this instance. |
protected SequenceRenamedEvent<T> |
convertSequenceRenamedEvent(SequenceRenamedEvent<U> event)
Converts a
SequenceRenamedEvent event from the decorated instance to an event object compatible
with this instance. |
protected abstract 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 java.lang.String |
convertUnderlyingSequenceID(java.lang.String underlyingSequenceID)
Method used to convert a sequence ID from the underlying model to the according sequence ID used by the decorator.
|
protected int |
convertUnderlyingTokenIndex(java.lang.String sequenceID,
int underlyingIndex) |
int |
getSequenceCount()
Returns the number of sequences in the underlying data source.
|
TokenSet<T> |
getTokenSet()
Returns the token set which is supported by the implementation.
|
AlignmentModel<U> |
getUnderlyingModel()
Returns the underlying sequence data provider that provides the data accessed with this object.
|
boolean |
isSequencesReadOnly()
Checks of whole sequences can be changed in the underlying data source
|
boolean |
removeSequence(java.lang.String sequenceID)
Removes the specified sequence from the underlying data source.
|
java.util.Iterator<java.lang.String> |
sequenceIDIterator()
Returns an iterator over unique IDs of all sequences contained in the underlying data source
in the order they are stored in this model.
|
java.util.Set<java.lang.String> |
sequenceIDsByName(java.lang.String sequenceName)
Returns the set of unique sequence IDs associated with the specified name.
|
java.lang.String |
sequenceNameByID(java.lang.String sequenceID)
Returns the sequence name (that would be visible to the application user) associated with the
specified unique ID.
|
void |
setTokenSet(TokenSet<T> tokenSet)
Replaces the current token set with the specified one.
|
protected void |
setUnderlyingModel(AlignmentModel<U> underlyingModel)
Replaces the decorated (underlying) model.
|
fireAfterSequenceChange, fireAfterSequenceRenamed, fireAfterTokenChange, getChangeListeners, getID, getLabel, setID, setLabel
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appendToken, appendTokens, getChangeListeners, getID, getLabel, getMaxSequenceLength, getSequenceLength, getTokenAt, getWriteType, insertTokenAt, insertTokensAt, isTokensReadOnly, removeTokenAt, removeTokensAt, renameSequence, setID, setLabel, setTokenAt, setTokensAt
public AbstractAlignmentModelDecorator(TokenSet<T> tokenSet, AlignmentModel<U> underlyingModel)
underlyingModel
- the underlying model to be viewedprotected java.lang.String convertUnderlyingSequenceID(java.lang.String underlyingSequenceID)
Inherited classes that use different IDs than their underlying model must overwrite this method. Otherwise
change events from the underlying model will not be converted correctly. The same applies if inherited classes
hide any of the underlying sequences. In this case, they must return null
for calls with the ID of a hidden
sequence.
underlyingSequenceID
- the sequence ID used in the underlying modelnull
if the specified underlying sequence is hidden by
this decoratorprotected java.lang.String convertDecoratedSequenceID(java.lang.String decoratedSequenceID)
Inherited classes that use different IDs than their underlying model must overwrite this method because numerous decorator methods rely on this conversion. The same applies if inherited classes add sequences to those contained in the underlying model. In this case, they must return -1 for calls with the ID of an additional sequence.
decoratedSequenceID
- the sequence ID used in the underlying modelnull
if the specified decorated sequence is not
present in the underlying modelprotected int convertUnderlyingTokenIndex(java.lang.String sequenceID, int underlyingIndex)
protected int convertDecoratedTokenIndex(java.lang.String sequenceID, int decoratedIndex)
protected abstract java.lang.Iterable<TokenChangeEvent<T>> convertTokenChangeEvent(TokenChangeEvent<U> event)
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.)
event
- the event fired by the underlying modelprotected SequenceChangeEvent<T> convertSequenceChangeEvent(SequenceChangeEvent<U> event)
SequenceChangeEvent
event from the decorated instance to an event object compatible
with this instance.
This default implementation returns a new event object with this instance as its owner and a sequence ID
converted using #convertUnderlyingSequenceID(int)
. If the ID conversion returns -1, null
is returned
by this method.
Inherited classes may overwrite this method to implement a different behavior, but in most cases it should
be sufficient to overwrite #convertUnderlyingSequenceID(int)
to change the behavior of this method.
event
- the event from the underlying (decorated) modelnull
if the specified underlying sequence is hidden by this decoratorjava.lang.IllegalArgumentException
- if SequenceChangeEvent.getType()
return anything else than
ListChangeType.INSERTION
or ListChangeType.DELETION
. (Events fired by models
of LibrAlign never have any other type.)protected SequenceRenamedEvent<T> convertSequenceRenamedEvent(SequenceRenamedEvent<U> event)
SequenceRenamedEvent
event from the decorated instance to an event object compatible
with this instance.
This default implementation returns a new event object with this instance as its owner, the same previous and
current name and a sequence ID converted using #convertUnderlyingSequenceID(int)
. If the ID conversion returns -1, null
is returned
by this method.
Inherited classes may overwrite this method to implement a different behavior, but in most cases it should
be sufficient to overwrite #convertUnderlyingSequenceID(int)
to change the behavior of this method.
event
- the event from the underlying (decorated) modelnull
if the specified underlying sequence is hidden by this decoratorpublic AlignmentModel<U> getUnderlyingModel()
BasicAlignmentModelView
getUnderlyingModel
in interface BasicAlignmentModelView<U>
public TokenSet<T> getTokenSet()
AlignmentModel
getTokenSet
in interface AlignmentModel<T>
public void setTokenSet(TokenSet<T> tokenSet)
AlignmentModel
setTokenSet
in interface AlignmentModel<T>
tokenSet
- the new token set to be usedprotected void setUnderlyingModel(AlignmentModel<U> underlyingModel)
underlyingModel
- the new underlying modelpublic boolean isSequencesReadOnly()
AlignmentModel
isSequencesReadOnly
in interface AlignmentModel<T>
true
if sequences can be written, renamed or removed, false
otherwisepublic boolean containsSequence(java.lang.String sequenceID)
AlignmentModel
containsSequence
in interface AlignmentModel<T>
sequenceID
- the ID of the sequence to checked ontrue
if an according sequence was found, false
otherwisepublic java.util.Set<java.lang.String> sequenceIDsByName(java.lang.String sequenceName)
AlignmentModel
sequenceIDsByName
in interface AlignmentModel<T>
sequenceName
- the name of the sequence that would be visible to the application userpublic java.lang.String sequenceNameByID(java.lang.String sequenceID)
AlignmentModel
sequenceNameByID
in interface AlignmentModel<T>
sequenceID
- the unique unmodifiable ID the sequence is identified bynull
if no sequence with this ID is contained in this modelpublic java.lang.String addSequence(java.lang.String sequenceName) throws AlignmentSourceNotWritableException
AlignmentModel
addSequence
in interface AlignmentModel<T>
sequenceName
- the name of the new sequenceAlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencespublic java.lang.String addSequence(java.lang.String sequenceName, java.lang.String sequenceID) throws AlignmentSourceNotWritableException
AlignmentModel
addSequence
in interface AlignmentModel<T>
sequenceName
- the name of the new sequencesequenceID
- the ID the new sequence shall havesequenceID
)AlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencespublic boolean removeSequence(java.lang.String sequenceID) throws AlignmentSourceNotWritableException
AlignmentModel
removeSequence
in interface AlignmentModel<T>
sequenceID
- the unique ID of the sequence to be removedtrue
if an sequence with the specified ID was removed, false
if no sequence with the specified ID was contained in this modelAlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencespublic java.util.Iterator<java.lang.String> sequenceIDIterator()
AlignmentModel
sequenceIDIterator
in interface AlignmentModel<T>
public int getSequenceCount()
AlignmentModel
getSequenceCount
in interface AlignmentModel<T>