replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-encapsulation / android / service / src / main / java / org / iotivity / service / RcsValue.java
index 7e916fe..a9edc82 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Map;
  *
  * Type helps identify type information of Value.
  *
- * @see RCSResourceAttributes
+ * @see RcsResourceAttributes
  * @see Type
  */
 public final class RcsValue {
@@ -47,14 +47,14 @@ public final class RcsValue {
      * @see Type
      */
     public static enum TypeId {
-        NULL, BOOLEAN, INTEGER, DOUBLE, STRING, ATTRIBUTES, ARRAY;
+        NULL, BOOLEAN, INTEGER, DOUBLE, STRING, BYTESTRING, ATTRIBUTES, ARRAY;
     }
 
     /**
      * A Helper class to identify types of Value.
      *
-     * @see RCSResourceAttributes
-     * @see Value
+     * @see RcsResourceAttributes
+     * @see RcsValue
      * @see TypeId
      */
     public static class Type {
@@ -69,9 +69,9 @@ public final class RcsValue {
          *
          * @return Identifier of type
          *
-         * @see getBaseTypeId
+         * @see #getBaseTypeId(RcsValue.Type)
          */
-        public final TypeId getTypeId() {
+        public final TypeId getId() {
             return mTypeId;
         }
 
@@ -86,7 +86,7 @@ public final class RcsValue {
         /**
          * Returns the type identifier of a base type of sequence.
          *
-         * For non sequence types, it is equivalent to calling getId.
+         * For non sequence types, it is equivalent to calling {@link #getId()}.
          *
          * @return identifier of type
          *
@@ -110,11 +110,10 @@ public final class RcsValue {
 
         /**
          * Factory method to create Type instance from an object.
+         * Note that object must be a supported type by RcsValue.
          *
          * @return An instance that has TypeId for obj.
          *
-         * @note object must be a supported type by Value.
-         *
          * @throws NullPointerException
          *             if obj is null.
          * @throws IllegalArgumentException
@@ -130,12 +129,11 @@ public final class RcsValue {
         }
 
         /**
-         * Factory method to create Type instance from a clss.
+         * Factory method to create Type instance from a class.
+         * Note that class must be a supported type by RcsValue.
          *
          * @return An instance that has TypeId for class.
          *
-         * @note class must be a supported type by Value.
-         *
          * @throws NullPointerException
          *             if cls is null.
          * @throws IllegalArgumentException
@@ -191,12 +189,14 @@ public final class RcsValue {
         types.put(Integer.class, new Type(TypeId.INTEGER));
         types.put(Double.class, new Type(TypeId.DOUBLE));
         types.put(String.class, new Type(TypeId.STRING));
+        types.put(RcsByteString.class, new Type(TypeId.BYTESTRING));
         types.put(RcsResourceAttributes.class, new Type(TypeId.ATTRIBUTES));
 
         types.put(boolean[].class, new ArrayType(TypeId.BOOLEAN, 1));
         types.put(int[].class, new ArrayType(TypeId.INTEGER, 1));
         types.put(double[].class, new ArrayType(TypeId.DOUBLE, 1));
         types.put(String[].class, new ArrayType(TypeId.STRING, 1));
+        types.put(RcsByteString[].class, new ArrayType(TypeId.BYTESTRING, 1));
         types.put(RcsResourceAttributes[].class,
                 new ArrayType(TypeId.ATTRIBUTES, 1));
 
@@ -204,6 +204,7 @@ public final class RcsValue {
         types.put(int[][].class, new ArrayType(TypeId.INTEGER, 2));
         types.put(double[][].class, new ArrayType(TypeId.DOUBLE, 2));
         types.put(String[][].class, new ArrayType(TypeId.STRING, 2));
+        types.put(RcsByteString[][].class, new ArrayType(TypeId.BYTESTRING, 2));
         types.put(RcsResourceAttributes[][].class,
                 new ArrayType(TypeId.ATTRIBUTES, 2));
 
@@ -211,6 +212,7 @@ public final class RcsValue {
         types.put(int[][][].class, new ArrayType(TypeId.INTEGER, 3));
         types.put(double[][][].class, new ArrayType(TypeId.DOUBLE, 3));
         types.put(String[][][].class, new ArrayType(TypeId.STRING, 3));
+        types.put(RcsByteString[][][].class, new ArrayType(TypeId.BYTESTRING, 3));
         types.put(RcsResourceAttributes[][][].class,
                 new ArrayType(TypeId.ATTRIBUTES, 3));
 
@@ -257,7 +259,7 @@ public final class RcsValue {
     }
 
     /**
-     * Constructs a new value that holds null value.
+     * Constructs a new value that holds a boolean value.
      *
      * @param value
      *            a boolean
@@ -471,8 +473,35 @@ public final class RcsValue {
     /**
      * Constructs a new value that holds a RcsResourceAttributes array.
      *
-     * @param value
-     *            a RcsResourceAttributes array
+     * @param value a RcsByteString array
+     * @throws NullPointerException if value is null.
+     */
+    public RcsValue(RcsByteString[] value) {
+        this((Object) value);
+    }
+
+    /**
+     * Constructs a new value that holds a two-dimensional RcsByteString array.
+     *
+     * @param value a two-dimensional RcsByteString array
+     * @throws NullPointerException if value is null.
+     */
+    public RcsValue(RcsByteString[][] value) {
+        this((Object) value);
+    }
+
+    /**
+     * Constructs a new value that holds a three-dimensional RcsByteString array.
+     *
+     * @param value a three-dimensional RcsByteString array
+     * @throws NullPointerException if value is null.
+     */
+    public RcsValue(RcsByteString[][][] value) {
+        this((Object) value);
+    }
+
+    /**
+     * Constructs a new value that holds a RcsResourceAttributes array.
      *
      * @throws NullPointerException
      *             if value is null.
@@ -510,7 +539,7 @@ public final class RcsValue {
     }
 
     /**
-     * Returns the value it represents is null.
+     * Returns whether the value is null.
      *
      * @return true if the value is null.
      */
@@ -519,7 +548,7 @@ public final class RcsValue {
     }
 
     /**
-     * Returns the object represents null for RcsValue.
+     * Returns whether the object represents null for RcsValue.
      *
      * @param o
      *            an object to be tested
@@ -824,6 +853,36 @@ public final class RcsValue {
     }
 
     /**
+     * Returns the value as an RcsByteString array, null if the value is not the
+     * desired type.
+     *
+     * @return an RcsByteString array
+     */
+    public RcsByteString[] asByteStringArray() {
+        return getOrNull();
+    }
+
+    /**
+     * Returns the value as a two-dimensional RcsByteString array, null if the
+     * value is not the desired type.
+     *
+     * @return a two-dimensional RcsByteString array
+     */
+    public RcsByteString[][] asByteString2DArray() {
+        return getOrNull();
+    }
+
+    /**
+     * Returns the value as a three-dimensional RcsByteString array, null if the
+     * value is not the desired type.
+     *
+     * @return a three-dimensional RcsByteString array
+     */
+    public RcsByteString[][][] asByteString3DArray() {
+        return getOrNull();
+    }
+
+    /**
      * Returns the value as an attributes array, null if the value is not the
      * desired type.
      *