1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/sync/repositories/HashSetStoreTracker.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.sync.repositories; 1.9 + 1.10 +import java.util.HashSet; 1.11 +import java.util.Iterator; 1.12 + 1.13 +import org.mozilla.gecko.sync.repositories.domain.Record; 1.14 + 1.15 +public class HashSetStoreTracker implements StoreTracker { 1.16 + 1.17 + // Guarded by `this`. 1.18 + // Used to store GUIDs that were not locally modified but 1.19 + // have been modified by a call to `store`, and thus 1.20 + // should not be returned by a subsequent fetch. 1.21 + private HashSet<String> guids; 1.22 + 1.23 + public HashSetStoreTracker() { 1.24 + guids = new HashSet<String>(); 1.25 + } 1.26 + 1.27 + @Override 1.28 + public String toString() { 1.29 + return "#<Tracker: " + guids.size() + " guids tracked.>"; 1.30 + } 1.31 + 1.32 + @Override 1.33 + public synchronized boolean trackRecordForExclusion(String guid) { 1.34 + return (guid != null) && guids.add(guid); 1.35 + } 1.36 + 1.37 + @Override 1.38 + public synchronized boolean isTrackedForExclusion(String guid) { 1.39 + return (guid != null) && guids.contains(guid); 1.40 + } 1.41 + 1.42 + @Override 1.43 + public synchronized boolean untrackStoredForExclusion(String guid) { 1.44 + return (guid != null) && guids.remove(guid); 1.45 + } 1.46 + 1.47 + @Override 1.48 + public RecordFilter getFilter() { 1.49 + if (guids.size() == 0) { 1.50 + return null; 1.51 + } 1.52 + return new RecordFilter() { 1.53 + @Override 1.54 + public boolean excludeRecord(Record r) { 1.55 + return isTrackedForExclusion(r.guid); 1.56 + } 1.57 + }; 1.58 + } 1.59 + 1.60 + @Override 1.61 + public Iterator<String> recordsTrackedForExclusion() { 1.62 + return this.guids.iterator(); 1.63 + } 1.64 +}