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 IntegerProperty extends AttributeProperty {
22 private int mDefaultValue;
25 private int[] mValues;
26 private boolean mHasRange = false;
28 private IntegerProperty(int value) {
30 mDefaultValue = value;
33 private IntegerProperty(int value, int min, int max) {
35 mDefaultValue = value;
41 private IntegerProperty(int value, int[] values) {
43 mDefaultValue = value;
44 mValues = Arrays.copyOf(values, values.length);
49 public boolean isInteger() {
54 public IntegerProperty asInteger() {
58 public int getDefaultValue() {
62 public boolean hasRange() {
74 public boolean hasValues() {
75 return (null != mValues && (mValues.length > 0));
78 public int[] getValues() {
83 public boolean validate(AttributeValue value) {
84 return new IntegerValueValidator(this).validate(value);
87 public boolean validate(int value) {
88 if (mHasRange && (value < mMin || value > mMax)) {
90 } else if (hasValues() && 0 > Arrays.binarySearch(mValues, value)) {
97 public static class Builder {
98 private int mDefaultValue = 0;
101 private int[] mValues;
102 private boolean mHasRange = false;
104 public void setDefaultValue(int value) {
105 mDefaultValue = value;
108 public void setRange(int min, int max) {
114 public void setValues(int[] values) {
118 public IntegerProperty build() {
120 return new IntegerProperty(mDefaultValue, mMin, mMax);
121 if (null != mValues && (0 != mValues.length))
122 return new IntegerProperty(mDefaultValue, mValues);
123 return new IntegerProperty(mDefaultValue);