simpledb
Class StringField

java.lang.Object
  extended by simpledb.StringField
All Implemented Interfaces:
Field

public class StringField
extends java.lang.Object
implements Field

Instance of Field that stores a single String of a fixed length.


Field Summary
private  int maxSize
           
private  java.lang.String value
           
 
Constructor Summary
StringField(java.lang.String s, int maxSize)
          Constructor.
 
Method Summary
 boolean compare(Predicate.Op op, Field val)
          Compare the specified field to the value of this Field.
 boolean equals(java.lang.Object field)
           
 Type getType()
          Returns the type of this field (see Type.INT_TYPE or Type.STRING_TYPE
 java.lang.String getValue()
           
 int hashCode()
          Hash code.
 void serialize(java.io.DataOutputStream dos)
          Write this string to dos.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

private java.lang.String value

maxSize

private int maxSize
Constructor Detail

StringField

public StringField(java.lang.String s,
                   int maxSize)
Constructor.

Parameters:
s - The value of this field.
maxSize - The maximum size of this string
Method Detail

getValue

public java.lang.String getValue()

toString

public java.lang.String toString()
Specified by:
toString in interface Field
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Description copied from interface: Field
Hash code. Different Field objects representing the same value should probably return the same hashCode.

Specified by:
hashCode in interface Field
Overrides:
hashCode in class java.lang.Object

equals

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

serialize

public void serialize(java.io.DataOutputStream dos)
               throws java.io.IOException
Write this string to dos. Always writes maxSize + 4 bytes to the passed in dos. First four bytes are string length, next bytes are string, with remainder padded with 0 to maxSize.

Specified by:
serialize in interface Field
Parameters:
dos - Where the string is written
Throws:
java.io.IOException
See Also:
DataOutputStream

compare

public boolean compare(Predicate.Op op,
                       Field val)
Compare the specified field to the value of this Field. Return semantics are as specified by Field.compare

Specified by:
compare in interface Field
Parameters:
op - The operator
val - The value to compare this Field to
Returns:
Whether or not the comparison yields true.
Throws:
IllegalCastException - if val is not a StringField
See Also:
Field.compare(simpledb.Predicate.Op, simpledb.Field)

getType

public Type getType()
Description copied from interface: Field
Returns the type of this field (see Type.INT_TYPE or Type.STRING_TYPE

Specified by:
getType in interface Field
Returns:
the Type for this Field