lishuai | 91d986c | 2015-07-28 09:45:20 +0800 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ovsdb.rfc.schema.type; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
| 23 | * One of the strings "integer", "real", "boolean", "string", or "uuid", |
| 24 | * representing the specified scalar type. Refer to RFC 7047 Section 3.2. |
| 25 | */ |
| 26 | public final class UuidBaseType implements BaseType { |
| 27 | /** |
| 28 | * RefType is strong or weak. refer to base-type of RFC 7047 Section 3.2. |
| 29 | */ |
| 30 | public enum RefType { |
| 31 | STRONG("strong"), WEAK("weak"); |
| 32 | |
| 33 | private String refType; |
| 34 | |
| 35 | private RefType(String refType) { |
| 36 | this.refType = refType; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns the refType for RefType. |
| 41 | * @return the refType |
| 42 | */ |
| 43 | public String refType() { |
| 44 | return refType; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | private final String refTable; |
| 49 | private final String refType; |
| 50 | |
| 51 | /** |
| 52 | * Constructs a UuidBaseType object. |
| 53 | */ |
| 54 | public UuidBaseType() { |
| 55 | this.refTable = null; |
| 56 | this.refType = RefType.STRONG.refType(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Constructs a UuidBaseType object. |
| 61 | * @param refTable refTable constraint |
| 62 | * @param refType refType constraint |
| 63 | */ |
| 64 | public UuidBaseType(String refTable, String refType) { |
| 65 | this.refTable = refTable; |
| 66 | this.refType = refType; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get refTable. |
| 71 | * @return refTable |
| 72 | */ |
| 73 | public String getRefTable() { |
| 74 | return refTable; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get refType. |
| 79 | * @return refType |
| 80 | */ |
| 81 | public String getRefType() { |
| 82 | return refType; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public int hashCode() { |
| 87 | return Objects.hash(refTable, refType); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public boolean equals(Object obj) { |
| 92 | if (this == obj) { |
| 93 | return true; |
| 94 | } |
| 95 | if (obj instanceof UuidBaseType) { |
| 96 | final UuidBaseType other = (UuidBaseType) obj; |
| 97 | return Objects.equals(this.refTable, other.refTable) |
| 98 | && Objects.equals(this.refType, other.refType); |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return toStringHelper(this).add("refTable", refTable) |
| 106 | .add("refType", refType).toString(); |
| 107 | } |
| 108 | } |