Class ReparentContext
- java.lang.Object
-
- org.biojava.bio.seq.projection.ReparentContext
-
- All Implemented Interfaces:
Serializable,ProjectionContext
- Direct Known Subclasses:
SimpleGappedSequence.GappedContext,SubSequence.SubProjectedFeatureContext,TranslateFlipContext
public class ReparentContext extends Object implements ProjectionContext, Serializable
A good base class to implement ProjectionContext from.ReparentContext takes care of much of the ugliness of implementing ProjectionContext, such as handling listeners and grafting features onto a new parent. It also sets up a framework for mutating feature filters. Think carefully before overriding methods in this class.
- Author:
- Matthew Pocock, Thomas Down
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ReparentContext(FeatureHolder parent, FeatureHolder wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(Feature f, ChangeListener cl, ChangeType ct)Add a ChangeListener to a projected feature.FeaturecreateFeature(Feature.Template projTempl)Create a projected feature with properties matching the template.FeaturecreateFeature(Feature f, Feature.Template projTempl)Create a new projected feature.FeatureHoldergetParent()FeatureHoldergetParent(Feature f)protected FilterUtils.FilterTransformergetReverter()FeatureFiltergetSchema(Feature f)SequencegetSequence(Feature f)Get the sequence for a feature.protected FilterUtils.FilterTransformergetTransformer()FeatureHoldergetUnprojectedFeatures()Get the features before projection.FeatureHolderprojectChildFeatures(Feature f, FeatureHolder parent)Project all features that are children of feature so that they become children of parent.FeatureprojectFeature(Feature feat)Create a single projected feature using the rules of thisProjectedFeatureHolder.FeatureHolderprojectFeatures(FeatureHolder fh)Project all of the features in a FeatureHolder.FeatureFilterprojectFilter(FeatureFilter ff)Transform a filter on unprojected features so that it applies to projected features.voidremoveChangeListener(Feature f, ChangeListener cl, ChangeType ct)Remove a ChangeListener from a projected feature.voidremoveFeature(Feature dyingChild)Remove the dying child.voidremoveFeature(Feature f, Feature f2)Remove the dying child.FeaturerevertFeature(Feature feat)Unproject a feature.FeatureFilterrevertFilter(FeatureFilter ff)Transform a filter on projected features so that it applies to unprojected features.
-
-
-
Constructor Detail
-
ReparentContext
public ReparentContext(FeatureHolder parent, FeatureHolder wrapped)
-
-
Method Detail
-
getParent
public final FeatureHolder getParent()
-
getUnprojectedFeatures
public final FeatureHolder getUnprojectedFeatures()
Description copied from interface:ProjectionContextGet the features before projection.If you are projecting all the features in some feature holder, that is what this method should return.
- Specified by:
getUnprojectedFeaturesin interfaceProjectionContext- Returns:
- the features before projection
-
projectFeature
public Feature projectFeature(Feature feat)
Create a single projected feature using the rules of thisProjectedFeatureHolder.- Specified by:
projectFeaturein interfaceProjectionContext- Parameters:
feat- the Feature to project- Returns:
- a Feature representing feat after being transformed by this context
-
revertFeature
public Feature revertFeature(Feature feat)
Description copied from interface:ProjectionContextUnproject a feature.This is the inverse opperation to @link projectFeature().
Note: The result of calling this method for a feature that is not projected through this context is not specified by this API, but it is reasonable to assume that bad things will happen.
- Specified by:
revertFeaturein interfaceProjectionContext- Parameters:
feat- the Feature to un-project- Returns:
- the unprojected feature
-
projectFilter
public final FeatureFilter projectFilter(FeatureFilter ff)
Description copied from interface:ProjectionContextTransform a filter on unprojected features so that it applies to projected features.- Specified by:
projectFilterin interfaceProjectionContext- Parameters:
ff- the FeatureFilter to transform- Returns:
- the transformed FeatureFilter
-
revertFilter
public final FeatureFilter revertFilter(FeatureFilter ff)
Description copied from interface:ProjectionContextTransform a filter on projected features so that it applies to unprojected features.- Specified by:
revertFilterin interfaceProjectionContext- Parameters:
ff- the FeatureFilter to transform- Returns:
- the transformed FeatureFilter
-
getTransformer
protected FilterUtils.FilterTransformer getTransformer()
-
getReverter
protected FilterUtils.FilterTransformer getReverter()
-
getParent
public final FeatureHolder getParent(Feature f)
- Specified by:
getParentin interfaceProjectionContext
-
getSequence
public final Sequence getSequence(Feature f)
Description copied from interface:ProjectionContextGet the sequence for a feature.This will be the return value of
projFeat.getParent().- Specified by:
getSequencein interfaceProjectionContext- Parameters:
f- the projected Feature- Returns:
- the Sequence of the Feature
-
projectChildFeatures
public FeatureHolder projectChildFeatures(Feature f, FeatureHolder parent)
Description copied from interface:ProjectionContextProject all features that are children of feature so that they become children of parent.- Specified by:
projectChildFeaturesin interfaceProjectionContext- Parameters:
f- the Feature to project all children ofparent- the new parent feature holder- Returns:
- a FeatureHolder containing projections of all children of feature so that f.getParent() is equal to parent
-
createFeature
public final Feature createFeature(Feature.Template projTempl) throws BioException, ChangeVetoException
Description copied from interface:ProjectionContextCreate a projected feature with properties matching the template.You will probably implement this by delegating to the unprojected feature holder. It is imperative that the template properties are unprojected first so that when the newly created feature is projected, the properties match up.
Not every projection context has fully reversible semantics. Use your discression and come up with a reasonable plan that causes least supprise to the user.
- Specified by:
createFeaturein interfaceProjectionContext- Parameters:
projTempl- the Feature.Template to instantiate- Returns:
- a new projected Feature matching the template as closely as possible
- Throws:
BioException- if there was a problem instantiating the templateChangeVetoException- if the feature creation was vetoed
-
removeFeature
public final void removeFeature(Feature dyingChild) throws BioException, ChangeVetoException
Description copied from interface:ProjectionContextRemove the dying child.- Specified by:
removeFeaturein interfaceProjectionContext- Parameters:
dyingChild- a projected feature to remove- Throws:
BioException- if there is an error removing the featureChangeVetoException- if the removal of the feature was vetoed
-
createFeature
public final Feature createFeature(Feature f, Feature.Template projTempl) throws BioException, ChangeVetoException
Description copied from interface:ProjectionContextCreate a new projected feature.See the notes for @link createFeature(Feature.Template) for implementation advice.
- Specified by:
createFeaturein interfaceProjectionContext- Parameters:
f- the parent for the newly created featureprojTempl- the Feature.Template specifying the new feature- Returns:
- a new ProjectedFeature that is a child of projParent
- Throws:
BioException- if there was a problem creating the featureChangeVetoException- if the creation of the feature was vetoed
-
removeFeature
public final void removeFeature(Feature f, Feature f2) throws ChangeVetoException, BioException
Description copied from interface:ProjectionContextRemove the dying child.- Specified by:
removeFeaturein interfaceProjectionContext- Parameters:
f- the projected parent Featuref2- the child Feature to remove- Throws:
ChangeVetoException- if the removal of the feature was vetoedBioException
-
getSchema
public final FeatureFilter getSchema(Feature f)
-
addChangeListener
public final void addChangeListener(Feature f, ChangeListener cl, ChangeType ct)
Description copied from interface:ProjectionContextAdd a ChangeListener to a projected feature.- Specified by:
addChangeListenerin interfaceProjectionContext- Parameters:
f- the projected Feature to add the listener forcl- the ChangeListener to addct- the ChangeType to register it for
-
removeChangeListener
public final void removeChangeListener(Feature f, ChangeListener cl, ChangeType ct)
Description copied from interface:ProjectionContextRemove a ChangeListener from a projected feature.- Specified by:
removeChangeListenerin interfaceProjectionContext- Parameters:
f- the projected Feature to remove the listener forcl- the ChangeListener to removect- the ChangeType it is registered for
-
projectFeatures
public final FeatureHolder projectFeatures(FeatureHolder fh)
Description copied from interface:ProjectionContextProject all of the features in a FeatureHolder.Warning: The results of calling this method for features that are not in getUnprojectedFeatures() is not specified by this API, but it is reasonable to assume that bad things will happen.
- Specified by:
projectFeaturesin interfaceProjectionContext- Parameters:
fh- the FeatureHolder containing the features to project- Returns:
- a FeatureHolder containing all the features projected
-
-