blob: d2cce633c86983b207129a61518267693f3f2ee3 [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.notation;
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.ColumnSchema;
24
25import com.fasterxml.jackson.annotation.JsonIgnore;
26
27/**
28 * Column is the basic element of the OpenVswitch database.
29 */
30public final class Column {
31 @JsonIgnore
32 private final ColumnSchema schema;
33 private final Object data;
34
35 /**
36 * Column constructor.
37 * @param schema the column schema
38 * @param obj the data of the column
39 */
40 public Column(ColumnSchema schema, Object obj) {
lishuai2f197432015-07-31 16:27:58 +080041 checkNotNull(schema, "schema cannot be null");
42 checkNotNull(obj, "data cannot be null");
lishuai91d986c2015-07-28 09:45:20 +080043 this.schema = schema;
44 this.data = obj;
45 }
46
47 /**
48 * Returns column data.
49 * @return column data
50 */
51 public Object data() {
52 return data;
53 }
54
55 /**
56 * Returns ColumnSchema.
57 * @return ColumnSchema
58 */
59 public ColumnSchema schema() {
60 return schema;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hash(schema, data);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj instanceof Column) {
74 final Column other = (Column) obj;
75 return Objects.equals(this.schema, other.schema)
76 && Objects.equals(this.data, other.data);
77 }
78 return false;
79 }
80
81 @Override
82 public String toString() {
83 return toStringHelper(this).add("schema", schema).add("data", data)
84 .toString();
85 }
86}