blob: 881755ae0d2be31e9de799a818d760b440fe6524 [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
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 */
16package org.onosproject.ovsdb.rfc.schema.type;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23/**
24 * The "atomic-type" specifies the type of data stored in this column. Refer
25 * to RFC 7047 Section 3.2.
26 */
27public final class AtomicColumnType implements ColumnType {
28 private final BaseType baseType;
29 private final int min;
30 private final int max;
31
32 /**
33 * Constructs a AtomicColumnType object.
34 * @param baseType BaseType entity
35 */
36 public AtomicColumnType(BaseType baseType) {
lishuai2f197432015-07-31 16:27:58 +080037 checkNotNull(baseType, "BaseType cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080038 this.baseType = baseType;
39 this.min = 1;
40 this.max = 1;
41 }
42
43 /**
44 * Constructs a AtomicColumnType object.
45 * @param baseType BaseType entity
46 * @param min min constraint
47 * @param max max constraint
48 */
49 public AtomicColumnType(BaseType baseType, int min, int max) {
lishuai2f197432015-07-31 16:27:58 +080050 checkNotNull(baseType, "BaseType cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080051 this.baseType = baseType;
52 this.min = min;
53 this.max = max;
54 }
55
56 /**
57 * Get baseType.
58 * @return baseType
59 */
60 public BaseType baseType() {
61 return baseType;
62 }
63
64 /**
65 * Get min.
66 * @return min
67 */
68 public int min() {
69 return min;
70 }
71
72 /**
73 * Get max.
74 * @return max
75 */
76 public int max() {
77 return max;
78 }
79
80 @Override
81 public int hashCode() {
82 return Objects.hash(baseType, min, max);
83 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (this == obj) {
88 return true;
89 }
90 if (obj instanceof AtomicColumnType) {
91 final AtomicColumnType other = (AtomicColumnType) obj;
92 return Objects.equals(this.baseType, other.baseType)
93 && Objects.equals(this.min, other.min)
94 && Objects.equals(this.max, other.max);
95 }
96 return false;
97 }
98
99 @Override
100 public String toString() {
101 return toStringHelper(this).add("baseType", baseType).add("min", min)
102 .add("max", max).toString();
103 }
104}