|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.umd.cloud9.io.Schema
public class Schema
Description of a Tuple's structure. The Schema class keeps track of column names, data types, and default values. The following code fragment illustrates the use of this class:
public static final Schema MYSCHEMA = new Schema();
static {
MYSCHEMA.addField("token", String.class, "");
MYSCHEMA.addField("int", Integer.class, new Integer(1));
}
The following field types are allowed:
Schema instances can be locked to prevent further changes. Any attempt to alter a locked Schema will result in a runtime exception being thrown. If a Schema is not locked, callers are free to add new fields and edit default values.
New Tuple instances can be created directly from Schema objects through the
use of the instantiate() method. A call to that method implicitly
locks the Schema.
Acknowledgments: much of this code was adapted from the Prefuse Visualization Toolkit.
| Constructor Summary | |
|---|---|
Schema()
Creates a new empty Schema. |
|
Schema(int n)
Creates a new empty Schema with a starting capacity for a given number of fields. |
|
Schema(String[] names,
Class<?>[] types)
Create a new Schema consisting of the given field names and types. |
|
Schema(String[] names,
Class<?>[] types,
Object[] defaults)
Create a new Schema consisting of the given field names, types, and default field values. |
|
| Method Summary | |
|---|---|
void |
addField(String name,
Class<?> type)
Adds a field to this Schema. |
void |
addField(String name,
Class<?> type,
Object defaultValue)
Adds a field to this schema. |
Object |
clone()
Creates a copy of this Schema. |
boolean |
equals(Object o)
Compares this Schema with another one for equality. |
Object |
getDefault(int index)
Returns the default value of the field at the given position. |
Object |
getDefault(String field)
Returns the default value of the field with the given name. |
int |
getFieldCount()
Returns the number of fields in this Schema. |
int |
getFieldIndex(String field)
Returns the position of a field given its name. |
String |
getFieldName(int index)
Returns the name of the field at the given position. |
Class<?> |
getFieldType(int index)
Returns the type of the field at the given position. |
Class<?> |
getFieldType(String field)
Returns the type of the field given its name. |
int |
hashCode()
Computes a hashcode for this schema. |
Tuple |
instantiate()
Instantiate a new Tuple instance with this Schema. |
Tuple |
instantiate(Object... objects)
Instantiate a new Tuple instance with this Schema. |
boolean |
isLocked()
Checks if this schema is locked. |
Schema |
lockSchema()
Locks the Schema, preventing any additional changes. |
void |
setDefault(int index,
Object val)
Sets the default value for the given field. |
void |
setDefault(String field,
boolean val)
Set the default value for the given field as a boolean. |
void |
setDefault(String field,
double val)
Set the default value for the given field as a double. |
void |
setDefault(String field,
float val)
Set the default value for the given field as a float. |
void |
setDefault(String field,
int val)
Sets the default value for the given field as an int. |
void |
setDefault(String field,
long val)
Set the default value for the given field as a long. |
void |
setDefault(String field,
Object val)
Sets the default value for the given field. |
String |
toString()
Returns a descriptive String for this schema. |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Schema()
public Schema(int n)
n - the number of columns in this schema
public Schema(String[] names,
Class<?>[] types)
names - the field namestypes - the field types (as Class instances)
public Schema(String[] names,
Class<?>[] types,
Object[] defaults)
names - the field namestypes - the field types (as Class instances)defaults - the default values for each field| Method Detail |
|---|
public Object clone()
clone in class ObjectObject.clone()public Schema lockSchema()
public boolean isLocked()
public void addField(String name,
Class<?> type)
name - the field nametype - the field type (as a Class instance)
IllegalArgumentException - if either name or type are null or the name already exists in
this schema.
public void addField(String name,
Class<?> type,
Object defaultValue)
name - the field nametype - the field type (as a Class instance)
IllegalArgumentException - if either name or type are null or the name already exists in
this schema.public int getFieldCount()
public String getFieldName(int index)
index - the field index
public int getFieldIndex(String field)
field - the field name
public Class<?> getFieldType(int index)
index - the column index
public Class<?> getFieldType(String field)
field - the field name
public Object getDefault(int index)
index - the field index
public Object getDefault(String field)
field - the field name
public void setDefault(int index,
Object val)
index - the index position of the field to set the default forval - the new default value
public void setDefault(String field,
Object val)
field - the name of field to set the default forval - the new default value
public void setDefault(String field,
int val)
int.
field - the name of field to set the default forval - the new default value
public void setDefault(String field,
long val)
long.
field - the name of field to set the default forval - the new default value
public void setDefault(String field,
float val)
float.
field - the name of field to set the default forval - the new default value
public void setDefault(String field,
double val)
double.
field - the name of field to set the default forval - the new default value
public void setDefault(String field,
boolean val)
boolean.
field - the name of field to set the default forval - the new default valuepublic boolean equals(Object o)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Objectpublic Tuple instantiate()
public Tuple instantiate(Object... objects)
objects - values of each field
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||