edu.indiana.iucbrf.feature
Class AbstractFeatureCollection

java.lang.Object
  extended by edu.indiana.iucbrf.feature.AbstractFeatureCollection
All Implemented Interfaces:
Feature, FeatureCollection, SwingRepresentableWithDomain, SwingRepresentable, java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
FeatureMap

public abstract class AbstractFeatureCollection
extends java.lang.Object
implements FeatureCollection, java.io.Serializable

This class makes some assumptions that are general enough to apply to most FeatureCollection implementations.

See Also:
Serialized Form

Nested Class Summary
 class AbstractFeatureCollection.FeatureCollectionPanel
           
 class AbstractFeatureCollection.FeatureCollectionTableModel
           
static class AbstractFeatureCollection.Key_KeyText_EntryIterator
          An iterator whose keys are FeatureKeys and whose values are the toString()s of those FeatureKeys.
static interface AbstractFeatureCollection.KeyTextEntryIterator
          The Object returned by next() is a Map.Entry with a FeatureKey key and a String value (some kind of description of that key).
static class AbstractFeatureCollection.Ordered_Key_DescText_EntryIterator
          An iterator over EntryImpl objects, whose keys are FeatureKeys and whose values are the textual descriptions of the features with those FeatureKeys.
 
Field Summary
protected  int collectionType
           
protected  boolean containsEstimates
          True if this collection contains feature estimates.
protected  java.lang.String customTitle
          The custom title, if set, overrules the standard title in the domain.
static int DEFAULT_VARIABLE_TYPE
           
static javax.swing.border.Border INSETS_BORDER
           
protected  boolean isReferenceSolution
           
protected  java.util.HashMap keyToConf
          Maps FeatureKey to the confidence (Double) in that feature value.
protected  java.util.ArrayList listeners
           
 
Fields inherited from interface edu.indiana.iucbrf.feature.FeatureCollection
PROBLEM_FEATURE_COLLECTION, SOLUTION_FEATURE_COLLECTION
 
Fields inherited from interface edu.indiana.util.swing.SwingRepresentable
TITLE_FONT
 
Fields inherited from interface edu.indiana.iucbrf.feature.Feature
DEFAULT_FEATURE_DIFFERENTIATORS_BY_VARTYPE, FEATURE_VALUE_FONT, INTERVAL_VARIABLE, LABEL_WIDTH, NOMINAL_VARIABLE, ORDINAL_VARIABLE, OTHER_VARIABLE
 
Fields inherited from interface edu.indiana.util.swing.SwingRepresentable
TITLE_FONT
 
Constructor Summary
protected AbstractFeatureCollection()
          Creates a new instance of AbstractFeatureCollection
  AbstractFeatureCollection(double[] featureValues, Domain domain, int collectionType)
          Assumes featureValues are in the correct order, either all are known for this domain or there are fewer featureValues than feature slots, and the last feature slots will not be filled in.
  AbstractFeatureCollection(DoubleCollection someFeatureValues, Domain domain, int collectionType)
           
  AbstractFeatureCollection(Feature[] features, Domain domain, int collectionType)
          Assumes featureValues are in the correct order, either all are known for this domain or there are fewer featureValues than feature slots, and the last feature slots will not be filled in.
  AbstractFeatureCollection(FeatureKey[] keys, Feature[] features, int collectionType)
           
  AbstractFeatureCollection(int collectionType)
           
  AbstractFeatureCollection(int collectionType, int initialCapacity)
           
 
Method Summary
 void addEstimatedFeature(FeatureKey featureKey, Feature additional_feature, double confidence, Domain domain)
          Add an estimated feature to this FeatureCollection.
 void addFeature(FeatureKey featureKey, Feature additional_feature, Domain domain)
          Add a feature to this FeatureCollection.
 void addFeatureCollectionListener(FeatureCollectionListener cll)
           
protected abstract  void addFeatureImpl(FeatureKey key, Feature feature)
          Add a feature to the collection.
 void adjust(double adjustAmount)
           
 void clearAllEstimates()
          Remove all estimated features from this collection.
 void clearEstimate(FeatureKey key)
          Remove the given estimated feature from this collection.
 void clearFeatures()
          Clear all features in this FeatureCollection.
protected abstract  void clearFeaturesImpl()
          Clear all features in this FeatureCollection.
 java.lang.Object clone()
           
protected  void commonInit(int collectionType, int initialCapacity)
           
 int compareTo(java.lang.Object other)
           
 boolean containsEstimates()
           
 boolean equals(java.lang.Object other)
           
protected  void fireFeatureAdded(FeatureKey key)
           
protected  void fireFeatureChange(FeatureKey key)
           
protected  void fireFeatureRemoved(FeatureKey key)
           
protected  void fireFeatureReplaced(FeatureKey key)
           
protected  void fireFeaturesCleared()
           
 int getCollectionType()
           
 double getConfidence(FeatureKey key)
          Get the confidence in the value of a feature.
 java.lang.String getCustomTitle()
          Returns null if no custom title is set (in which case, the standard title defined in the domain should be used.
 int getDefaultVariableType()
          Get the variable type (for example, Feature.NOMINAL_VARIABLE, Feature.ORDINAL_VARIABLE, Feature.INTERVAL_VARIABLE, or Feature.OTHER_VARIABLE).
 java.util.ArrayList getFeaturesMatching(java.lang.Class feature_class)
          Get the features that are of the given class.
 boolean getIsReferenceSolution()
           
 int getKnownFeatureCount()
          Get the number of known features in this collection (not including estimated features).
protected  java.lang.String getTitle(Domain domain)
           
protected abstract  void initializeCollection(int initialCapacity)
          Override to construct needed object (may ignore initialCapacity if not applicable)
 boolean isDefinitelyKnown(FeatureKey key)
           
 boolean isEstimated(FeatureKey key)
           
 Feature midpoint(Feature other_feature)
           
 Feature removeFeature(FeatureKey key)
          Remove the feature at the given index.
 void removeFeatureCollectionListener(FeatureCollectionListener cll)
           
protected abstract  Feature removeFeatureImpl(FeatureKey key)
          Remove the feature at the given index from this FeatureCollection.
 Feature replaceFeature(FeatureKey key, Feature replacement_feature, Domain domain)
          Replace the feature at the given index with another feature.
protected abstract  Feature replaceFeatureImpl(FeatureKey key, Feature feature)
          Set the feature at an index in the collection to the given feature.
protected  void setConfidence(FeatureKey key, double confidence)
          Set the confidence c in this feature.
 void setCustomTitle(java.lang.String customTitle)
          Set a custom title to override the standard title (defined in the domain) for this FeatureCollection.
 void setIsReferenceSolution(boolean isReferenceSolution)
           
 java.lang.String toString()
          For an ordered display, call toString(Domain).
 java.lang.String toString(Domain domain)
           
 java.lang.String toString(FeatureValueFormat formatter)
           
 javax.swing.JComponent toSwing(Domain domain)
           
 javax.swing.JComponent toSwing(FeatureValueFormat formatter)
           
 javax.swing.JComponent toSwing(int detailLevel)
          Does not print nice labels for the features: only prints the keys
 AbstractFeatureCollection.FeatureCollectionPanel toSwing(java.util.Iterator entryIter)
           
 AbstractFeatureCollection.FeatureCollectionPanel toSwing(java.util.Iterator entryIter, Domain domain)
          If the domain is not known, null may be passed, but SwingRepresentableWithDomain Features may not display properly
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.indiana.iucbrf.feature.FeatureCollection
entryIterator, featureIterator, getFeature, getKeySet, getTotalFeatureCount, keyIterator
 
Methods inherited from interface edu.indiana.iucbrf.feature.Feature
getValue, setValue
 

Field Detail

DEFAULT_VARIABLE_TYPE

public static final int DEFAULT_VARIABLE_TYPE
See Also:
Constant Field Values

listeners

protected transient java.util.ArrayList listeners

collectionType

protected int collectionType

isReferenceSolution

protected boolean isReferenceSolution

customTitle

protected java.lang.String customTitle
The custom title, if set, overrules the standard title in the domain.


keyToConf

protected java.util.HashMap keyToConf
Maps FeatureKey to the confidence (Double) in that feature value. Confidences for definitely-known (not estimated) values are 1.0, and are not stored in keyToConf. Confidences for estimated (by an UnknownFeatureHandler) values are between 0.0 and 1.0, exclusive, and are stored in keyToConf. Confidences for unknown values are 0.0, and are not stored in keyToConf.


containsEstimates

protected boolean containsEstimates
True if this collection contains feature estimates. False otherwise.


INSETS_BORDER

public static final javax.swing.border.Border INSETS_BORDER
Constructor Detail

AbstractFeatureCollection

protected AbstractFeatureCollection()
Creates a new instance of AbstractFeatureCollection


AbstractFeatureCollection

public AbstractFeatureCollection(int collectionType)

AbstractFeatureCollection

public AbstractFeatureCollection(int collectionType,
                                 int initialCapacity)

AbstractFeatureCollection

public AbstractFeatureCollection(double[] featureValues,
                                 Domain domain,
                                 int collectionType)
Assumes featureValues are in the correct order, either all are known for this domain or there are fewer featureValues than feature slots, and the last feature slots will not be filled in. Also assumes that all feature types are DoubleRepresentable.


AbstractFeatureCollection

public AbstractFeatureCollection(Feature[] features,
                                 Domain domain,
                                 int collectionType)
Assumes featureValues are in the correct order, either all are known for this domain or there are fewer featureValues than feature slots, and the last feature slots will not be filled in.


AbstractFeatureCollection

public AbstractFeatureCollection(FeatureKey[] keys,
                                 Feature[] features,
                                 int collectionType)

AbstractFeatureCollection

public AbstractFeatureCollection(DoubleCollection someFeatureValues,
                                 Domain domain,
                                 int collectionType)
Method Detail

commonInit

protected void commonInit(int collectionType,
                          int initialCapacity)

initializeCollection

protected abstract void initializeCollection(int initialCapacity)
Override to construct needed object (may ignore initialCapacity if not applicable)


getCollectionType

public int getCollectionType()
Specified by:
getCollectionType in interface FeatureCollection

getDefaultVariableType

public int getDefaultVariableType()
Description copied from interface: Feature
Get the variable type (for example, Feature.NOMINAL_VARIABLE, Feature.ORDINAL_VARIABLE, Feature.INTERVAL_VARIABLE, or Feature.OTHER_VARIABLE).

Specified by:
getDefaultVariableType in interface Feature

setIsReferenceSolution

public void setIsReferenceSolution(boolean isReferenceSolution)
Specified by:
setIsReferenceSolution in interface FeatureCollection

getIsReferenceSolution

public boolean getIsReferenceSolution()
Specified by:
getIsReferenceSolution in interface FeatureCollection

getCustomTitle

public java.lang.String getCustomTitle()
Returns null if no custom title is set (in which case, the standard title defined in the domain should be used.

Specified by:
getCustomTitle in interface FeatureCollection

setCustomTitle

public void setCustomTitle(java.lang.String customTitle)
Set a custom title to override the standard title (defined in the domain) for this FeatureCollection.

Specified by:
setCustomTitle in interface FeatureCollection

getConfidence

public double getConfidence(FeatureKey key)
Get the confidence in the value of a feature.

Specified by:
getConfidence in interface FeatureCollection
Returns:
c, where c == 1.0 for definitely known (not estimated) features, 0.0 < c < 1.0 for estimated features, and c == 0.0 for unknown and unestimated values.

setConfidence

protected void setConfidence(FeatureKey key,
                             double confidence)
Set the confidence c in this feature. c == 1.0 for definitely known (not estimated) features, 0.0 < c < 1.0 for estimated features, and c == 0.0 for unknown and unestimated values. This method need only be called for estimated features, to indicate that they are estimated. Unknown and definitely known features have assumed confidence values.


isDefinitelyKnown

public boolean isDefinitelyKnown(FeatureKey key)
Specified by:
isDefinitelyKnown in interface FeatureCollection
Returns:
true if the feature is known, false if estimated or unknown.

isEstimated

public boolean isEstimated(FeatureKey key)
Specified by:
isEstimated in interface FeatureCollection
Returns:
true if the feature is estimated, false if definitely known or unknown.

getKnownFeatureCount

public int getKnownFeatureCount()
Description copied from interface: FeatureCollection
Get the number of known features in this collection (not including estimated features).

Specified by:
getKnownFeatureCount in interface FeatureCollection
Returns:
The number of features known (not including estimated features).

clearAllEstimates

public void clearAllEstimates()
Remove all estimated features from this collection.

Specified by:
clearAllEstimates in interface FeatureCollection

clearEstimate

public void clearEstimate(FeatureKey key)
Remove the given estimated feature from this collection. Request ignored if the given key does not correspond to an estimated feature.

Specified by:
clearEstimate in interface FeatureCollection

containsEstimates

public boolean containsEstimates()
Specified by:
containsEstimates in interface FeatureCollection
Returns:
true when the collection contains estimated features, false otherwise.

getFeaturesMatching

public java.util.ArrayList getFeaturesMatching(java.lang.Class feature_class)
Description copied from interface: FeatureCollection
Get the features that are of the given class.

Specified by:
getFeaturesMatching in interface FeatureCollection
Returns:
An unordered ArrayList of Map.Entry objects

addEstimatedFeature

public void addEstimatedFeature(FeatureKey featureKey,
                                Feature additional_feature,
                                double confidence,
                                Domain domain)
Description copied from interface: FeatureCollection
Add an estimated feature to this FeatureCollection.

Specified by:
addEstimatedFeature in interface FeatureCollection
additional_feature - The feature to add.

addFeature

public void addFeature(FeatureKey featureKey,
                       Feature additional_feature,
                       Domain domain)
Description copied from interface: FeatureCollection
Add a feature to this FeatureCollection.

Specified by:
addFeature in interface FeatureCollection
additional_feature - The feature to add.

replaceFeature

public Feature replaceFeature(FeatureKey key,
                              Feature replacement_feature,
                              Domain domain)
Description copied from interface: FeatureCollection
Replace the feature at the given index with another feature.

Specified by:
replaceFeature in interface FeatureCollection
replacement_feature - The feature to replace the one at the index.

clearFeatures

public void clearFeatures()
Description copied from interface: FeatureCollection
Clear all features in this FeatureCollection.

Specified by:
clearFeatures in interface FeatureCollection

removeFeature

public Feature removeFeature(FeatureKey key)
Description copied from interface: FeatureCollection
Remove the feature at the given index.

Specified by:
removeFeature in interface FeatureCollection
Parameters:
key - The key of the feature to remove.

equals

public boolean equals(java.lang.Object other)
Specified by:
equals in interface FeatureCollection
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object other)
Specified by:
compareTo in interface java.lang.Comparable

toSwing

public javax.swing.JComponent toSwing(Domain domain)
Specified by:
toSwing in interface SwingRepresentableWithDomain

toString

public java.lang.String toString(FeatureValueFormat formatter)
Specified by:
toString in interface Feature

toSwing

public javax.swing.JComponent toSwing(FeatureValueFormat formatter)
Specified by:
toSwing in interface Feature

toSwing

public javax.swing.JComponent toSwing(int detailLevel)
Does not print nice labels for the features: only prints the keys

Specified by:
toSwing in interface SwingRepresentable
Returns:
A JPanel containing a JTable

getTitle

protected java.lang.String getTitle(Domain domain)

toSwing

public AbstractFeatureCollection.FeatureCollectionPanel toSwing(java.util.Iterator entryIter,
                                                                Domain domain)
If the domain is not known, null may be passed, but SwingRepresentableWithDomain Features may not display properly

Parameters:
entryIter - should return entries with a FeatureKey key and a feature description (String) value.
Returns:
A JPanel containing a JTable

toSwing

public AbstractFeatureCollection.FeatureCollectionPanel toSwing(java.util.Iterator entryIter)

toString

public java.lang.String toString(Domain domain)
Specified by:
toString in interface FeatureCollection

toString

public java.lang.String toString()
For an ordered display, call toString(Domain). Does not print nice labels for the features: only prints the keys

Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Specified by:
clone in interface Feature
Overrides:
clone in class java.lang.Object

midpoint

public Feature midpoint(Feature other_feature)
Specified by:
midpoint in interface Feature

adjust

public void adjust(double adjustAmount)
            throws CouldNotAdjustException,
                   java.lang.UnsupportedOperationException
Specified by:
adjust in interface Feature
Throws:
CouldNotAdjustException
java.lang.UnsupportedOperationException

addFeatureCollectionListener

public void addFeatureCollectionListener(FeatureCollectionListener cll)
Specified by:
addFeatureCollectionListener in interface FeatureCollection

removeFeatureCollectionListener

public void removeFeatureCollectionListener(FeatureCollectionListener cll)
Specified by:
removeFeatureCollectionListener in interface FeatureCollection

fireFeatureChange

protected void fireFeatureChange(FeatureKey key)

fireFeatureReplaced

protected void fireFeatureReplaced(FeatureKey key)

fireFeaturesCleared

protected void fireFeaturesCleared()

fireFeatureRemoved

protected void fireFeatureRemoved(FeatureKey key)

fireFeatureAdded

protected void fireFeatureAdded(FeatureKey key)

addFeatureImpl

protected abstract void addFeatureImpl(FeatureKey key,
                                       Feature feature)
Add a feature to the collection. This method assumes that issues such as type checking and event-handling are already taken care of, and the feature merely needs to be added to the collection.

Parameters:
feature - The feature to add

replaceFeatureImpl

protected abstract Feature replaceFeatureImpl(FeatureKey key,
                                              Feature feature)
Set the feature at an index in the collection to the given feature. This method assumes that issues such as type checking and event-handling are already taken care of, and the feature merely needs to be replaced in the collection.

Returns:
The old feature value

clearFeaturesImpl

protected abstract void clearFeaturesImpl()
Clear all features in this FeatureCollection.


removeFeatureImpl

protected abstract Feature removeFeatureImpl(FeatureKey key)
Remove the feature at the given index from this FeatureCollection. This method assumes that issues such as type checking and event-handling are already taken care of, and the feature merely needs to be removed from the collection.

Parameters:
index - The index of the feature to be removed.