From f4cfa5d544e440144d0ee8d517ec4966654a5842 Mon Sep 17 00:00:00 2001 From: prajgov Date: Fri, 22 Dec 2017 11:58:50 +0530 Subject: [PATCH] added JavaDoc comments --- .../fr/free/nrw/commons/data/Category.java | 213 +++++++++--------- 1 file changed, 104 insertions(+), 109 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/data/Category.java b/app/src/main/java/fr/free/nrw/commons/data/Category.java index 05a8681f7..be4a29846 100644 --- a/app/src/main/java/fr/free/nrw/commons/data/Category.java +++ b/app/src/main/java/fr/free/nrw/commons/data/Category.java @@ -25,6 +25,107 @@ public class Category { private int timesUsed; // Getters/setters + /** + * Gets name + * + * @return name + */ + public String getName() { + return name; + } + + /** + * Modifies name + * + * @param name Category name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Gets last used date + * + * @return Last used date + */ + private Date getLastUsed() { + // warning: Date objects are mutable. + return (Date)lastUsed.clone(); + } + + /** + * Modifies last used date + * + * @param lastUsed Category date + */ + public void setLastUsed(Date lastUsed) { + // warning: Date objects are mutable. + this.lastUsed = (Date)lastUsed.clone(); + } + + /** + * Generates new last used date + */ + private void touch() { + lastUsed = new Date(); + } + + /** + * Gets no. of times the category is used + * + * @return no. of times used + */ + private int getTimesUsed() { + return timesUsed; + } + + /** + * Modifies no. of times used + * + * @param timesUsed Category used times + */ + public void setTimesUsed(int timesUsed) { + this.timesUsed = timesUsed; + } + + /** + * Increments timesUsed by 1 and sets last used date as now. + */ + public void incTimesUsed() { + timesUsed++; + touch(); + } + + //region Database/content-provider stuff + + /** + * Persist category. + * @param client ContentProviderClient to handle DB connection + */ + public void save(ContentProviderClient client) { + try { + if (contentUri == null) { + contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues()); + } else { + client.update(contentUri, toContentValues(), null, null); + } + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + /** + * Gets content values + * + * @return Content values + */ + private ContentValues toContentValues() { + ContentValues cv = new ContentValues(); + cv.put(Table.COLUMN_NAME, getName()); + cv.put(Table.COLUMN_LAST_USED, getLastUsed().getTime()); + cv.put(Table.COLUMN_TIMES_USED, getTimesUsed()); + return cv; + } /** * Gets category from cursor @@ -42,10 +143,10 @@ public class Category { } /** - * Find persisted category in database table, based on its name. + * Find persisted category in database, based on its name. * @param client ContentProviderClient to handle DB connection * @param name Category's name - * @return category from , database table, or null if not found + * @return category from database, or null if not found */ public static @Nullable Category find(ContentProviderClient client, String name) { Cursor cursor = null; @@ -100,112 +201,6 @@ public class Category { return items; } - /** - * Gets name - * - * @return name - */ - public String getName() { - return name; - } - - /** - * Modifies name - * - * @param name Category name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Gets last used date - * - * @return Last used date - */ - private Date getLastUsed() { - // warning: Date objects are mutable. - return (Date) lastUsed.clone(); - } - - /** - * Modifies last used date - * - * @param lastUsed Category date - */ - public void setLastUsed(Date lastUsed) { - // warning: Date objects are mutable. - this.lastUsed = (Date) lastUsed.clone(); - } - - /** - * Generates new last used date - */ - private void touch() { - lastUsed = new Date(); - } - - //region Database/content-provider stuff - - /** - * Gets no. of times the category is used - * - * @return no. of times used - */ - private int getTimesUsed() { - return timesUsed; - } - - /** - * Modifies no. of times used - * - * @param timesUsed Category used times - */ - public void setTimesUsed(int timesUsed) { - this.timesUsed = timesUsed; - } - - /** - * Increments timesUsed by 1 and sets last used date as now. - */ - public void incTimesUsed() { - timesUsed++; - touch(); - } - - /** - * Persist category. - * - * @param client ContentProviderClient to handle DB connection - */ - public void save(ContentProviderClient client) { - try { - if (contentUri == null) { - contentUri = client.insert(CategoryContentProvider.BASE_URI, this.toContentValues()); - } else { - client.update(contentUri, toContentValues(), null, null); - } - } catch (RemoteException e) { - throw new RuntimeException(e); - } - } - - /** - * Gets content values - * - * @return Content values - */ - private ContentValues toContentValues() { - ContentValues cv = new ContentValues(); - cv.put(Table.COLUMN_NAME, getName()); - cv.put(Table.COLUMN_LAST_USED, getLastUsed().getTime()); - cv.put(Table.COLUMN_TIMES_USED, getTimesUsed()); - return cv; - } - - /** - * Represents table - */ public static class Table { public static final String TABLE_NAME = "categories"; @@ -278,4 +273,4 @@ public class Category { } } //endregion -} +} \ No newline at end of file