From 300eeaef566abcbf25b0aba3ce3484094d4dc5cf Mon Sep 17 00:00:00 2001 From: G S Senthil Kumar Date: Fri, 4 Mar 2016 01:42:40 +0530 Subject: [PATCH] Resolved an issue related to array value validation. Handled unique property when validating an array type attribute value. Change-Id: Ifbe6e8f4d8077b410780adc7b517e203043a2ecd Signed-off-by: G S Senthil Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/5367 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../src/org/oic/simulator/ArrayValueValidator.java | 23 ++++++++++++++++++++++ .../oic/simulator/server/SimulatorResource.java | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java b/service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java index 99f7d4f..26206c4 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/ArrayValueValidator.java @@ -16,6 +16,9 @@ package org.oic.simulator; +import java.util.HashSet; +import java.util.Set; + class ArrayValueValidator implements AttributeValueVisitor.VisitingMethods { @@ -75,7 +78,12 @@ class ArrayValueValidator implements return false; } + Set uniqueSet = new HashSet(); for (Integer value : values) { + if (mProperty.isUnique() && uniqueSet.add(value) == false) { + return false; + } + if (false == elementProperty.asInteger().validate(value)) return false; } @@ -103,7 +111,12 @@ class ArrayValueValidator implements return false; } + Set uniqueSet = new HashSet(); for (Double value : values) { + if (mProperty.isUnique() && uniqueSet.add(value) == false) { + return false; + } + if (false == elementProperty.asDouble().validate(value)) return false; } @@ -131,7 +144,12 @@ class ArrayValueValidator implements return false; } + Set uniqueSet = new HashSet(); for (Boolean value : values) { + if (mProperty.isUnique() && uniqueSet.add(value) == false) { + return false; + } + if (false == elementProperty.asBoolean().validate(value)) return false; } @@ -159,7 +177,12 @@ class ArrayValueValidator implements return false; } + Set uniqueSet = new HashSet(); for (String value : values) { + if (mProperty.isUnique() && uniqueSet.add(value) == false) { + return false; + } + if (false == elementProperty.asString().validate(value)) return false; } diff --git a/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java b/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java index 0f63299..be548d6 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java @@ -280,8 +280,8 @@ public class SimulatorResource { * This exception will be thrown if the interface type is * invalid. * @throws NoSupportException - * This exception will be thrown if the interface type is - * not supported by the resource. + * This exception will be thrown if the interface type is not + * supported by the resource. * @throws SimulatorException * This exception will be thrown if the native resource object * does not exist or for some general errors. -- 2.7.4