T
- the type of sequence elements (tokens) the implementing provider object works withpublic abstract class AbstractUndecoratedAlignmentModel<T> extends AbstractAlignmentModel<T>
This mainly includes sequence ID management, token set storage and efficient max length calculation.
Constructor and Description |
---|
AbstractUndecoratedAlignmentModel(TokenSet<T> tokenSet)
Creates a new instance of this class with its own instance of
SequenceIDManager . |
AbstractUndecoratedAlignmentModel(TokenSet<T> tokenSet,
SequenceIDManager idManager)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
String |
addSequence(String sequenceName)
Adds a new empty sequence to the underlying data source and generates an ID for it.
|
void |
appendToken(String sequenceID,
T token)
Appends a token at the end of the sequence.
|
void |
appendTokens(String sequenceID,
Collection<? extends T> tokens)
Appends a sequence of tokens starting at the end of the current sequence.
|
protected abstract void |
doAddSequence(String sequenceID,
String sequenceName)
|
protected abstract void |
doRemoveSequence(String sequenceID)
This method is called by
#removeSequence(int) if #isReadOnly() returns false . |
protected void |
doRenameSequence(String sequenceID,
String newSequenceName)
This method is called by
#renameSequence(int, String) if #isReadOnly() returns
false and the specified sequence is contained in this model. |
protected void |
fireAfterSequenceChange(SequenceChangeEvent<T> e)
Informs all listeners that a sequence has been inserted, removed or replaced.
|
protected void |
fireAfterTokenChange(TokenChangeEvent<T> e)
Informs all listeners that a sequence has been inserted, removed or replaced.
|
int |
getApproxMaxSequenceLength()
Returns the maximum sequence length that is currently known.
|
protected SequenceIDManager |
getIDManager() |
int |
getMaxSequenceLength()
Iterates over all sequence IDs and determines the maximum sequence length by calling
#getSequenceLength(int) for each ID. |
TokenSet<T> |
getTokenSet()
Returns the token set which is supported by the implementation.
|
boolean |
isSequencesReadOnly()
Checks of whole sequences can be changed in the underlying data source
|
boolean |
isTokensReadOnly()
Checks of tokens can be changed in the underlying data source
|
boolean |
removeSequence(String sequenceID)
Removes the specified sequence from the underlying data source.
|
String |
renameSequence(String sequenceID,
String newSequenceName)
Renames a sequence in the underlying data source.
|
String |
sequenceIDByName(String sequenceName)
Returns the unique sequence ID associated with the specified name.
|
String |
sequenceNameByID(String sequenceID)
Returns the sequence name (that would be visible to the application user) associated with the
specified unique ID.
|
void |
setMaxSequeceLengthRecalculte() |
void |
setTokenSet(TokenSet<T> set)
Replaces the current token set with the specified one.
|
fireAfterSequenceRenamed, getChangeListeners, getLabel, setLabel
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
containsSequence, getSequenceCount, getSequenceLength, getTokenAt, getWriteType, insertTokenAt, insertTokensAt, removeTokenAt, removeTokensAt, sequenceIDIterator, setTokenAt, setTokensAt
public AbstractUndecoratedAlignmentModel(TokenSet<T> tokenSet)
SequenceIDManager
.tokenSet
- the set of allowed tokens in the sequences of the implementing classpublic AbstractUndecoratedAlignmentModel(TokenSet<T> tokenSet, SequenceIDManager idManager)
tokenSet
- the set of allowed tokens in the sequences of the implementing classidManager
- the ID manager to be used by the new instance (maybe shared among multiple instances)public TokenSet<T> getTokenSet()
AlignmentModel
public void setTokenSet(TokenSet<T> set)
AlignmentModel
set
- the new token set to be usedprotected SequenceIDManager getIDManager()
public boolean isTokensReadOnly()
AlignmentModel
true
if token can be written or removed, false
otherwisepublic boolean isSequencesReadOnly()
AlignmentModel
true
if sequences can be written, renamed or removed, false
otherwisepublic String sequenceNameByID(String sequenceID)
AlignmentModel
sequenceID
- the unique unmodifiable ID the sequence is identified bynull
if no sequence with this ID is contained in this modelpublic String sequenceIDByName(String sequenceName)
AlignmentModel
sequenceName
- the name of the sequence that would be visible to the application usernull
if no sequence with the specified name is contained in this modelprotected abstract void doAddSequence(String sequenceID, String sequenceName)
addSequence(String)
if #isReadOnly()
returns false
.
Implementing classes should add the specified new sequence to their underlying data source in this
method. The according events or exceptions are already created by this class if necessary, therefore
this does not need to be done in the implementation of this method.sequenceID
- the unique identifier for the new sequence which has been generated before the
call of this methodsequenceName
- the initial name the new sequence shall havepublic String addSequence(String sequenceName)
AlignmentModel
sequenceName
- the name of the new sequenceprotected abstract void doRemoveSequence(String sequenceID)
#removeSequence(int)
if #isReadOnly()
returns false
.
Implementing classes should remove the specified sequence from their underlying data source in this
method. The according events or exceptions are already created by this class if necessary, therefore
this does not need to be done in the implementation of this method.sequenceID
- the unique identifier of the sequence to be removedpublic boolean removeSequence(String sequenceID)
AlignmentModel
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 modelprotected void doRenameSequence(String sequenceID, String newSequenceName)
#renameSequence(int, String)
if #isReadOnly()
returns
false
and the specified sequence is contained in this model. Implementing classes should
overwrite this method and rename the specified sequence in their underlying data source if necessary.
The renaming in the maps associating names and IDs used by this class have benn updated before the call of this method. The according events or exceptions are created by this class if necessary, therefore all of this does not need to be done in the implementation of this method. (A change event is fired after this method has been executed.)
This default implementation is empty.
sequenceID
- the unique identifier of the sequence to be removednewSequenceName
- the new name the sequence shall havepublic int getMaxSequenceLength()
#getSequenceLength(int)
for each ID.getApproxMaxSequenceLength()
public int getApproxMaxSequenceLength()
getMaxSequenceLength()
if you need an up-to-date value,
but for a high number of sequences getMaxSequenceLength()
might be much slower.public void setMaxSequeceLengthRecalculte()
public String renameSequence(String sequenceID, String newSequenceName)
AlignmentModel
sequenceID
- the ID of the sequence to be renamednewSequenceName
- the new name the sequence shall havepublic void appendToken(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(String sequenceID, 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)
protected void fireAfterSequenceChange(SequenceChangeEvent<T> e)
AbstractAlignmentModel
fireAfterSequenceChange
in class AbstractAlignmentModel<T>
protected void fireAfterTokenChange(TokenChangeEvent<T> e)
AbstractAlignmentModel
fireAfterTokenChange
in class AbstractAlignmentModel<T>