blob: 8407457ad0cee2cc3243f02181220d8fc9149d47 [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 * a JSON object that describes the type of a database column, with key and
25 * value. Refer to RFC 7047 Section 3.2.
26 */
27public final class KeyValuedColumnType implements ColumnType {
28 private final BaseType keyType;
29 private final BaseType valueType;
30 private final int min;
31 private final int max;
32
33 /**
34 * Constructs a KeyValuedColumnType object.
35 * @param keyType BaseType entity
36 * @param valueType BaseType entity
37 * @param min min constraint
38 * @param max max constraint
39 */
40 public KeyValuedColumnType(BaseType keyType, BaseType valueType, int min,
41 int max) {
lishuai2f197432015-07-31 16:27:58 +080042 checkNotNull(keyType, "keyType cannot be null");
43 checkNotNull(valueType, "valueType cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080044 this.keyType = keyType;
45 this.valueType = valueType;
46 this.min = min;
47 this.max = max;
48 }
49
50 /**
51 * Get keyType.
52 * @return keyType
53 */
54 public BaseType keyType() {
55 return keyType;
56 }
57
58 /**
59 * Get valueType.
60 * @return valueType
61 */
62 public BaseType valueType() {
63 return valueType;
64 }
65
66 /**
67 * Get min.
68 * @return min
69 */
70 public int min() {
71 return min;
72 }
73
74 /**
75 * Get max.
76 * @return max
77 */
78 public int max() {
79 return max;
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(keyType, valueType, min, max);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (obj instanceof KeyValuedColumnType) {
93 final KeyValuedColumnType other = (KeyValuedColumnType) obj;
94 return Objects.equals(this.keyType, other.keyType)
95 && Objects.equals(this.valueType, other.valueType)
96 && Objects.equals(this.min, other.min)
97 && Objects.equals(this.max, other.max);
98 }
99 return false;
100 }
101
102 @Override
103 public String toString() {
104 return toStringHelper(this).add("keyType", keyType)
105 .add("valueType", valueType).add("min", min).add("max", max)
106 .toString();
107 }
108}