public class DbxFields
extends java.lang.Object
DbxFields
methods can be used to
change the record, and any changes to the record will be seen immediately.
A temporary DbxFields
created by one of the constructors in this class
is saved only in memory, but can be used to set fields in a record.
Fields are identified by name, and have a value of one of the types defined
by DbxFields.ValueType
. Fields can never have a null
value.
Fields can be retrieved by name and type. Illegal field access will be
signaled by an exception: DbxFields.FieldNotFound
, DbxFields.IllegalFieldName
,
or DbxFields.WrongValueType
.
Modifier and Type | Class and Description |
---|---|
static class |
DbxFields.AtomType
The atomic value types: those which can be included in lists.
|
static class |
DbxFields.FieldNotFound
Thrown when attempting to get the value of a field that isn't present.
|
static class |
DbxFields.IllegalFieldName
Thrown when an illegal field name is given.
|
static class |
DbxFields.ValueType
The possible types of datastore field values, as stored on the server.
|
static class |
DbxFields.WrongValueType
Thrown when attempting to get a field that isn't of the specified type.
|
Constructor and Description |
---|
DbxFields()
Creates a new temporary set of fields held in memory, without being included in a record.
|
DbxFields(DbxFields fields)
Creates a new temporary set of fields held in memory, without being included in a record.
|
Modifier and Type | Method and Description |
---|---|
DbxFields |
deleteField(java.lang.String name)
Removes the field with the given name.
|
boolean |
equals(java.lang.Object o) |
java.util.Set |
fieldNames()
Returns a set containing the names of all of the fields that are set.
|
boolean |
getBoolean(java.lang.String name)
Returns the value of a
boolean field with the given name, which must
exist and be of the correct type. |
byte[] |
getBytes(java.lang.String name)
Returns the value of a byte field of the given name, which must
exist and be of the correct type.
|
java.util.Date |
getDate(java.lang.String name)
Returns the value of a
Date field of the given name, which must
exist and be of the correct type. |
double |
getDouble(java.lang.String name)
Returns the value of a
double field of the given name, which must
exist and be of a numerical type. |
DbxFields.ValueType |
getFieldType(java.lang.String name)
Returns the type of value in the field with the given name, or
null
if the field isn't set. |
DbxList |
getList(java.lang.String name)
Returns a
DbxList object for reading and writing the contents of a
List field of the given name. |
long |
getLong(java.lang.String name)
Returns the value of a
long field of the given name, which must
exist and be of the correct type. |
DbxList |
getOrCreateList(java.lang.String name)
Returns a
DbxList object for reading and writing the contents of a
List field of the given name. |
java.lang.String |
getString(java.lang.String name)
Returns the value of a
String field of the given name, which must
exist and be of the correct type. |
boolean |
hasField(java.lang.String name)
Returns whether a field with the given name is set.
|
int |
hashCode() |
static boolean |
isValidFieldName(java.lang.String name)
Returns true if
id is a valid name for a field in a DbxRecord . |
DbxFields |
set(java.lang.String name,
boolean value)
Sets a field with the given name to the given
boolean value,
replacing any prior value. |
DbxFields |
set(java.lang.String name,
byte[] value)
Sets a field with the given name to the given byte value
replacing any prior value.
|
DbxFields |
set(java.lang.String name,
java.util.Date value)
Sets a field with the given name to the given
Date value,
replacing any prior value. |
DbxFields |
set(java.lang.String name,
DbxList value)
Sets a field with the given name to List value with a copy of
the contents of the given
DbxList , replacing any prior value. |
DbxFields |
set(java.lang.String name,
double value)
Sets a field with the given name to the given
double value,
replacing any prior value. |
DbxFields |
set(java.lang.String name,
long value)
Sets a field with the given name to the given
long value,
replacing any prior value. |
DbxFields |
set(java.lang.String name,
java.lang.String value)
Sets a field with the given name to the given
String value,
replacing any prior value. |
DbxFields |
setAll(DbxFields fields)
Copies all of the fields from the given object to this object,
replacing any prior values.
|
java.lang.String |
toString() |
public DbxFields()
public DbxFields(DbxFields fields)
public boolean hasField(java.lang.String name)
public DbxFields.ValueType getFieldType(java.lang.String name)
null
if the field isn't set.public boolean getBoolean(java.lang.String name)
boolean
field with the given name, which must
exist and be of the correct type.public long getLong(java.lang.String name)
long
field of the given name, which must
exist and be of the correct type. This method won't convert a
double
or boolean
field to a double.public double getDouble(java.lang.String name)
double
field of the given name, which must
exist and be of a numerical type. If the field value is a long
,
this method will silently convert it to a double
. No conversion
is performed on other field types.public java.lang.String getString(java.lang.String name)
String
field of the given name, which must
exist and be of the correct type.public byte[] getBytes(java.lang.String name)
public java.util.Date getDate(java.lang.String name)
Date
field of the given name, which must
exist and be of the correct type.public DbxList getList(java.lang.String name)
public DbxList getOrCreateList(java.lang.String name)
public DbxFields set(java.lang.String name, boolean value)
boolean
value,
replacing any prior value.
Returns a reference to this object, to allow for call chaining.
public DbxFields set(java.lang.String name, long value)
long
value,
replacing any prior value.
Returns a reference to this object, to allow for call chaining.
public DbxFields set(java.lang.String name, double value)
double
value,
replacing any prior value.
Returns a reference to this object, to allow for call chaining.
public DbxFields set(java.lang.String name, java.lang.String value)
String
value,
replacing any prior value. The value must not be null
.
Returns a reference to this object, to allow for call chaining.
public DbxFields set(java.lang.String name, byte[] value)
null
.
Returns a reference to this object, to allow for call chaining.
public DbxFields set(java.lang.String name, java.util.Date value)
Date
value,
replacing any prior value. The value must not be null
.
Returns a reference to this object, to allow for call chaining.
public DbxFields set(java.lang.String name, DbxList value)
DbxList
, replacing any prior value.
The value must not be null
.
Setting a list in this way won't allow automatic conflict
resolution on items within the list. If you need that, you
should modify lists using a DbxList
obtained from DbxFields.getList(java.lang.String)
or DbxFields.getOrCreateList(java.lang.String)
.
Returns a reference to this object, to allow for call chaining.
public DbxFields setAll(DbxFields fields)
Returns a reference to this object, to allow for call chaining.
public DbxFields deleteField(java.lang.String name)
Returns a reference to this object, to allow for call chaining.
public java.util.Set fieldNames()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static boolean isValidFieldName(java.lang.String name)
id
is a valid name for a field in a DbxRecord
.
Field names are case-sensitive, can be 1-32 characters long and may contain
alphanumeric characters plus these punctuation characters: . - _ + / =
Field names with a leading colon (:) are also valid, but reserved for internal use.