blob: abab008ffad4b238ff5b047146f8b95cb1e84bdf [file] [log] [blame]
Carmelo Cascone5899c132016-04-06 22:09:08 -07001/*
Carmelo Casconeaa8b6292016-04-13 14:27:06 -07002 * Copyright 2016-present Open Networking Laboratory
Carmelo Cascone5899c132016-04-06 22:09:08 -07003 *
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
Carmelo Casconeaa8b6292016-04-13 14:27:06 -070017package org.onosproject.bmv2.api.model;
Carmelo Cascone5899c132016-04-06 22:09:08 -070018
19import com.google.common.base.Objects;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22
23/**
24 * Representation of a BMv2 model header instance.
25 */
26public final class Bmv2ModelHeader {
27
28 private final String name;
29 private final int id;
30 private final Bmv2ModelHeaderType type;
31 private final boolean isMetadata;
32
33 /**
34 * Creates a new header instance.
35 *
36 * @param name name
37 * @param id id
38 * @param type header type
39 * @param metadata if is metadata
40 */
41 protected Bmv2ModelHeader(String name, int id, Bmv2ModelHeaderType type, boolean metadata) {
42 this.name = name;
43 this.id = id;
44 this.type = type;
45 this.isMetadata = metadata;
46 }
47
48 /**
49 * Returns the name of this header instance.
50 *
51 * @return a string value
52 */
53 public String name() {
54 return name;
55 }
56
57 /**
58 * Return the id of this header instance.
59 *
60 * @return an integer value
61 */
62 public int id() {
63 return id;
64 }
65
66 /**
67 * Return the type of this header instance.
68 *
69 * @return a header type value
70 */
71 public Bmv2ModelHeaderType type() {
72 return type;
73 }
74
75 /**
76 * Return true if this header instance is a metadata, false elsewhere.
77 *
78 * @return a boolean value
79 */
80 public boolean isMetadata() {
81 return isMetadata;
82 }
83
84 @Override
85 public int hashCode() {
86 return Objects.hashCode(name, id, type, isMetadata);
87 }
88
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
94 if (obj == null || getClass() != obj.getClass()) {
95 return false;
96 }
97 final Bmv2ModelHeader other = (Bmv2ModelHeader) obj;
98 return Objects.equal(this.name, other.name)
99 && Objects.equal(this.id, other.id)
100 && Objects.equal(this.type, other.type)
101 && Objects.equal(this.isMetadata, other.isMetadata);
102 }
103
104 @Override
105 public String toString() {
106 return toStringHelper(this)
107 .add("name", name)
108 .add("id", id)
109 .add("type", type)
110 .add("isMetadata", isMetadata)
111 .toString();
112 }
113}