java.lang.Object
com.getpebble.android.kit.util.PebbleDictionary
- All Implemented Interfaces:
Iterable<PebbleTuple>
A collection of key-value pairs of heterogeneous types. PebbleDictionaries are the primary structure used to exchange
data between the phone and watch.
To accommodate the mixed-types contained within a PebbleDictionary, an internal JSON representation is used when
exchanging the dictionary between Android processes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBytes
(int key, byte[] bytes) Associate the specified byte array with the provided key in the dictionary.void
addInt16
(int key, short s) Associate the specified signed short with the provided key in the dictionary.void
addInt32
(int key, int i) Associate the specified signed int with the provided key in the dictionary.void
addInt8
(int key, byte b) Associate the specified signed byte with the provided key in the dictionary.void
Associate the specified String with the provided key in the dictionary.protected void
addTuple
(PebbleTuple tuple) void
addUint16
(int key, short s) Associate the specified unsigned short with the provided key in the dictionary.void
addUint32
(int key, int i) Associate the specified unsigned int with the provided key in the dictionary.void
addUint8
(int key, byte b) Associate the specified unsigned byte with the provided key in the dictionary.boolean
contains
(int key) Returns true if this dictionary contains a mapping for the specified key.static PebbleDictionary
Deserializes a JSON representation of a PebbleDictionary.byte[]
getBytes
(int key) Returns the byte array to which the specified key is mapped, or null if the key does not exist in this dictionary.getInteger
(int key) Returns the signed integer to which the specified key is mapped, or null if the key does not exist in this dictionary.getString
(int key) Returns the string to which the specified key is mapped, or null if the key does not exist in this dictionary.getUnsignedIntegerAsLong
(int key) Returns the unsigned integer as a long to which the specified key is mapped, or null if the key does not exist in this dictionary.iterator()
void
remove
(int key) Removes the mapping for a key from this map if it is present.int
size()
Returns the number of key-value pairs in this dictionary.Returns a JSON representation of this dictionary.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
tuples
-
-
Constructor Details
-
PebbleDictionary
public PebbleDictionary()
-
-
Method Details
-
iterator
- Specified by:
-
iterator
in interfaceIterable<PebbleTuple>
-
size
public int size()Returns the number of key-value pairs in this dictionary.- Returns:
- the number of key-value pairs in this dictionary
-
contains
public boolean contains(int key) Returns true if this dictionary contains a mapping for the specified key.- Parameters:
-
key
- key whose presence in this dictionary is to be tested - Returns:
- true if this dictionary contains a mapping for the specified key
-
remove
public void remove(int key) Removes the mapping for a key from this map if it is present.- Parameters:
-
key
- key to be removed from the dictionary
-
addBytes
public void addBytes(int key, byte[] bytes) Associate the specified byte array with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
bytes
- value to be associated with the specified key
-
addString
Associate the specified String with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
value
- value to be associated with the specified key
-
addInt8
public void addInt8(int key, byte b) Associate the specified signed byte with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
b
- value to be associated with the specified key
-
addUint8
public void addUint8(int key, byte b) Associate the specified unsigned byte with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
b
- value to be associated with the specified key
-
addInt16
public void addInt16(int key, short s) Associate the specified signed short with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
s
- value to be associated with the specified key
-
addUint16
public void addUint16(int key, short s) Associate the specified unsigned short with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
s
- value to be associated with the specified key
-
addInt32
public void addInt32(int key, int i) Associate the specified signed int with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
i
- value to be associated with the specified key
-
addUint32
public void addUint32(int key, int i) Associate the specified unsigned int with the provided key in the dictionary. If another key-value pair with the same key is already present in the dictionary, it will be replaced.- Parameters:
-
key
- key with which the specified value is associated -
i
- value to be associated with the specified key
-
getInteger
Returns the signed integer to which the specified key is mapped, or null if the key does not exist in this dictionary.- Parameters:
-
key
- key whose associated value is to be returned - Returns:
- value to which the specified key is mapped
-
getUnsignedIntegerAsLong
Returns the unsigned integer as a long to which the specified key is mapped, or null if the key does not exist in this dictionary. We are using the Long type here so that we can remove the guava dependency. This is done so that we dont have incompatibility issues with the UnsignedInteger class from the Holo application, which uses a newer version of Guava.- Parameters:
-
key
- key whose associated value is to be returned - Returns:
- value to which the specified key is mapped
-
getBytes
public byte[] getBytes(int key) Returns the byte array to which the specified key is mapped, or null if the key does not exist in this dictionary.- Parameters:
-
key
- key whose associated value is to be returned - Returns:
- value to which the specified key is mapped
-
getString
Returns the string to which the specified key is mapped, or null if the key does not exist in this dictionary.- Parameters:
-
key
- key whose associated value is to be returned - Returns:
- value to which the specified key is mapped
-
addTuple
-
toJsonString
Returns a JSON representation of this dictionary.- Returns:
- a JSON representation of this dictionary
-
fromJson
Deserializes a JSON representation of a PebbleDictionary.- Parameters:
-
jsonString
- the JSON representation to be deserialized - Throws:
-
org.json.JSONException
- thrown if the specified JSON representation cannot be parsed
-