2 * Copyright 2015 Samsung Electronics All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.oic.simulator;
19 import java.util.Arrays;
21 public class StringProperty extends AttributeProperty {
23 private String mDefaultValue;
26 private String[] mValues;
27 private boolean mHasRange = false;
29 private StringProperty(String value) {
31 mDefaultValue = value;
34 private StringProperty(String value, int min, int max) {
36 mDefaultValue = value;
42 private StringProperty(String value, String[] values) {
44 mDefaultValue = value;
45 mValues = Arrays.copyOf(values, values.length);
50 public boolean isString() {
55 public StringProperty asString() {
59 public String getDefaultValue() {
63 public boolean hasRange() {
75 public boolean hasValues() {
76 return (null != mValues && (mValues.length > 0));
79 public String[] getValues() {
84 public boolean validate(AttributeValue value) {
85 return new StringValueValidator(this).validate(value);
88 public boolean validate(String value) {
89 int length = value.length();
90 if (mHasRange && (length < mMin || length > mMax)) {
92 } else if (hasValues() && 0 > Arrays.binarySearch(mValues, value)) {
99 public static class Builder {
100 private String mDefaultValue;
103 private String[] mValues;
104 private boolean mHasRange = false;
106 public void setDefaultValue(String value) {
108 mDefaultValue = value;
111 public void setRange(int min, int max) {
117 public void setValues(String[] values) {
121 public StringProperty build() {
123 return new StringProperty(mDefaultValue, mMin, mMax);
124 if (null != mValues && (0 != mValues.length))
125 return new StringProperty(mDefaultValue, mValues);
126 return new StringProperty(mDefaultValue);