lishuai | fa7013d | 2015-08-10 19:35:10 +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.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.Collection;
|
| 22 | import java.util.Map;
|
| 23 | import java.util.Objects;
|
| 24 |
|
| 25 | import com.google.common.collect.Maps;
|
| 26 |
|
| 27 | /**
|
| 28 | * Row is the basic element of the OpenVswitch's table.
|
| 29 | */
|
| 30 | public final class Row {
|
| 31 | private String tableName;
|
| 32 | private Map<String, Column> columns;
|
| 33 |
|
| 34 | /**
|
| 35 | * Row constructor.
|
| 36 | */
|
| 37 | public Row() {
|
| 38 | this.columns = Maps.newHashMap();
|
| 39 | }
|
| 40 |
|
| 41 | /**
|
| 42 | * Row constructor.
|
| 43 | * @param tableName table name
|
| 44 | */
|
| 45 | public Row(String tableName) {
|
| 46 | checkNotNull(tableName, "tableName cannot be null");
|
| 47 | this.tableName = tableName;
|
| 48 | this.columns = Maps.newHashMap();
|
| 49 | }
|
| 50 |
|
| 51 | /**
|
| 52 | * Row constructor.
|
| 53 | * @param tableName table name
|
| 54 | * @param columns Map of Column entity
|
| 55 | */
|
| 56 | public Row(String tableName, Map<String, Column> columns) {
|
| 57 | checkNotNull(tableName, "table name cannot be null");
|
| 58 | checkNotNull(columns, "columns cannot be null");
|
| 59 | this.tableName = tableName;
|
| 60 | this.columns = columns;
|
| 61 | }
|
| 62 |
|
| 63 | /**
|
| 64 | * Returns tableName.
|
| 65 | * @return tableName
|
| 66 | */
|
| 67 | public String tableName() {
|
| 68 | return tableName;
|
| 69 | }
|
| 70 |
|
| 71 | /**
|
| 72 | * Set tableName value.
|
| 73 | * @param tableName table name
|
| 74 | */
|
| 75 | public void setTableName(String tableName) {
|
| 76 | this.tableName = tableName;
|
| 77 | }
|
| 78 |
|
| 79 | /**
|
| 80 | * Returns Column by ColumnSchema.
|
| 81 | * @param columnName column name
|
| 82 | * @return Column
|
| 83 | */
|
| 84 | public Column getColumn(String columnName) {
|
| 85 | return columns.get(columnName);
|
| 86 | }
|
| 87 |
|
| 88 | /**
|
| 89 | * Returns Collection of Column.
|
| 90 | * @return Collection of Column
|
| 91 | */
|
| 92 | public Collection<Column> getColumns() {
|
| 93 | return columns.values();
|
| 94 | }
|
| 95 |
|
| 96 | /**
|
| 97 | * add Column.
|
| 98 | * @param columnName column name
|
| 99 | * @param data Column entity
|
| 100 | */
|
| 101 | public void addColumn(String columnName, Column data) {
|
| 102 | this.columns.put(columnName, data);
|
| 103 | }
|
| 104 |
|
| 105 | @Override
|
| 106 | public int hashCode() {
|
| 107 | return Objects.hash(tableName, columns);
|
| 108 | }
|
| 109 |
|
| 110 | @Override
|
| 111 | public boolean equals(Object obj) {
|
| 112 | if (this == obj) {
|
| 113 | return true;
|
| 114 | }
|
| 115 | if (obj instanceof Row) {
|
| 116 | final Row other = (Row) obj;
|
| 117 | return Objects.equals(this.tableName, other.tableName)
|
| 118 | && Objects.equals(this.columns, other.columns);
|
| 119 | }
|
| 120 | return false;
|
| 121 | }
|
| 122 |
|
| 123 | @Override
|
| 124 | public String toString() {
|
| 125 | return toStringHelper(this).add("tableName", tableName)
|
| 126 | .add("columns", columns).toString();
|
| 127 | }
|
| 128 | }
|