gov.sandia.cognition.text.document
Class AbstractDocument

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.util.AbstractNamed
          extended by gov.sandia.cognition.text.document.AbstractDocument
All Implemented Interfaces:
Document, CloneableSerializable, Named, Serializable, Cloneable
Direct Known Subclasses:
DefaultDocument

public class AbstractDocument
extends AbstractNamed
implements Document

An abstract implementation of the Document interface. It holds the reference plus the fields as a mapping of field names to values.

Since:
3.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
static String ACCESSED_DATE_FIELD_NAME
          The name of the last accessed date field is "accessedDate".
static String AUTHOR_FIELD_NAME
          The name of the author field is "author".
static String BODY_FIELD_NAME
          The name of the body field is "body".
protected  HashMap<String,Field> fieldMap
          A mapping of field names to fields.
static String LAST_MODIFIED_DATE_FIELD_NAME
          The name of the last modified date field is "lastModifiedDate".
protected  DocumentReference reference
          A reference to where the document came from.
static String TITLE_FIELD_NAME
          The name of the title field is "title".
 
Fields inherited from class gov.sandia.cognition.util.AbstractNamed
name
 
Constructor Summary
AbstractDocument()
          Creates a new AbstractDocument.
 
Method Summary
protected  void addField(Field field)
          Adds a field to the document.
 Field getAccessedDateField()
          Gets the commonly-used accessed date field.
 Field getAuthorField()
          Gets the commonly-used author field.
 Field getBodyField()
          Gets the commonly-used body field.
 Field getField(String fieldName)
          Gets the field from the document with the given field name, if it exists.
protected  HashMap<String,Field> getFieldMap()
          Gets the mapping of field name to the field.
 Collection<Field> getFields()
          Gets the collection of the fields that make up the document.
 Field getLastModifiedDateField()
          Gets the commonly-used last modified date field.
 DocumentReference getReference()
          Gets a reference to the location of the document so that it can be retrieved again later.
 URI getReferenceURI()
          Gets the reference to the location of the document as a URI.
 Field getTitleField()
          Gets the commonly-used title field.
 boolean hasField(String fieldName)
          Determines if this document has a field of the given name.
protected  void removeField(String fieldName)
          Removes a field of the given name from the document.
protected  void setFieldMap(HashMap<String,Field> fieldMap)
          Sets the mapping of field name to the field.
protected  void setReference(DocumentReference reference)
          Sets the reference to where the document can be found.
 
Methods inherited from class gov.sandia.cognition.util.AbstractNamed
clone, getName, setName, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.util.Named
getName
 

Field Detail

TITLE_FIELD_NAME

public static final String TITLE_FIELD_NAME
The name of the title field is "title".

See Also:
Constant Field Values

LAST_MODIFIED_DATE_FIELD_NAME

public static final String LAST_MODIFIED_DATE_FIELD_NAME
The name of the last modified date field is "lastModifiedDate".

See Also:
Constant Field Values

ACCESSED_DATE_FIELD_NAME

public static final String ACCESSED_DATE_FIELD_NAME
The name of the last accessed date field is "accessedDate".

See Also:
Constant Field Values

AUTHOR_FIELD_NAME

public static final String AUTHOR_FIELD_NAME
The name of the author field is "author".

See Also:
Constant Field Values

BODY_FIELD_NAME

public static final String BODY_FIELD_NAME
The name of the body field is "body".

See Also:
Constant Field Values

reference

protected DocumentReference reference
A reference to where the document came from.


fieldMap

protected HashMap<String,Field> fieldMap
A mapping of field names to fields.

Constructor Detail

AbstractDocument

public AbstractDocument()
Creates a new AbstractDocument.

Method Detail

addField

protected void addField(Field field)
Adds a field to the document. If there is already a field with the same name, that field is replaced.

Parameters:
field - The field to add.

removeField

protected void removeField(String fieldName)
Removes a field of the given name from the document.

Parameters:
fieldName - The name of the field to remove.

hasField

public boolean hasField(String fieldName)
Description copied from interface: Document
Determines if this document has a field of the given name.

Specified by:
hasField in interface Document
Parameters:
fieldName - The name of the field.
Returns:
True if the document has a field of the given name; otherwise, false.

getField

public Field getField(String fieldName)
Description copied from interface: Document
Gets the field from the document with the given field name, if it exists. If not, null is returned.

Specified by:
getField in interface Document
Parameters:
fieldName - The name of the field.
Returns:
The field with the given name if it exists; otherwise, null.

getReference

public DocumentReference getReference()
Description copied from interface: Document
Gets a reference to the location of the document so that it can be retrieved again later. It should be unique and reproducible since it is used to identify this document.

Specified by:
getReference in interface Document
Returns:
The reference to the document.

setReference

protected void setReference(DocumentReference reference)
Sets the reference to where the document can be found.

Parameters:
reference - The reference to where the document can be found.

getReferenceURI

public URI getReferenceURI()
Description copied from interface: Document
Gets the reference to the location of the document as a URI.

Specified by:
getReferenceURI in interface Document
Returns:
The document reference as a URI.

getFields

public Collection<Field> getFields()
Description copied from interface: Document
Gets the collection of the fields that make up the document.

Specified by:
getFields in interface Document
Returns:
The collection of fields that make up the document.

getTitleField

public Field getTitleField()
Description copied from interface: Document
Gets the commonly-used title field.

Specified by:
getTitleField in interface Document
Returns:
The title field, if it exists; otherwise, null.

getLastModifiedDateField

public Field getLastModifiedDateField()
Description copied from interface: Document
Gets the commonly-used last modified date field.

Specified by:
getLastModifiedDateField in interface Document
Returns:
The last modified date field, if it exists; otherwise, null.

getAccessedDateField

public Field getAccessedDateField()
Description copied from interface: Document
Gets the commonly-used accessed date field.

Specified by:
getAccessedDateField in interface Document
Returns:
The accessed date field, if it exists; otherwise, null.

getAuthorField

public Field getAuthorField()
Description copied from interface: Document
Gets the commonly-used author field.

Specified by:
getAuthorField in interface Document
Returns:
The author field, if it exists; otherwise, null.

getBodyField

public Field getBodyField()
Description copied from interface: Document
Gets the commonly-used body field. Implementations of the Document interface are highly encouraged to use this field to represent the primary content of the document.

Specified by:
getBodyField in interface Document
Returns:
The body field, if it exists; otherwise, null.

getFieldMap

protected HashMap<String,Field> getFieldMap()
Gets the mapping of field name to the field.

Returns:
The mapping of field name to field.

setFieldMap

protected void setFieldMap(HashMap<String,Field> fieldMap)
Sets the mapping of field name to the field.

Parameters:
fieldMap - The mapping of field name to field.