Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync.repositories; |
michael@0 | 6 | |
michael@0 | 7 | import java.util.HashSet; |
michael@0 | 8 | import java.util.Iterator; |
michael@0 | 9 | |
michael@0 | 10 | import org.mozilla.gecko.sync.repositories.domain.Record; |
michael@0 | 11 | |
michael@0 | 12 | public class HashSetStoreTracker implements StoreTracker { |
michael@0 | 13 | |
michael@0 | 14 | // Guarded by `this`. |
michael@0 | 15 | // Used to store GUIDs that were not locally modified but |
michael@0 | 16 | // have been modified by a call to `store`, and thus |
michael@0 | 17 | // should not be returned by a subsequent fetch. |
michael@0 | 18 | private HashSet<String> guids; |
michael@0 | 19 | |
michael@0 | 20 | public HashSetStoreTracker() { |
michael@0 | 21 | guids = new HashSet<String>(); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | @Override |
michael@0 | 25 | public String toString() { |
michael@0 | 26 | return "#<Tracker: " + guids.size() + " guids tracked.>"; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | @Override |
michael@0 | 30 | public synchronized boolean trackRecordForExclusion(String guid) { |
michael@0 | 31 | return (guid != null) && guids.add(guid); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | @Override |
michael@0 | 35 | public synchronized boolean isTrackedForExclusion(String guid) { |
michael@0 | 36 | return (guid != null) && guids.contains(guid); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | @Override |
michael@0 | 40 | public synchronized boolean untrackStoredForExclusion(String guid) { |
michael@0 | 41 | return (guid != null) && guids.remove(guid); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | @Override |
michael@0 | 45 | public RecordFilter getFilter() { |
michael@0 | 46 | if (guids.size() == 0) { |
michael@0 | 47 | return null; |
michael@0 | 48 | } |
michael@0 | 49 | return new RecordFilter() { |
michael@0 | 50 | @Override |
michael@0 | 51 | public boolean excludeRecord(Record r) { |
michael@0 | 52 | return isTrackedForExclusion(r.guid); |
michael@0 | 53 | } |
michael@0 | 54 | }; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | @Override |
michael@0 | 58 | public Iterator<String> recordsTrackedForExclusion() { |
michael@0 | 59 | return this.guids.iterator(); |
michael@0 | 60 | } |
michael@0 | 61 | } |