Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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.util.HashSet;
8 import java.util.Iterator;
10 import org.mozilla.gecko.sync.repositories.domain.Record;
12 public class HashSetStoreTracker implements StoreTracker {
14 // Guarded by `this`.
15 // Used to store GUIDs that were not locally modified but
16 // have been modified by a call to `store`, and thus
17 // should not be returned by a subsequent fetch.
18 private HashSet<String> guids;
20 public HashSetStoreTracker() {
21 guids = new HashSet<String>();
22 }
24 @Override
25 public String toString() {
26 return "#<Tracker: " + guids.size() + " guids tracked.>";
27 }
29 @Override
30 public synchronized boolean trackRecordForExclusion(String guid) {
31 return (guid != null) && guids.add(guid);
32 }
34 @Override
35 public synchronized boolean isTrackedForExclusion(String guid) {
36 return (guid != null) && guids.contains(guid);
37 }
39 @Override
40 public synchronized boolean untrackStoredForExclusion(String guid) {
41 return (guid != null) && guids.remove(guid);
42 }
44 @Override
45 public RecordFilter getFilter() {
46 if (guids.size() == 0) {
47 return null;
48 }
49 return new RecordFilter() {
50 @Override
51 public boolean excludeRecord(Record r) {
52 return isTrackedForExclusion(r.guid);
53 }
54 };
55 }
57 @Override
58 public Iterator<String> recordsTrackedForExclusion() {
59 return this.guids.iterator();
60 }
61 }