public class Document
extends java.lang.Object
implements java.io.Serializable
Document document = Document.newBuilder().setId("document id") .setLocale(Locale.UK) .addField(Field.newBuilder() .setName("subject") .setText("going for dinner")) .addField(Field.newBuilder() .setName("body") .setHTML("<html>I found a restaurant.</html>")) .addField(Field.newBuilder() .setName("signature") .setText("ten post jest przeznaczony dla odbiorcy") .setLocale(new Locale("pl"))) .addField(Field.newBuilder() .setName("tag") .setText("food")) .addField(Field.newBuilder() .setName("tag") .setText("friend")) .build();The following example shows how to access the fields within a document:
Document document = ... for (Field field : document.getFields()) { switch (field.getType()) { case TEXT: use(field.getText()); break; case HTML: use(field.getHtml()); break; case ATOM: use(field.getAtom()); break; case DATE: use(field.getDate()); break; } }
Modifier and Type | Class and Description |
---|---|
static class
|
Document.Builder
A builder of documents.
|
Modifier and Type | Method and Description |
---|---|
boolean
|
equals
(java.lang.Object object)
|
int
|
getFieldCount
(java.lang.String name)
Returns the number of times a field with the given name is present
in this document.
|
java.util.Set<java.lang.String>
|
getFieldNames
()
|
java.lang.Iterable<
Field
>
|
getFields
()
|
java.lang.Iterable<
Field
>
|
getFields
(java.lang.String name)
Get an iterable of all fields with the given name.
|
java.lang.String
|
getId
()
|
java.util.Locale
|
getLocale
()
|
Field
|
getOnlyField
(java.lang.String name)
Returns the single field with the given name.
|
int
|
getRank
()
Returns the rank of this document.
|
int
|
hashCode
()
|
static
Document.Builder
|
newBuilder
()
Creates a new document builder.
|
java.lang.String
|
toString
()
|
public java.lang.Iterable<Field> getFields()
Field
in the document
public java.util.Set<java.lang.String> getFieldNames()
Set
of the field names in the document
public java.lang.Iterable<Field> getFields(java.lang.String name)
name
- the name of the field name whose values are to be returned
Iterable
of
Field
with the given name
or
null
public Field getOnlyField(java.lang.String name)
name
- the name of the field to return
java.lang.IllegalArgumentException
- if the document does not have exactly
one field with the name
public int getFieldCount(java.lang.String name)
name
- the name of the field to be counted
public java.lang.String getId()
public java.util.Locale getLocale()
Locale
the document is written in. Can be null
public int getRank()
public int hashCode()
hashCode
in class
java.lang.Object
public boolean equals(java.lang.Object object)
equals
in class
java.lang.Object
public static Document.Builder newBuilder()
Document.Builder.build()
method on the returned builder.
public java.lang.String toString()
toString
in class
java.lang.Object