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,
boolean reuseSequenceIDs)
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.
|
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 void |
doAddSequence(java.lang.String sequenceID,
java.lang.String sequenceName)
|
protected abstract void |
doRemoveSequence(java.lang.String sequenceID)
This method is called by
#removeSequence(int) if #isReadOnly() returns false . |
protected void |
doRenameSequence(java.lang.String sequenceID,
java.lang.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 |
isReuseSequenceIDs()
Determines whether new sequence IDs should be created each time a new sequence is added or if existing IDs already
present for a specified name in the ID manager should be reused.
|
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(java.lang.String sequenceID)
Removes the specified sequence 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.
|
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 |
setMaxSequeceLengthRecalculte() |
void |
setReuseSequenceIDs(boolean reuseSequenceIDs)
Allows to specify whether unused IDs of the underlying ID manager should be reused by this model.
|
void |
setTokenSet(TokenSet<T> set)
Replaces the current token set with the specified one.
|
fireAfterSequenceRenamed, getChangeListeners, getID, getLabel, setID, 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, boolean reuseSequenceIDs)
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)reuseSequenceIDs
- Specifies whether unused IDs of the underlying ID manager should be reused by this model.
(See the documentation of isReuseSequenceIDs()
for details. Specify false
, if you are unsure
what this property does.)public TokenSet<T> getTokenSet()
AlignmentModel
public void setTokenSet(TokenSet<T> set)
AlignmentModel
set
- the new token set to be usedpublic boolean isReuseSequenceIDs()
The default value for this property is false
, which will be the best choice in most application. It can be
set to true
if specific IDs, e.g. provided by a shared ID manager should be used. (Removing a sequence
with a certain name and later on adding another sequence with the same name will e.g. result in a reuse of the old
ID for the new sequence.) Reusing IDs may cause problems, if out-dated IDs are stored in application code as
references, since these refer to a new sequence, when such an ID is reused. Application developers must make sure
to avoid respective problems, when setting this property to true
.
If this property is set to true
, IDs will only be reused if a sequences with a name is inserted for which
the underlying ID manager already contains a mapping that is currently not used by this model. Sequences with names
without any present mapping in the ID manager will always get new IDs and there will never be two sequences with
the same ID in one model, even if they have identical names.
If this property is set to false
, IDs will never be reused.
true
if IDs should be reused or false
otherwisepublic void setReuseSequenceIDs(boolean reuseSequenceIDs)
isReuseSequenceIDs()
for details.)reuseSequenceIDs
- Specify true
here if IDs should be reused or false
otherwise.protected 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 java.lang.String sequenceNameByID(java.lang.String sequenceID)
AlignmentModel
sequenceID
- the unique unmodifiable ID the sequence is identified bynull
if no sequence with this ID is contained in this modelpublic java.util.Set<java.lang.String> sequenceIDsByName(java.lang.String sequenceName)
AlignmentModel
sequenceName
- the name of the sequence that would be visible to the application userprotected abstract void doAddSequence(java.lang.String sequenceID, java.lang.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 java.lang.String addSequence(java.lang.String sequenceName)
AlignmentModel
sequenceName
- the name of the new sequencepublic java.lang.String addSequence(java.lang.String sequenceName, java.lang.String sequenceID) throws AlignmentSourceNotWritableException, java.lang.IllegalArgumentException
AlignmentModel
sequenceName
- the name of the new sequencesequenceID
- the ID the new sequence shall havesequenceID
)AlignmentSourceNotWritableException
- if the underlying data source is not writable for sequencesjava.lang.IllegalArgumentException
- if a sequence with the specified ID is already present in this modelprotected abstract void doRemoveSequence(java.lang.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(java.lang.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(java.lang.String sequenceID, java.lang.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 java.lang.String renameSequence(java.lang.String sequenceID, java.lang.String newSequenceName)
AlignmentModel
sequenceID
- the ID of the sequence to be renamednewSequenceName
- the new name the sequence shall havepublic 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)
protected void fireAfterSequenceChange(SequenceChangeEvent<T> e)
AbstractAlignmentModel
fireAfterSequenceChange
in class AbstractAlignmentModel<T>
protected void fireAfterTokenChange(TokenChangeEvent<T> e)
AbstractAlignmentModel
fireAfterTokenChange
in class AbstractAlignmentModel<T>