blob: f54cc1d1e62c6cdd76db45f7fdbe889e5748cb0f [file] [log] [blame]
Carmelo Cascone17fc9e42016-05-31 11:29:21 -07001/*
2 * Copyright 2016-present 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
17package org.onosproject.bmv2.api.context;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * A BMv2 device context, defined by a configuration and an interpreter.
27 */
28@Beta
29public final class Bmv2DeviceContext {
30
31 private final Bmv2Configuration configuration;
32 private final Bmv2Interpreter interpreter;
33
34 /**
35 * Creates a new BMv2 device context.
36 *
37 * @param configuration a configuration
38 * @param interpreter an interpreter
39 */
40 public Bmv2DeviceContext(Bmv2Configuration configuration, Bmv2Interpreter interpreter) {
41 this.configuration = checkNotNull(configuration, "configuration cannot be null");
42 this.interpreter = checkNotNull(interpreter, "interpreter cannot be null");
43 }
44
45 /**
46 * Returns the BMv2 configuration of this context.
47 *
48 * @return a configuration
49 */
50 public Bmv2Configuration configuration() {
51 return configuration;
52 }
53
54 /**
55 * Returns the BMv2 interpreter of this context.
56 *
57 * @return an interpreter
58 */
59 public Bmv2Interpreter interpreter() {
60 return interpreter;
61 }
62
63 @Override
64 public int hashCode() {
65 return Objects.hashCode(configuration, interpreter);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73 if (obj == null || getClass() != obj.getClass()) {
74 return false;
75 }
76 final Bmv2DeviceContext other = (Bmv2DeviceContext) obj;
77 return Objects.equal(this.configuration, other.configuration)
78 && Objects.equal(this.interpreter, other.interpreter);
79 }
80
81 @Override
82 public String toString() {
83 return MoreObjects.toStringHelper(this)
84 .add("configuration", configuration)
85 .add("interpreter", interpreter)
86 .toString();
87 }
88}