blob: 85ec5e9dfee3f0b59505c66d6030a43fea3aabef [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 StringBaseType implements BaseType {
30 private final int minLength;
31 private final int maxLength;
32 private final Set<String> enums;
33
34 /**
35 * Constructs a StringBaseType object.
36 */
37 public StringBaseType() {
38 this.minLength = Integer.MIN_VALUE;
39 this.maxLength = Integer.MAX_VALUE;
40 this.enums = Sets.newHashSet();
41 }
42
43 /**
44 * Constructs a StringBaseType object.
45 * @param minLength minLength constraint
46 * @param maxLength maxLength constraint
47 * @param enums enums constraint
48 */
49 public StringBaseType(int minLength, int maxLength, Set<String> enums) {
50 this.minLength = minLength;
51 this.maxLength = maxLength;
52 this.enums = enums;
53 }
54
55 /**
56 * Get minLength.
57 * @return minLength
58 */
59 public int getMinLength() {
60 return minLength;
61 }
62
63 /**
64 * Get maxLength.
65 * @return maxLength
66 */
67 public int getMaxLength() {
68 return maxLength;
69 }
70
71 /**
72 * Get enums.
73 * @return enums
74 */
75 public Set<String> getEnums() {
76 return enums;
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(minLength, maxLength, enums);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) {
87 return true;
88 }
89 if (obj instanceof StringBaseType) {
90 final StringBaseType other = (StringBaseType) obj;
91 return Objects.equals(this.enums, other.enums)
92 && Objects.equals(this.minLength, other.minLength)
93 && Objects.equals(this.maxLength, other.maxLength);
94 }
95 return false;
96 }
97
98 @Override
99 public String toString() {
100 return toStringHelper(this).add("minLength", minLength)
101 .add("maxLength", maxLength).add("enums", enums).toString();
102 }
103}