|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.bluetooth.DataElement
public class DataElement
The DataElement class defines the various data
types that a Bluetooth service attribute value may have.
The following table describes the data types and valid
values that a DataElement object can store.
| Data Type | Valid Values |
|---|---|
NULL | represents a
null value
|
U_INT_1 |
long value range [0, 255] |
U_INT_2 | long
value range [0, 216-1] |
U_INT_4 |
long value range [0, 232-1] |
U_INT_8 |
byte[] value range [0, 264-1] |
U_INT_16 |
byte[] value range [0, 2128-1] |
INT_1 | long
value range [-128, 127] |
INT_2 | long
value range [-215, 215-1] |
INT_4 | long
value range [-231, 231-1] |
INT_8 | long
value range [-263, 263-1] |
INT_16 | byte[]
value range [-2127, 2127-1] |
URL |
java.lang.String |
UUID |
javax.bluetooth.UUID |
BOOL | boolean |
STRING |
java.lang.String |
DATSEQ |
java.util.Enumeration |
DATALT |
java.util.Enumeration |
| Field Summary | ||
|---|---|---|
static int |
BOOL
Defines data of type BOOL. |
|
static int |
DATALT
Defines data of type DATALT. |
|
static int |
DATSEQ
Defines data of type DATSEQ. |
|
static int |
INT_1
Defines a signed integer of size one byte. |
|
static int |
INT_16
Defines a signed integer of size sixteen bytes. |
|
static int |
INT_2
Defines a signed integer of size two bytes. |
|
static int |
INT_4
Defines a signed integer of size four bytes. |
|
static int |
INT_8
Defines a signed integer of size eight bytes. |
|
static int |
NULL
Defines data of type NULL. |
|
static int |
STRING
Defines data of type STRING. |
|
static int |
URL
Defines data of type URL. |
|
static int |
UUID
Defines data of type UUID. |
|
static int |
U_INT_1
Defines an unsigned integer of size one byte. |
|
static int |
U_INT_16
Defines an unsigned integer of size sixteen bytes. |
|
static int |
U_INT_2
Defines an unsigned integer of size two bytes. |
|
static int |
U_INT_4
Defines an unsigned integer of size four bytes. |
|
static int |
U_INT_8
Defines an unsigned integer of size eight bytes. |
|
| Constructor Summary | ||
|---|---|---|
DataElement(boolean bool)
Creates a DataElement whose data type is
BOOL and whose value is equal to bool |
||
DataElement(int valueType)
Creates a DataElement of type NULL,
DATALT, or DATSEQ. |
||
DataElement(int valueType,
Object value)
Creates a DataElement whose data type is given by
valueType and whose value is specified by the argument
value. |
||
DataElement(int valueType,
long value)
Creates a DataElement that encapsulates an integer
value of size U_INT_1, U_INT_2,
U_INT_4, INT_1, INT_2,
INT_4, and INT_8. |
||
| Method Summary | ||
|---|---|---|
void |
addElement(DataElement elem)
Adds a DataElement to this DATALT
or DATSEQ DataElement object. |
|
boolean |
getBoolean()
Returns the value of the DataElement if it is represented as
a boolean. |
|
int |
getDataType()
Returns the data type of the object this DataElement
represents. |
|
long |
getLong()
Returns the value of the DataElement if it can be
represented as a long. |
|
int |
getSize()
Returns the number of DataElements that are present
in this DATALT or DATSEQ object. |
|
Object |
getValue()
Returns the value of this DataElement as an
Object. |
|
void |
insertElementAt(DataElement elem,
int index)
Inserts a DataElement at the specified location. |
|
boolean |
removeElement(DataElement elem)
Removes the first occurrence of the DataElement
from this object. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int NULL
DataElement.NULL is
implicit, i.e., there is no representation of it.
Accordingly there is no method to retrieve
it, and attempts to retrieve the value will throw an exception.
The value of NULL is 0x00 (0).
public static final int U_INT_1
The value of the constant U_INT_1
is 0x08 (8).
public static final int U_INT_2
The value of the constant U_INT_2 is 0x09 (9).
public static final int U_INT_4
The value of the constant U_INT_4 is 0x0A (10).
public static final int U_INT_8
The value of the constant U_INT_8 is 0x0B (11).
public static final int U_INT_16
The value of the constant U_INT_16 is 0x0C (12).
public static final int INT_1
The value of the constant INT_1 is 0x10 (16).
public static final int INT_2
The value of the constant INT_2 is 0x11 (17).
public static final int INT_4
The value of the constant INT_4 is 0x12 (18).
public static final int INT_8
The value of the constant INT_8 is 0x13 (19).
public static final int INT_16
The value of the constant INT_16 is 0x14 (20).
public static final int URL
The value of the constant URL is 0x40 (64).
public static final int UUID
The value of the constant UUID is 0x18 (24).
public static final int BOOL
The value of the constant BOOL is 0x28 (40).
public static final int STRING
The value of the constant STRING is 0x20 (32).
public static final int DATSEQ
The value of the constant DATSEQ is 0x30 (48).
public static final int DATALT
The value of the constant DATALT is 0x38 (56).
| Constructor Detail |
|---|
public DataElement(int valueType)
DataElement of type NULL,
DATALT, or DATSEQ.
valueType - the type of DataElement to create:
NULL, DATALT, or DATSEQ
IllegalArgumentException - if valueType
is not NULL, DATALT, or
DATSEQDataElement.NULL,
DataElement.DATALT,
DataElement.DATSEQpublic DataElement(boolean bool)
DataElement whose data type is
BOOL and whose value is equal to bool
bool - the value of the DataElement of type
BOOL.DataElement.BOOL
public DataElement(int valueType,
long value)
DataElement that encapsulates an integer
value of size U_INT_1, U_INT_2,
U_INT_4, INT_1, INT_2,
INT_4, and INT_8.
The legal values for the valueType and the corresponding
attribute values are:
| Value Type | Value Range |
|---|---|
U_INT_1 |
[0, 28-1] |
U_INT_2 |
[0, 216-1] |
U_INT_4 |
[0, 232-1] |
INT_1 |
[-27, 27-1] |
INT_2 |
[-215, 215-1] |
INT_4 |
[-231, 231-1] |
INT_8 |
[-263, 263-1] |
IllegalArgumentException to be thrown.
valueType - the data type of the object that is being
created; must be one of the following:
U_INT_1,
U_INT_2,
U_INT_4,
INT_1,
INT_2,
INT_4, or
INT_8value - the value of the object being created; must be
in the range specified for the given valueType
IllegalArgumentException - if the valueType
is not valid or the value for the given legal
valueType is outside the valid rangeDataElement.U_INT_1,
DataElement.U_INT_2,
DataElement.U_INT_4,
DataElement.INT_1,
DataElement.INT_2,
DataElement.INT_4,
DataElement.INT_8
public DataElement(int valueType,
Object value)
DataElement whose data type is given by
valueType and whose value is specified by the argument
value. The legal values for the valueType
and the corresponding attribute values are:
| Value Type | Java Type / Value Range |
|---|---|
URL | java.lang.String
|
UUID |
javax.bluetooth.UUID |
STRING |
java.lang.String |
INT_16 |
[-2127, 2127-1] as a byte array whose length must be 16 |
U_INT_8 |
[0, 264-1] as a byte array whose length must be 8 |
U_INT_16 |
[0, 2128-1] as a byte array whose length must be 16 |
IllegalArgumentException exception.
valueType - the data type of the object that is being
created; must be one of the following: URL,
UUID,
STRING,
INT_16,
U_INT_8, or
U_INT_16value - the value for the DataElement being created
of type valueType
IllegalArgumentException - if the value
is not of the valueType type or is not in the range
specified or is nullDataElement.URL,
DataElement.UUID,
DataElement.STRING,
DataElement.U_INT_8,
DataElement.INT_16,
DataElement.U_INT_16| Method Detail |
|---|
public void addElement(DataElement elem)
DataElement to this DATALT
or DATSEQ DataElement object.
The elem will be added at the end of the list.
The elem can be of any
DataElement type, i.e., URL,
NULL, BOOL, UUID,
STRING, DATSEQ, DATALT,
and the various signed and unsigned integer types.
The same object may be added twice. If the object is
successfully added the size of the DataElement is
increased by one.
elem - the DataElement object to add
ClassCastException - if the method is invoked on a
DataElement whose type is not DATALT
or DATSEQ
NullPointerException - if elem is
null
public void insertElementAt(DataElement elem,
int index)
DataElement at the specified location.
This method can be invoked only on a DATALT or
DATSEQ DataElement.
elem can be of any DataElement
type, i.e., URL, NULL,
BOOL,
UUID, STRING, DATSEQ,
DATALT, and the various signed and unsigned
integers. The same object may be added twice. If the object is
successfully added the size will be increased by one.
Each element with an index greater than or equal to the specified
index is shifted upward to have an index one
greater than the value it had previously.
The index must be greater than or equal to 0 and
less than or equal to the current size. Therefore,
DATALT and
DATSEQ are zero-based objects.
elem - the DataElement object to addindex - the location at which to add the
DataElement
ClassCastException - if the method is invoked on an
instance of DataElement whose type is not
DATALT or DATSEQ
IndexOutOfBoundsException - if index
is negative or greater than
the size of the DATALT or DATSEQ
NullPointerException - if elem is
nullpublic int getSize()
DataElements that are present
in this DATALT or DATSEQ object.
It is possible that the number of elements is equal to zero.
DATALT
or DATSEQ
ClassCastException - if this object is not of type
DATALT or DATSEQpublic boolean removeElement(DataElement elem)
DataElement
from this object. elem may be of any type, i.e.,
URL, NULL, BOOL,
UUID, STRING, DATSEQ,
DATALT, or the variously sized signed and unsigned
integers.
Only the first object in the list that is equal to
elem will be removed. Other objects, if present,
are not removed. Since this class doesn’t override the
equals() method of the Object class,
the remove method compares only the
references of objects. If elem is
successfully removed the size of this DataElement
is decreased by one. Each DataElement in the
DATALT or DATSEQ with an index greater
than the index of elem is shifted downward to have
an index one smaller than the value it had previously.
elem - the DataElement to be removed
true if the input value was found and
removed; else false
ClassCastException - if this object is not of
type DATALT or DATSEQ
NullPointerException - if elem is
nullpublic int getDataType()
DataElement
represents.
DataElement object; the legal
return values are:
URL,
NULL,
BOOL,
UUID,
STRING,
DATSEQ,
DATALT,
U_INT_1,
U_INT_2,
U_INT_4,
U_INT_8,
U_INT_16,
INT_1,
INT_2,
INT_4,
INT_8, or
INT_16- Since:
- BlackBerry API 4.2.1
public long getLong()
DataElement if it can be
represented as a long. The data type of the object must be
U_INT_1,
U_INT_2,
U_INT_4,
INT_1,
INT_2,
INT_4, or
INT_8.
DataElement as a long
ClassCastException - if the data type of the object is not
U_INT_1,
U_INT_2,
U_INT_4, INT_1,
INT_2, INT_4,
or INT_8public boolean getBoolean()
DataElement if it is represented as
a boolean.
boolean value of this DataElement
object
ClassCastException - if the data type of this object is
not of type BOOLpublic Object getValue()
DataElement as an
Object. This method returns the appropriate Java
object for the following data types:
URL,
UUID,
STRING,
DATSEQ,
DATALT,
U_INT_8,
U_INT_16, and
INT_16.
Modifying the returned Object will not change this
DataElement.
The following are the legal pairs of data type
and Java object type being returned.
DataElement Data Type |
Java Data Type |
|---|---|
URL | java.lang.String
|
UUID |
javax.bluetooth.UUID |
STRING | java.lang.String
|
DATSEQ |
java.util.Enumeration |
DATALT |
java.util.Enumeration |
U_INT_8 |
byte[] of length 8 |
U_INT_16 |
byte[] of length 16 |
INT_16 |
byte[] of length 16 |
ClassCastException - if the object is not a
URL, UUID,
STRING, DATSEQ, DATALT,
U_INT_8,
U_INT_16,
or INT_16
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal