michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.sync.repositories; michael@0: michael@0: import java.util.HashSet; michael@0: import java.util.Iterator; michael@0: michael@0: import org.mozilla.gecko.sync.repositories.domain.Record; michael@0: michael@0: public class HashSetStoreTracker implements StoreTracker { michael@0: michael@0: // Guarded by `this`. michael@0: // Used to store GUIDs that were not locally modified but michael@0: // have been modified by a call to `store`, and thus michael@0: // should not be returned by a subsequent fetch. michael@0: private HashSet guids; michael@0: michael@0: public HashSetStoreTracker() { michael@0: guids = new HashSet(); michael@0: } michael@0: michael@0: @Override michael@0: public String toString() { michael@0: return "#"; michael@0: } michael@0: michael@0: @Override michael@0: public synchronized boolean trackRecordForExclusion(String guid) { michael@0: return (guid != null) && guids.add(guid); michael@0: } michael@0: michael@0: @Override michael@0: public synchronized boolean isTrackedForExclusion(String guid) { michael@0: return (guid != null) && guids.contains(guid); michael@0: } michael@0: michael@0: @Override michael@0: public synchronized boolean untrackStoredForExclusion(String guid) { michael@0: return (guid != null) && guids.remove(guid); michael@0: } michael@0: michael@0: @Override michael@0: public RecordFilter getFilter() { michael@0: if (guids.size() == 0) { michael@0: return null; michael@0: } michael@0: return new RecordFilter() { michael@0: @Override michael@0: public boolean excludeRecord(Record r) { michael@0: return isTrackedForExclusion(r.guid); michael@0: } michael@0: }; michael@0: } michael@0: michael@0: @Override michael@0: public Iterator recordsTrackedForExclusion() { michael@0: return this.guids.iterator(); michael@0: } michael@0: }