Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.gecko.sync.repositories;
7 import java.io.IOException;
9 import org.json.simple.parser.ParseException;
10 import org.mozilla.gecko.background.common.log.Logger;
11 import org.mozilla.gecko.sync.ExtendedJSONObject;
12 import org.mozilla.gecko.sync.NonObjectJSONException;
14 public class RepositorySessionBundle {
15 public static final String LOG_TAG = RepositorySessionBundle.class.getSimpleName();
17 protected static final String JSON_KEY_TIMESTAMP = "timestamp";
19 protected final ExtendedJSONObject object;
21 public RepositorySessionBundle(String jsonString) throws IOException, ParseException, NonObjectJSONException {
22 object = ExtendedJSONObject.parseJSONObject(jsonString);
23 }
25 public RepositorySessionBundle(long lastSyncTimestamp) {
26 object = new ExtendedJSONObject();
27 this.setTimestamp(lastSyncTimestamp);
28 }
30 public long getTimestamp() {
31 if (object.containsKey(JSON_KEY_TIMESTAMP)) {
32 return object.getLong(JSON_KEY_TIMESTAMP);
33 }
35 return -1;
36 }
38 public void setTimestamp(long timestamp) {
39 Logger.debug(LOG_TAG, "Setting timestamp to " + timestamp + ".");
40 object.put(JSON_KEY_TIMESTAMP, Long.valueOf(timestamp));
41 }
43 public void bumpTimestamp(long timestamp) {
44 long existing = this.getTimestamp();
45 if (timestamp > existing) {
46 this.setTimestamp(timestamp);
47 } else {
48 Logger.debug(LOG_TAG, "Timestamp " + timestamp + " not greater than " + existing + "; not bumping.");
49 }
50 }
52 public String toJSONString() {
53 return object.toJSONString();
54 }
55 }