FreeCBR
Class Feature

java.lang.Object
  extended by FreeCBR.Feature
All Implemented Interfaces:
java.io.Serializable

public class Feature
extends java.lang.Object
implements java.io.Serializable

This class represents a feature defined by a feature type and a value.

Since:
1.0
Author:
Lars Johanson
See Also:
Serialized Form

Field Summary
static short FEATURE_TYPE_BOOL
          The feature is of type Bool
static short FEATURE_TYPE_FLOAT
          The feature is of type Float
static short FEATURE_TYPE_INT
          The feature is of type Int
static short FEATURE_TYPE_MULTISTRING
          The feature is of type MultiString
static short FEATURE_TYPE_STRING
          The feature is of type String
static java.lang.String FEATURE_VALUE_UNDEFINED
          The feature is undefined or not applicable
protected  java.lang.Object value
          Contains the feature value
 
Constructor Summary
Feature(boolean value)
          Creates a feature of type Bool and initiates it
Feature(double value)
          Creates a feature of type Float and initiates it
Feature(long value)
          Creates a feature of type Int and initiates it
Feature(java.lang.String value)
          Creates a feature of type String and initiates it
Feature(java.lang.String[] value)
          Creates a feature of type MultiString and initiates it
Feature(java.lang.String value, short type)
          Creates a feature of specified type from a String
 
Method Summary
 boolean equals(java.lang.Object obj)
          Tests if two Features are equal.
 boolean getBoolValue()
          Returns the feature value if the type is Bool.
 short getFeatureType()
          Returns the type of this feature
 double getFloatValue()
          Returns the feature value if the type is Float.
 long getIntValue()
          Returns the feature value if the type is Int.
 java.lang.String[] getMultiStringValue()
          Returns the feature value if the type is MultiString.
 java.lang.String getStringValue()
          Returns the feature value if the type is String.
 java.lang.Object getValue()
          Returns the feature value casted to Object whatever the actual type is
 boolean isUndefined()
          Is this feature undefined?
protected static java.lang.String multiStringJoin(java.lang.String[] strings)
          Creates a "MultiString" from an array of strings
protected static java.lang.String[] multiStringSplit(java.lang.String mstring)
          Splits a "MultiString" to an array of String:s
static short stringToType(java.lang.String typeString)
          Converts a string representing a type to the type
 java.lang.String toString()
          Returns a string representing the instance
static java.lang.String typeToString(short type)
          Converts a type to a string representing the type
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

protected java.lang.Object value
Contains the feature value


FEATURE_VALUE_UNDEFINED

public static final java.lang.String FEATURE_VALUE_UNDEFINED
The feature is undefined or not applicable

Since:
1.0
See Also:
Constant Field Values

FEATURE_TYPE_STRING

public static final short FEATURE_TYPE_STRING
The feature is of type String

Since:
1.0
See Also:
Constant Field Values

FEATURE_TYPE_MULTISTRING

public static final short FEATURE_TYPE_MULTISTRING
The feature is of type MultiString

Since:
1.0
See Also:
Constant Field Values

FEATURE_TYPE_INT

public static final short FEATURE_TYPE_INT
The feature is of type Int

Since:
1.0
See Also:
Constant Field Values

FEATURE_TYPE_FLOAT

public static final short FEATURE_TYPE_FLOAT
The feature is of type Float

Since:
1.0
See Also:
Constant Field Values

FEATURE_TYPE_BOOL

public static final short FEATURE_TYPE_BOOL
The feature is of type Bool

Since:
1.0
See Also:
Constant Field Values
Constructor Detail

Feature

public Feature(java.lang.String value)
Creates a feature of type String and initiates it

Parameters:
value - the String to initiate the feature with
Since:
1.0

Feature

public Feature(java.lang.String[] value)
Creates a feature of type MultiString and initiates it

Parameters:
value - the String array to initiate the feature with
Since:
1.0

Feature

public Feature(long value)
Creates a feature of type Int and initiates it

Parameters:
value - the integer to initiate the feature with
Since:
1.0

Feature

public Feature(double value)
Creates a feature of type Float and initiates it

Parameters:
value - the floating point to initiate the feature with
Since:
1.0

Feature

public Feature(boolean value)
Creates a feature of type Bool and initiates it

Parameters:
value - the boolean to initiate the feature with
Since:
1.0

Feature

public Feature(java.lang.String value,
               short type)
Creates a feature of specified type from a String

Parameters:
value - the value of the feature. If empty string then feature will be of type FEATURE_VALUE_UNDEFINED
type - the datatype of the feature
Since:
1.0
Method Detail

equals

public boolean equals(java.lang.Object obj)
Tests if two Features are equal. Overrides the default Object implementation

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare
Returns:
true if this object is the same as the obj argument; false otherwise
Since:
1.0

isUndefined

public boolean isUndefined()
Is this feature undefined?

Returns:
true if the feature is undefined, otherwise false
Since:
1.0

getFeatureType

public short getFeatureType()
Returns the type of this feature

Returns:
the feature type
Since:
1.0

getStringValue

public java.lang.String getStringValue()
Returns the feature value if the type is String. Otherwise throws an exception

Returns:
the String value
Throws:
IllegalTypeException - if the feature is not a String
Since:
1.0

getMultiStringValue

public java.lang.String[] getMultiStringValue()
Returns the feature value if the type is MultiString. Otherwise throws an exception

Returns:
the MultiString value
Throws:
IllegalTypeException - if the feature is not a MultiString
Since:
1.0

getIntValue

public long getIntValue()
Returns the feature value if the type is Int. Otherwise throws an exception

Returns:
the Int value
Throws:
IllegalTypeException - if the feature is not an Int
NoDataException - if the value is undefined
Since:
1.0

getFloatValue

public double getFloatValue()
Returns the feature value if the type is Float. Otherwise throws an exception

Returns:
the Float value
Throws:
IllegalTypeException - if the feature is not a Float
NoDataException - if the value is undefined
Since:
1.0

getBoolValue

public boolean getBoolValue()
Returns the feature value if the type is Bool. Otherwise throws an exception

Returns:
the Bool value
Throws:
IllegalTypeException - if the feature is not a Bool
NoDataException - if the value is undefined
Since:
1.0

getValue

public java.lang.Object getValue()
Returns the feature value casted to Object whatever the actual type is

Returns:
the feature value
Since:
1.0

toString

public java.lang.String toString()
Returns a string representing the instance

Overrides:
toString in class java.lang.Object
Returns:
a string
Since:
1.0

stringToType

public static short stringToType(java.lang.String typeString)
Converts a string representing a type to the type

Parameters:
typeString - the string that will be translated to a type, for example "String"
Returns:
the type that the parameter represents (in the example Feature.STRING_FEATURE)
Throws:
IllegalTypeException - if no valid type is found
Since:
1.0

typeToString

public static java.lang.String typeToString(short type)
Converts a type to a string representing the type

Parameters:
type - the type that shall be converted, for example Feature.STRING_FEATURE
Returns:
a string representing the type, for example "String"
Throws:
IllegalTypeException - if no valid type is found
Since:
1.0

multiStringSplit

protected static java.lang.String[] multiStringSplit(java.lang.String mstring)
Splits a "MultiString" to an array of String:s

Parameters:
mstring - the MultiString
Returns:
array of strings retrieved from the mstring
Since:
1.0

multiStringJoin

protected static java.lang.String multiStringJoin(java.lang.String[] strings)
Creates a "MultiString" from an array of strings

Parameters:
strings - array of strings to convert
Returns:
the resulting MultiString
Since:
1.0


Public Domain