blob: 5e412a4eb827941e8b3e2b7b923a35e854d3f832 [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
lishuai91d986c2015-07-28 09:45:20 +08003 *
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 */
16package org.onosproject.ovsdb.rfc.schema.type;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21import java.util.Set;
22
23import 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 */
29public final class RealBaseType implements BaseType {
30 private final double min;
31 private final double max;
32 private final Set<Double> enums;
33
34 /**
35 * Constructs a RealBaseType object.
36 */
37 public RealBaseType() {
38 this.min = Double.MIN_VALUE;
39 this.max = Double.MAX_VALUE;
40 this.enums = Sets.newHashSet();
41 }
42
43 /**
44 * Constructs a RealBaseType object.
45 * @param min min constraint
46 * @param max max constraint
47 * @param enums enums constraint
48 */
49 public RealBaseType(double min, double max, Set<Double> 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 double getMin() {
60 return min;
61 }
62
63 /**
64 * Get max.
65 * @return max
66 */
67 public double getMax() {
68 return max;
69 }
70
71 /**
72 * Get enums.
73 * @return enums
74 */
75 public Set<Double> getEnums() {
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 RealBaseType) {
90 final RealBaseType other = (RealBaseType) 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}