blob: 9450f392ff754b46545b4a49bfd9268844cedca8 [file] [log] [blame]
Hyunsun Moon89478662016-06-09 17:52:34 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Hyunsun Moon89478662016-06-09 17:52:34 -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 */
16package org.onosproject.net.behaviour;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Strings;
20import org.onosproject.net.AbstractDescription;
21import org.onosproject.net.SparseAnnotations;
22
Ray Milkeyec253f82017-09-20 16:29:19 +090023import java.util.Objects;
Hyunsun Moon89478662016-06-09 17:52:34 -070024import java.util.Optional;
25
26import static com.google.common.base.Preconditions.checkArgument;
27
28/**
29 * Default implementation of immutable patch interface description entity.
30 */
31public final class DefaultPatchDescription extends AbstractDescription
32 implements PatchDescription {
33
34 private final Optional<String> deviceId;
35 private final String ifaceName;
36 private final String peerName;
37
38 private DefaultPatchDescription(Optional<String> deviceId,
39 String ifaceName,
40 String peerName,
41 SparseAnnotations... annotations) {
42 super(annotations);
43 this.deviceId = deviceId;
44 this.ifaceName = ifaceName;
45 this.peerName = peerName;
46 }
47
48
49 @Override
50 public Optional<String> deviceId() {
51 return deviceId;
52 }
53
54 @Override
55 public String ifaceName() {
56 return ifaceName;
57 }
58
59 @Override
60 public String peer() {
61 return peerName;
62 }
63
64 @Override
Ray Milkeyec253f82017-09-20 16:29:19 +090065 public int hashCode() {
66 return Objects.hash(deviceId, ifaceName, peerName);
67 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj instanceof DefaultPatchDescription) {
75 final DefaultPatchDescription that = (DefaultPatchDescription) obj;
76 return this.getClass() == that.getClass() &&
77 Objects.equals(this.deviceId, that.deviceId) &&
78 Objects.equals(this.ifaceName, that.ifaceName) &&
79 Objects.equals(this.peerName, that.peerName);
80 }
81 return false;
82 }
83
84 @Override
Hyunsun Moon89478662016-06-09 17:52:34 -070085 public String toString() {
86 return MoreObjects.toStringHelper(this)
87 .add("deviceId", deviceId)
88 .add("ifaceName", ifaceName)
89 .add("peerName", peerName)
90 .toString();
91 }
92
93 /**
94 * Returns new builder instance.
95 *
96 * @return default patch description builder
97 */
98 public static Builder builder() {
99 return new Builder();
100 }
101
102 public static final class Builder implements PatchDescription.Builder {
103
104 private Optional<String> deviceId = Optional.empty();
105 private String ifaceName;
106 private String peerName;
107
108 private Builder() {
109 }
110
111 @Override
112 public PatchDescription build() {
113 return new DefaultPatchDescription(deviceId, ifaceName, peerName);
114 }
115
116 @Override
117 public PatchDescription.Builder deviceId(String deviceId) {
118 this.deviceId = Optional.ofNullable(deviceId);
119 return this;
120 }
121
122 @Override
123 public PatchDescription.Builder ifaceName(String ifaceName) {
124 checkArgument(!Strings.isNullOrEmpty(ifaceName));
125 this.ifaceName = ifaceName;
126 return this;
127 }
128
129 @Override
130 public PatchDescription.Builder peer(String peerName) {
131 checkArgument(!Strings.isNullOrEmpty(peerName));
132 this.peerName = peerName;
133 return this;
134 }
135 }
136}