Deskana has uploaded a new change for review.
https://gerrit.wikimedia.org/r/174906
Change subject: Add Javadoc comments to WikidataCache.
......................................................................
Add Javadoc comments to WikidataCache.
The methods in WikidataCache are quite complicated, and it might not be
outwardly clear which ones are best to use for any particular purpose.
This patch adds Javadoc comments to the class so that it's a bit clearer how
to use it.
Change-Id: I2d0595c99a42592bde68114f1e6db2cb14686255
---
M wikipedia/src/main/java/org/wikipedia/wikidata/WikidataCache.java
1 file changed, 52 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/06/174906/1
diff --git a/wikipedia/src/main/java/org/wikipedia/wikidata/WikidataCache.java
b/wikipedia/src/main/java/org/wikipedia/wikidata/WikidataCache.java
index b05be2a..2442b2b 100644
--- a/wikipedia/src/main/java/org/wikipedia/wikidata/WikidataCache.java
+++ b/wikipedia/src/main/java/org/wikipedia/wikidata/WikidataCache.java
@@ -10,7 +10,6 @@
public class WikidataCache {
private static final int MAX_CACHE_SIZE_DESCRIPTIONS = 96;
-
private WikipediaApp app;
private ParcelableLruCache<String> descriptionCache
= new ParcelableLruCache<String>(MAX_CACHE_SIZE_DESCRIPTIONS,
String.class);
@@ -19,31 +18,81 @@
this.app = app;
}
+ /**
+ * Removes all the data in the Wikidata descriptions cache.
+ */
public void clear() {
descriptionCache.evictAll();
}
+ /**
+ * Adds the description for a Wikidata item directly to the Wikidata
description cache.
+ *
+ * This method should be used sparingly. Instead of putting descriptions
directly into the
+ * cache consider using the get method instead, which will retrieve
descriptions that the cache
+ * currently does not contain and cache them itself if appropriate.
+ *
+ * @param key Wikidata ID of the page for which the description is to be
cached.
+ * @param value Wikidata description of the page associated with the
Wikidata ID.
+ */
public void put(String key, String value) {
descriptionCache.put(key, value);
}
+ /**
+ * Retrieves the description for a Wikidata item directly from the
Wikidata description cache.
+ *
+ * This method should be used sparingly. Instead of getting descriptions
directly from the
+ * cache consider using the get method instead, which will retrieve
descriptions that the cache
+ * currently does not contain and cache them itself if appropriate.
+ *
+ * @param id Wikidata ID of the page for which the description is required.
+ * @return The Wikidata description that was cached, or null if the
description is not cached.
+ */
public String get(String id) {
return descriptionCache.get(id);
}
+ /**
+ * Retrieves Wikidata description for a page in the app's current primary
language.
+ *
+ * @param id Wikidata ID of the page for which the description is required.
+ * @param listener Listener that will receive the description retrieved
from the cache.
+ */
public void get(String id, OnWikidataReceiveListener listener) {
get(id, app.getPrimaryLanguage(), listener);
}
+ /**
+ * Retrieves Wikidata description for a page in the specified language.
+ *
+ * @param id Wikidata ID of the page for which the description is required.
+ * @param language The language in which the description is required.
+ * @param listener Listener that will receive the description retrieved
from the cache.
+ */
public void get(String id, String language, OnWikidataReceiveListener
listener) {
List<String> idList = new ArrayList<String>();
idList.add(id);
get(idList, language, listener);
}
+
+ /**
+ * Retrieves Wikidata descriptions for a list of pages in the app's
current primary language.
+ *
+ * @param ids Wikidata IDs of the pages for which the descriptions are
required.
+ * @param listener Listener that will receive the descriptions retrieved
from the cache.
+ */
public void get(List<String> ids, final OnWikidataReceiveListener
listener) {
get(ids, app.getPrimaryLanguage(), listener);
}
+ /**
+ * Retrieves Wikidata descriptions for a list of pages in the specified
language.
+ *
+ * @param ids Wikidata IDs of the pages for which the descriptions are
required.
+ * @param language The language in which the descriptions are required.
+ * @param listener Listener that will receive the descriptions retrieved
from the cache.
+ */
public void get(List<String> ids, final String language, final
OnWikidataReceiveListener listener) {
final Map<String, String> results = new HashMap<String, String>();
List<String> idsToFetch = new ArrayList<String>();
@@ -68,8 +117,8 @@
continue;
}
// Only store results in cache if they correspond to
the language we're
- // currently using; that way if you choose "Read in
another language" you
- // won't cache and display results from the incorrect
language
+ // currently using; that way if the user chose "Read
in another language"
+ // we're not caching and displaying results from the
incorrect language
if (language.equals(app.getPrimaryLanguage())) {
descriptionCache.put(entry.getKey(),
entry.getValue());
}
--
To view, visit https://gerrit.wikimedia.org/r/174906
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2d0595c99a42592bde68114f1e6db2cb14686255
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Deskana <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits