Sho SHIMIZU | e4efe45 | 2015-08-26 15:06:55 -0700 | [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.notation; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | /** |
| 24 | * Column is the basic element of the OpenVswitch database. |
| 25 | */ |
| 26 | public final class Column { |
| 27 | private final String columnName; |
| 28 | private final Object data; |
| 29 | |
| 30 | /** |
| 31 | * Column constructor. |
| 32 | * @param columnName the column name |
| 33 | * @param obj the data of the column |
| 34 | */ |
| 35 | public Column(String columnName, Object obj) { |
| 36 | checkNotNull(columnName, "columnName cannot be null"); |
| 37 | checkNotNull(obj, "data cannot be null"); |
| 38 | this.columnName = columnName; |
| 39 | this.data = obj; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns column data. |
| 44 | * @return column data |
| 45 | */ |
| 46 | public Object data() { |
| 47 | return data; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns columnName. |
| 52 | * @return columnName |
| 53 | */ |
| 54 | public String columnName() { |
| 55 | return columnName; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public int hashCode() { |
| 60 | return Objects.hash(columnName, data); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object obj) { |
| 65 | if (this == obj) { |
| 66 | return true; |
| 67 | } |
| 68 | if (obj instanceof Column) { |
| 69 | final Column other = (Column) obj; |
| 70 | return Objects.equals(this.columnName, other.columnName) |
| 71 | && Objects.equals(this.data, other.data); |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public String toString() { |
| 78 | return toStringHelper(this).add("columnName", columnName) |
| 79 | .add("data", data).toString(); |
| 80 | } |
| 81 | } |