From 328ea1e04928e39d3ad892885baf34ae62528d3a Mon Sep 17 00:00:00 2001 From: Michael Nitschinger Date: Wed, 28 Nov 2012 09:21:05 +0100 Subject: [PATCH] JCBC-155: Adding JavaDoc for *View.java files. This changeset adds JavaDoc for AbstractView, SpatialView and View. It is intended to clarify their usage and what they can be used for. Change-Id: I62b9bda1eb4b006fa012be909cec92a66e3fafdc Reviewed-on: http://review.couchbase.org/22872 Tested-by: Michael Nitschinger Reviewed-by: Matt Ingenthron --- .../client/protocol/views/AbstractView.java | 53 +++++++++++++++++-- .../client/protocol/views/SpatialView.java | 30 +++++++++-- .../couchbase/client/protocol/views/View.java | 43 ++++++++++++--- 3 files changed, 111 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/couchbase/client/protocol/views/AbstractView.java b/src/main/java/com/couchbase/client/protocol/views/AbstractView.java index e75424a3..63ad0e8c 100644 --- a/src/main/java/com/couchbase/client/protocol/views/AbstractView.java +++ b/src/main/java/com/couchbase/client/protocol/views/AbstractView.java @@ -23,34 +23,77 @@ package com.couchbase.client.protocol.views; /** - * A base class for views and spatial views. + * The base class for Views and Spatial Views. + * + * This class acts as a base class for both map/reduce views and spatial + * views. Do not use this class directly, but instead create instances from + * either the View or the SpatialView classes. */ public abstract class AbstractView { private final String viewName; private final String designDocumentName; private final String databaseName; - public AbstractView(String dn, String ddn, String vn) { - databaseName = dn; - designDocumentName = ddn; - viewName = vn; + /** + * Instantiate a AbstractView object. + * + * This should only be used by subclasses like View or SpatialView. + * + * @param database the name of the database. + * @param designDoc the name of the corresponding design document. + * @param view the name of the view itself. + */ + public AbstractView(String database, String designDoc, String view) { + databaseName = database; + designDocumentName = designDoc; + viewName = view; } + /** + * Returns the database (bucket) name. + * + * @return the database (bucket) name. + */ public String getDatabaseName() { return databaseName; } + /** + * Returns the design document name. + * + * @return the name of the design document. + */ public String getDesignDocumentName() { return designDocumentName; } + /** + * Returns the view name. + * + * @return the name of the view. + */ public String getViewName() { return viewName; } + /** + * Checks if the view has a "map" method defined. + * + * @return true if it has a "map" method defined, false otherwise. + */ public abstract boolean hasMap(); + /** + * Checks if the view has a "reduce" method defined. + * + * @return true if it has a "reduce" method defined, false otherwise. + */ public abstract boolean hasReduce(); + /** + * Returns the URI/String representation of the View. + * + * @return the URI path of the View to query against the cluster. + */ public abstract String getURI(); } diff --git a/src/main/java/com/couchbase/client/protocol/views/SpatialView.java b/src/main/java/com/couchbase/client/protocol/views/SpatialView.java index edffac18..2b4b263a 100644 --- a/src/main/java/com/couchbase/client/protocol/views/SpatialView.java +++ b/src/main/java/com/couchbase/client/protocol/views/SpatialView.java @@ -28,23 +28,47 @@ */ public class SpatialView extends AbstractView { - public SpatialView(String dn, String ddn, String vn) { - super(dn, ddn, vn); + /** + * Create a new Spatial View object. + * + * @param database the name of the database. + * @param designDoc the name of the corresponding design document. + * @param viewName the name of the view itself. + */ + public SpatialView(String database, String designDoc, String viewName) { + super(database, designDoc, viewName); } + /** + * Will always return true, because Spatial Views need to have a map + * function. + * + * @return true. + */ @Override public boolean hasMap() { return true; } + /** + * Will always return false, because Spatial Views can't have reduce + * functions. + * + * @return false. + */ @Override public boolean hasReduce() { return false; } + /** + * Returns the URI/String representation of the Spatial View. + * + * @return the URI path of the Spatial View to query against the cluster. + */ @Override public String getURI() { return "/" + getDatabaseName() + "/_design/" + getDesignDocumentName() + "/_spatial/" + getViewName(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/couchbase/client/protocol/views/View.java b/src/main/java/com/couchbase/client/protocol/views/View.java index fea4e799..7d92ab16 100644 --- a/src/main/java/com/couchbase/client/protocol/views/View.java +++ b/src/main/java/com/couchbase/client/protocol/views/View.java @@ -23,33 +23,62 @@ package com.couchbase.client.protocol.views; /** - * Holds information about a view that can be queried in - * Couchbase Server. + * Represents a View definition inside the Couchbase cluster. + * + * This class knows whether the view contains "map" and/or "reduce" functions. + * It also is able to generate the URI representation of itself to be used + * against the cluster. Also, instances of a View can be used in combination + * with DesignDocuments to actually create them. */ public class View extends AbstractView { private final boolean map; private final boolean reduce; - public View(String dn, String ddn, String vn, boolean m, boolean r) { - super(dn, ddn, vn); - map = m; - reduce = r; + /** + * Create a new View object. + * + * @param database the name of the database. + * @param designDoc the name of the corresponding design document. + * @param viewName the name of the view itself. + * @param map if the View contains a map function or not. + * @param reduce if the View contains a reduce function or not. + */ + public View(String database, String designDoc, String viewName, + boolean map, boolean reduce) { + super(database, designDoc, viewName); + this.map = map; + this.reduce = reduce; } + /** + * Checks if the view has a "map" method defined. + * + * @return true if it has a "map" method defined, false otherwise. + */ @Override public boolean hasMap() { return map; } + /** + * Checks if the view has a "reduce" method defined. + * + * @return true if it has a "reduce" method defined, false otherwise. + */ @Override public boolean hasReduce() { return reduce; } + /** + * Returns the URI/String representation of the View. + * + * @return the URI path of the View to query against the cluster. + */ @Override public String getURI() { return "/" + getDatabaseName() + "/_design/" + getDesignDocumentName() + "/_view/" + getViewName(); } -} +} \ No newline at end of file