Java Reference
In-Depth Information
int category = arrayToInt(candidate,4);
if(code == product.getCode() && category == product.getCategory()) {
return true;
} return false;
} private int arrayToInt(byte[] b, int offset)
{
int value = 0;
for (int i = 0; i < 4; i++) {
int shift = (4 - 1 - i) * 8;
value += (b[i + offset] & 0x000000FF) << shift;
} return value;
}
}
The filtering logic has been changed to do the same thing without
creating any objects, and using only primitive types. That fits perfectly
with the primary reason for which the Java language has primitive types
(which are not objects) - for efficiency. This simple change speeds up the
search several times and the search completes in seconds.
RecordComparator implementations are used to order elements in
a record store prior to their return to a RecordEnumeration , upon a
call to RecordStore.enumerateRecords(filter,comparator,
Boolean) . Although filters and comparators serve different purposes,
the advice is the same: keep your comparators fast and efficient, as they
are executed in many records (in all records if the filter is NULL ).
9.2.8 Use the Mobile Media API Correctly
Nearly all use cases requiring MMAPI deal with resources that are
constrained in mobile devices: large amounts of memory (playing and
recording audio and video files), hardware (camera, memory cards,
disk) that is expensive with respect to performance, frequent use of the
network and tight integration to native components. All these factors put
together can make a multimedia application heavy and slow to use. To
avoid this, let us look at some best practices for the main use cases of
MMAPI.
The JSR-135 API is very abstract and relies on multiple optional com-
ponents for proper functioning. Not all implementations of it support all
multimedia formats or operations, therefore run-time checks are needed
to ensure your MIDlet behaves properly on the current device. Let us
consider the following example code:
/* Portions of the code omitted for brevity */
private Player player = null;
private VideoControl control = null;
private RecordControl record = null;
Search WWH ::




Custom Search