mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-06 17:16:12 +00:00
584e717110
--HG-- rename : mobile/android/base/sync/GlobalConstants.java.in => mobile/android/base/background/common/GlobalConstants.java.in rename : mobile/android/base/sync/Logger.java => mobile/android/base/background/common/log/Logger.java rename : mobile/android/base/sync/log/writers/AndroidLevelCachingLogWriter.java => mobile/android/base/background/common/log/writers/AndroidLevelCachingLogWriter.java rename : mobile/android/base/sync/log/writers/AndroidLogWriter.java => mobile/android/base/background/common/log/writers/AndroidLogWriter.java rename : mobile/android/base/sync/log/writers/LevelFilteringLogWriter.java => mobile/android/base/background/common/log/writers/LevelFilteringLogWriter.java rename : mobile/android/base/sync/log/writers/LogWriter.java => mobile/android/base/background/common/log/writers/LogWriter.java rename : mobile/android/base/sync/log/writers/PrintLogWriter.java => mobile/android/base/background/common/log/writers/PrintLogWriter.java rename : mobile/android/base/sync/log/writers/SimpleTagLogWriter.java => mobile/android/base/background/common/log/writers/SimpleTagLogWriter.java rename : mobile/android/base/sync/log/writers/StringLogWriter.java => mobile/android/base/background/common/log/writers/StringLogWriter.java rename : mobile/android/base/sync/log/writers/TagLogWriter.java => mobile/android/base/background/common/log/writers/TagLogWriter.java rename : mobile/android/base/sync/log/writers/ThreadLocalTagLogWriter.java => mobile/android/base/background/common/log/writers/ThreadLocalTagLogWriter.java
68 lines
1.8 KiB
Java
68 lines
1.8 KiB
Java
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.gecko.sync;
|
|
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map.Entry;
|
|
import java.util.Set;
|
|
|
|
import org.mozilla.gecko.background.common.log.Logger;
|
|
|
|
public class InfoCounts {
|
|
static final String LOG_TAG = "InfoCounts";
|
|
|
|
/**
|
|
* Counts fetched from the server, or <code>null</code> if not yet fetched.
|
|
*/
|
|
private Map<String, Integer> counts = null;
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public InfoCounts(final ExtendedJSONObject record) {
|
|
Logger.debug(LOG_TAG, "info/collection_counts is " + record.toJSONString());
|
|
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
|
|
|
Set<Entry<String, Object>> entrySet = record.object.entrySet();
|
|
|
|
String key;
|
|
Object value;
|
|
|
|
for (Entry<String, Object> entry : entrySet) {
|
|
key = entry.getKey();
|
|
value = entry.getValue();
|
|
|
|
if (value instanceof Integer) {
|
|
map.put(key, (Integer) value);
|
|
continue;
|
|
}
|
|
|
|
if (value instanceof Long) {
|
|
map.put(key, ((Long) value).intValue());
|
|
continue;
|
|
}
|
|
|
|
Logger.warn(LOG_TAG, "Skipping info/collection_counts entry for " + key);
|
|
}
|
|
|
|
this.counts = Collections.unmodifiableMap(map);
|
|
}
|
|
|
|
/**
|
|
* Return the server count for the given collection, or null if the counts
|
|
* have not been fetched or the given collection does not have a count.
|
|
*
|
|
* @param collection
|
|
* The collection to inspect.
|
|
* @return the number of elements in the named collection.
|
|
*/
|
|
public Integer getCount(String collection) {
|
|
if (counts == null) {
|
|
return null;
|
|
}
|
|
return counts.get(collection);
|
|
}
|
|
}
|