blob: 9cf7dd0e64167bb6968863dc4c32a750fbc8af60 [file] [log] [blame]
lishuai91d986c2015-07-28 09:45:20 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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;
lishuai2f197432015-07-31 16:27:58 +080019import static com.google.common.base.Preconditions.checkNotNull;
lishuai91d986c2015-07-28 09:45:20 +080020
21import java.util.Objects;
22
23/**
24 * One of the strings "integer", "real", "boolean", "string", or "uuid",
25 * representing the specified scalar type. Refer to RFC 7047 Section 3.2.
26 */
27public final class UuidBaseType implements BaseType {
28 /**
29 * RefType is strong or weak. refer to base-type of RFC 7047 Section 3.2.
30 */
31 public enum RefType {
32 STRONG("strong"), WEAK("weak");
33
34 private String refType;
35
36 private RefType(String refType) {
37 this.refType = refType;
38 }
39
40 /**
41 * Returns the refType for RefType.
42 * @return the refType
43 */
44 public String refType() {
45 return refType;
46 }
47 }
48
49 private final String refTable;
50 private final String refType;
51
52 /**
53 * Constructs a UuidBaseType object.
54 */
55 public UuidBaseType() {
56 this.refTable = null;
57 this.refType = RefType.STRONG.refType();
58 }
59
60 /**
61 * Constructs a UuidBaseType object.
62 * @param refTable refTable constraint
63 * @param refType refType constraint
64 */
65 public UuidBaseType(String refTable, String refType) {
lishuai2f197432015-07-31 16:27:58 +080066 checkNotNull(refType, "refType cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080067 this.refTable = refTable;
68 this.refType = refType;
69 }
70
71 /**
72 * Get refTable.
73 * @return refTable
74 */
75 public String getRefTable() {
76 return refTable;
77 }
78
79 /**
80 * Get refType.
81 * @return refType
82 */
83 public String getRefType() {
84 return refType;
85 }
86
87 @Override
88 public int hashCode() {
89 return Objects.hash(refTable, refType);
90 }
91
92 @Override
93 public boolean equals(Object obj) {
94 if (this == obj) {
95 return true;
96 }
97 if (obj instanceof UuidBaseType) {
98 final UuidBaseType other = (UuidBaseType) obj;
99 return Objects.equals(this.refTable, other.refTable)
100 && Objects.equals(this.refType, other.refType);
101 }
102 return false;
103 }
104
105 @Override
106 public String toString() {
107 return toStringHelper(this).add("refTable", refTable)
108 .add("refType", refType).toString();
109 }
110}