blob: 23eb2be70865a657a3333d17df6cbcfa0fb81a3b [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;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23import org.onosproject.ovsdb.rfc.schema.type.ColumnType;
24
25/**
26 * A schema for the column represented by column-schema.
27 */
28public final class ColumnSchema {
29 private final String name;
30 private final ColumnType type;
31
32 /**
33 * Constructs a ColumnSchema object.
34 * @param name the column name
35 * @param columnType the column type
36 */
37 public ColumnSchema(String name, ColumnType columnType) {
lishuai2f197432015-07-31 16:27:58 +080038 checkNotNull(name, "name cannot be null");
39 checkNotNull(columnType, "column type cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080040 this.name = name;
41 this.type = columnType;
42 }
43
44 /**
45 * Returns the name of column.
46 * @return the name of column
47 */
48 public String name() {
49 return name;
50 }
51
52 /**
53 * Returns the type of column.
54 * @return the type of column
55 */
56 public ColumnType type() {
57 return type;
58 }
59
60 @Override
61 public int hashCode() {
62 return Objects.hash(name, type);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof ColumnSchema) {
71 final ColumnSchema other = (ColumnSchema) obj;
72 return Objects.equals(this.name, other.name)
73 && Objects.equals(this.type, other.type);
74 }
75 return false;
76 }
77
78 @Override
79 public String toString() {
80 return toStringHelper(this).add("name", name).add("type", type)
81 .toString();
82 }
83}