java.lang.Object |
↳ |
com.google.firebase.database.MutableData |
Class Overview
Instances of this class encapsulate the data and priority at a location. It is used in
transactions, and it is intended to be inspected and then updated to the desired data at that
location.
Note that changes made to a child MutableData instance will be visible to the parent and vice
versa.
Summary
Public Methods |
MutableData
|
child(String path)
Used to obtain a MutableData instance that encapsulates the data and priority at the given
relative path.
|
boolean
|
equals(Object o)
|
Iterable<MutableData>
|
getChildren()
Used to iterate over the immediate children at this location
for (MutableData child : parent.getChildren()) {
...
|
long
|
getChildrenCount()
|
String
|
getKey()
|
Object
|
getPriority()
Gets the current priority at this location.
|
<T>
T
|
getValue(GenericTypeIndicator<T> t)
Due to the way that Java implements generics, it takes an extra step to get back a
properly-typed Collection.
|
Object
|
getValue()
getValue() returns the data contained in this instance as native types.
|
<T>
T
|
getValue(Class<T> valueType)
This method is used to marshall the data contained in this instance into a class of your
choosing.
|
boolean
|
hasChild(String path)
|
boolean
|
hasChildren()
|
void
|
setPriority(Object priority)
Sets the priority at this location
|
void
|
setValue(Object value)
Set the data at this location to the given value.
|
String
|
toString()
|
[Expand]
Inherited Methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public Methods
public
MutableData
child
(String path)
Used to obtain a MutableData instance that encapsulates the data and priority at the given
relative path.
Parameters |
path |
String :
A relative path |
Returns |
MutableData |
An instance encapsulating the data and priority at the given path
|
public
boolean
equals
(Object o)
public
Iterable<MutableData>
getChildren
()
Used to iterate over the immediate children at this location
for (MutableData child : parent.getChildren()) {
...
}
Returns |
Iterable<MutableData> |
The immediate children at this location
|
public
long
getChildrenCount
()
Returns |
long |
The number of immediate children at this location |
public
String
getKey
()
Returns |
String |
The key name of this location, or null if it is the top-most location |
public
Object
getPriority
()
Gets the current priority at this location. The possible return types are:
Note that null is allowed
Returns |
Object |
The priority at this location as a native type
|
Due to the way that Java implements generics, it takes an extra step to get back a
properly-typed Collection. So, in the case where you want a List
of Message
instances, you will need to do something like the following:
GenericTypeIndicator<List<Message>> t =
new GenericTypeIndicator<List<Message>>() {};
List<Message> messages = mutableData.getValue(t);
It is important to use a subclass of
GenericTypeIndicator
. See
GenericTypeIndicator
for more details
Parameters |
t |
GenericTypeIndicator :
A subclass of GenericTypeIndicator indicating the type of generic collection
to be returned. |
Returns |
T |
A properly typed collection, populated with the data from this instance, or null if
there is no data at this location.
|
public
Object
getValue
()
getValue() returns the data contained in this instance as native types. The possible types
returned are:
- Boolean
- String
- Long
- Double
- Map<String, Object>
- List<Object>
This list is recursive; the possible types for
Object
in the above list is
given by the same list. These types correspond to the types available in JSON.
Returns |
Object |
The data contained in this instance as native types, or null if there is no data at
this location.
|
public
T
getValue
(Class<T> valueType)
This method is used to marshall the data contained in this instance into a class of your
choosing. The class must fit 2 simple constraints:
- The class must have a default constructor that takes no arguments
- The class must define public getters for the properties to be assigned. Properties
without a public getter will be set to their default value when an instance is
deserialized
An example class might look like:
class Message {
private String author;
private String text;
private Message() {}
public Message(String author, String text) {
this.author = author;
this.text = text;
}
public String getAuthor() {
return author;
}
public String getText() {
return text;
}
}
// Later
Message m = mutableData.getValue(Message.class);
Parameters |
valueType |
Class :
The class into which this data in this instance should be marshalled |
Returns |
T |
An instance of the class passed in, populated with the data from this instance, or null
if there is no data at this location.
|
public
boolean
hasChild
(String path)
Parameters |
path |
String :
A relative path |
Returns |
boolean |
True if data exists at the given path, otherwise false
|
public
boolean
hasChildren
()
Returns |
boolean |
True if the data at this location has children, false otherwise |
public
void
setPriority
(Object priority)
Sets the priority at this location
Parameters |
priority |
Object :
The desired priority
|
public
void
setValue
(Object value)
Set the data at this location to the given value. The native types accepted by this method for
the value correspond to the JSON types:
- Boolean
- Long
- Double
- Map<String, Object>
- List<Object>
In addition, you can set instances of your own class into this location, provided they satisfy
the following constraints:
- The class must have a default constructor that takes no arguments
- The class must define public getters for the properties to be assigned. Properties
without a public getter will be set to their default value when an instance is
deserialized
Generic collections of objects that satisfy the above constraints are also permitted, i.e.
Map<String, MyPOJO>
, as well as null values.
Note that this overrides the priority, which must be set separately.
Parameters |
value |
Object :
The value to set at this location
|
public
String
toString
()