919395150000511a2a67b327f3ee942a6013eca4
[onosfw.git] /
1 /*
2  * Copyright 2015 Open Networking Laboratory
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onosproject.ovsdb.rfc.schema.type;
17
18 import static com.google.common.base.MoreObjects.toStringHelper;
19
20 import java.util.Objects;
21 import java.util.Set;
22
23 import com.google.common.collect.Sets;
24
25 /**
26  * One of the strings "integer", "real", "boolean", "string", or "uuid",
27  * representing the specified scalar type. Refer to RFC 7047 Section 3.2.
28  */
29 public final class IntegerBaseType implements BaseType {
30     private final int min;
31     private final int max;
32     private final Set<Integer> enums;
33
34     /**
35      * Constructs a IntegerBaseType object.
36      */
37     public IntegerBaseType() {
38         this.min = Integer.MIN_VALUE;
39         this.max = Integer.MAX_VALUE;
40         this.enums = Sets.newHashSet();
41     }
42
43     /**
44      * Constructs a IntegerBaseType object.
45      * @param min min constraint
46      * @param max max constraint
47      * @param enums enums constraint
48      */
49     public IntegerBaseType(int min, int max, Set<Integer> enums) {
50         this.min = min;
51         this.max = max;
52         this.enums = enums;
53     }
54
55     /**
56      * Get min.
57      * @return min
58      */
59     public int min() {
60         return min;
61     }
62
63     /**
64      * Get max.
65      * @return max
66      */
67     public int max() {
68         return max;
69     }
70
71     /**
72      * Get enums.
73      * @return enums
74      */
75     public Set<Integer> enums() {
76         return enums;
77     }
78
79     @Override
80     public int hashCode() {
81         return Objects.hash(min, max, enums);
82     }
83
84     @Override
85     public boolean equals(Object obj) {
86         if (this == obj) {
87             return true;
88         }
89         if (obj instanceof IntegerBaseType) {
90             final IntegerBaseType other = (IntegerBaseType) obj;
91             return Objects.equals(this.enums, other.enums)
92                     && Objects.equals(this.min, other.min)
93                     && Objects.equals(this.max, other.max);
94         }
95         return false;
96     }
97
98     @Override
99     public String toString() {
100         return toStringHelper(this).add("min", min).add("max", max)
101                 .add("enums", enums).toString();
102     }
103 }