}
@Override
public void getChanges(int index, int num, JavaScriptObject items,
AsyncCallback<Response> callback) {
Response response = Response.create();
response.setTotalItems(this.trucks.size());
JSONArray array = new JSONArray(items);
for (int i = 0; i < array.size(); i++) {
Truck truck = trucks.get(index + i);
Truck checkTruck = null;
JSONValue value = array.get(i);
JSONObject item = null;
if (value != null) {
item = value.isObject();
}
if (item != null) {
checkTruck = new Truck(item);
}
if (truck != null && checkTruck != null &&
!checkTruck._uuid.equals(truck._uuid)) {
// truck found and at the same index.
// Check the update sequence
if (truck._updateSeq > checkTruck._updateSeq) {
// the checkTruck is outdated
response.addItem(checkTruck.toJSON().getJavaScriptObject());
}
}
else {
// truck not found. Apperently removed.
if (checkTruck != null) {
response.addItem(checkTruck.toJSON().getJavaScriptObject());
}
}
}
callback.onSuccess(response);