## org.biojava.bio.seq
Class LazyFeatureHolder

    java.lang.Object
      org.biojava.utils.AbstractChangeable
          org.biojava.bio.seq.LazyFeatureHolder

All Implemented Interfaces:
  FeatureHolder, Changeable

    public abstract class LazyFeatureHolder

extends AbstractChangeable
implements FeatureHolder

Wrapper implementation of FeatureHolder which calls a method to create a contained FeatureHolder on demand. This is an abstract class and is normally used like: FeatureHolder fh = new LazyFeatureHolder() { protected FeatureHolder createFeatureHolder() { SimpleFeatureHolder features = new SimpleFeatureHolder(); // Create some features in here... return features; } } ;

Since:
  1.2
Author:
  Thomas Down, Matthew Pocock
See Also:
  `RichFeatureHolder`

Nested Class Summary

Nested classes/interfaces inherited from interface org.biojava.bio.seq.FeatureHolder
`FeatureHolder.EmptyFeatureHolder`

Field Summary

Fields inherited from interface org.biojava.bio.seq.FeatureHolder
`EMPTY_FEATURE_HOLDER, FEATURES, SCHEMA`

Constructor Summary
`protected` `LazyFeatureHolder()` Construct a LazyFeatureHolder with the schema of its contained featureholder
`protected` `LazyFeatureHolder(FeatureFilter schema)` Construct a LazyFeatureHolder with the specified schema

Method Summary
`boolean` `containsFeature(Feature f)` Check if the feature is present in this holder.
`int` `countFeatures()` Count how many features are contained.
`Feature` `createFeature(Feature.Template template)` Create a new Feature, and add it to this FeatureHolder.
`protected abstract FeatureHolder` `createFeatureHolder()`
`java.util.Iterator` `features()` Iterate over the features in no well defined order.
`FeatureHolder` `filter(FeatureFilter ff)` Query this set of features using a supplied `FeatureFilter`.
`FeatureHolder` `filter(FeatureFilter ff, boolean recurse)` Return a new FeatureHolder that contains all of the children of this one that passed the filter fc.
`protected void` `flushFeatures()`
`protected ChangeSupport` `getChangeSupport(ChangeType ct)` Called to retrieve the ChangeSupport for this object.
`FeatureFilter` `getSchema()` Return a schema-filter for this `FeatureHolder`.
`void` `removeFeature(Feature f)` Remove a feature from this FeatureHolder.

Methods inherited from class org.biojava.utils.AbstractChangeable
`addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface org.biojava.utils.Changeable
`addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener`

Constructor Detail

### LazyFeatureHolder

    protected LazyFeatureHolder()

  Construct a LazyFeatureHolder with the schema of its contained featureholder

### LazyFeatureHolder

    protected LazyFeatureHolder(FeatureFilter schema)

  Construct a LazyFeatureHolder with the specified schema

Method Detail

### getSchema

    public FeatureFilter getSchema()

  Description copied from interface: `FeatureHolder`
  Return a schema-filter for this `FeatureHolder`. This is a filter which all `Feature`s immediately contained by this `FeatureHolder` will match. It need not directly match their child features, but it can (and should!) provide information about them using `FeatureFilter.OnlyChildren` filters. In cases where there is no feature hierarchy, this can be indicated by including `FeatureFilter.leaf` in the schema filter.

  For the truly non-informative case, it is possible to return `FeatureFilter.all`. However, it is almost always possible to provide slightly more information that this. For example, `Sequence` objects should, at a minimum, return `FeatureFilter.top_level`. `Feature` objects should, as a minimum, return `FeatureFilter.ByParent(new FeatureFilter.ByFeature(this))`.

  Specified by:
    `getSchema` in interface `FeatureHolder`
  Returns:
    the schema filter

### createFeatureHolder

    protected abstract FeatureHolder createFeatureHolder()

### flushFeatures

    protected void flushFeatures()

### features

    public java.util.Iterator features()

  Description copied from interface: `FeatureHolder`
  Iterate over the features in no well defined order.

  Specified by:
    `features` in interface `FeatureHolder`
  Returns:
    an Iterator

### countFeatures

    public int countFeatures()

  Description copied from interface: `FeatureHolder`
  Count how many features are contained.

  Specified by:
    `countFeatures` in interface `FeatureHolder`
  Returns:
    a positive integer or zero, equal to the number of features contained

### filter

    public FeatureHolder filter(FeatureFilter ff)

  Description copied from interface: `FeatureHolder`
  Query this set of features using a supplied `FeatureFilter`.

  Specified by:
    `filter` in interface `FeatureHolder`
  Parameters:
    `ff` - the `FeatureFilter` to apply.
  Returns:
    all features in this container which match `filter`.

### filter

    public FeatureHolder filter(FeatureFilter ff,
                                boolean recurse)

  Description copied from interface: `FeatureHolder`
  Return a new FeatureHolder that contains all of the children of this one that passed the filter fc. This method is scheduled for deprecation. Use the 1-arg filter instead.

  Specified by:
    `filter` in interface `FeatureHolder`
  Parameters:
    `ff` - the FeatureFilter to apply
    `recurse` - true if all features-of-features should be scanned, and a single flat collection of features returned, or false if just immediate children should be filtered.

### createFeature

    public Feature createFeature(Feature.Template template)
                          throws BioException,
                                 ChangeVetoException

  Description copied from interface: `FeatureHolder`
  Create a new Feature, and add it to this FeatureHolder. This method will generally only work on Sequences, and on some Features which have been attached to Sequences.

  Specified by:
    `createFeature` in interface `FeatureHolder`
  Throws:
    `BioException` - if something went wrong during creating the feature
    `ChangeVetoException` - if this FeatureHolder does not support creation of new features, or if the change was vetoed

### removeFeature

    public void removeFeature(Feature f)
                       throws ChangeVetoException,
                              BioException

  Description copied from interface: `FeatureHolder`
  Remove a feature from this FeatureHolder.

  Specified by:
    `removeFeature` in interface `FeatureHolder`
  Throws:
    `ChangeVetoException` - if this FeatureHolder does not support feature removal or if the change was vetoed
    `BioException` - if there was an error removing the feature

### containsFeature

    public boolean containsFeature(Feature f)

  Description copied from interface: `FeatureHolder`
  Check if the feature is present in this holder.

  Specified by:
    `containsFeature` in interface `FeatureHolder`
  Parameters:
    `f` - the Feature to check
  Returns:
    true if f is in this set

### getChangeSupport

    protected ChangeSupport getChangeSupport(ChangeType ct)

  Description copied from class: `AbstractChangeable`
  Called to retrieve the ChangeSupport for this object.

  Your implementation of this method should have the following structure: ``

       ChangeSupport cs = super.getChangeSupport(ct);

       if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) {
         someForwarder = new ChangeForwarder(...

         this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange);
       }

       return cs;

  It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register & unregister the forwarder in the code that does the ChangeEvent handling in setter methods.

  Overrides:
    `getChangeSupport` in class `AbstractChangeable`