blob: 8d13c68cac586c30fc8371bd6e548b48623f90cc [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
23import java.util.Optional;
24
25import static com.google.common.base.Preconditions.checkArgument;
26
27/**
28 * Default implementation of immutable patch interface description entity.
29 */
30public final class DefaultPatchDescription extends AbstractDescription
31 implements PatchDescription {
32
33 private final Optional<String> deviceId;
34 private final String ifaceName;
35 private final String peerName;
36
37 private DefaultPatchDescription(Optional<String> deviceId,
38 String ifaceName,
39 String peerName,
40 SparseAnnotations... annotations) {
41 super(annotations);
42 this.deviceId = deviceId;
43 this.ifaceName = ifaceName;
44 this.peerName = peerName;
45 }
46
47
48 @Override
49 public Optional<String> deviceId() {
50 return deviceId;
51 }
52
53 @Override
54 public String ifaceName() {
55 return ifaceName;
56 }
57
58 @Override
59 public String peer() {
60 return peerName;
61 }
62
63 @Override
64 public String toString() {
65 return MoreObjects.toStringHelper(this)
66 .add("deviceId", deviceId)
67 .add("ifaceName", ifaceName)
68 .add("peerName", peerName)
69 .toString();
70 }
71
72 /**
73 * Returns new builder instance.
74 *
75 * @return default patch description builder
76 */
77 public static Builder builder() {
78 return new Builder();
79 }
80
81 public static final class Builder implements PatchDescription.Builder {
82
83 private Optional<String> deviceId = Optional.empty();
84 private String ifaceName;
85 private String peerName;
86
87 private Builder() {
88 }
89
90 @Override
91 public PatchDescription build() {
92 return new DefaultPatchDescription(deviceId, ifaceName, peerName);
93 }
94
95 @Override
96 public PatchDescription.Builder deviceId(String deviceId) {
97 this.deviceId = Optional.ofNullable(deviceId);
98 return this;
99 }
100
101 @Override
102 public PatchDescription.Builder ifaceName(String ifaceName) {
103 checkArgument(!Strings.isNullOrEmpty(ifaceName));
104 this.ifaceName = ifaceName;
105 return this;
106 }
107
108 @Override
109 public PatchDescription.Builder peer(String peerName) {
110 checkArgument(!Strings.isNullOrEmpty(peerName));
111 this.peerName = peerName;
112 return this;
113 }
114 }
115}