hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.odtn.utils.tapi; |
| 18 | |
| 19 | import java.util.ArrayList; |
| 20 | import java.util.List; |
| 21 | import java.util.Objects; |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | public final class TapiConnection { |
| 25 | |
| 26 | private TapiCepPair ceps; |
| 27 | private List<TapiConnection> lowerConnections = new ArrayList<>(); |
| 28 | |
| 29 | private TapiConnection(TapiCepPair ceps) { |
| 30 | this.ceps = ceps; |
| 31 | } |
| 32 | |
| 33 | public static TapiConnection create(TapiCepPair ceps) { |
| 34 | return new TapiConnection(ceps); |
| 35 | } |
| 36 | |
| 37 | public static TapiConnection create(TapiCepRef left, TapiCepRef right) { |
| 38 | TapiCepPair cepPair = TapiCepPair.create(left, right); |
| 39 | return new TapiConnection(cepPair); |
| 40 | } |
| 41 | |
| 42 | public TapiCepPair getCeps() { |
| 43 | return ceps; |
| 44 | } |
| 45 | |
| 46 | public List<TapiConnection> getLowerConnections() { |
| 47 | return lowerConnections; |
| 48 | } |
| 49 | |
| 50 | public TapiConnection addLowerConnection(TapiConnection lowerConnection) { |
| 51 | this.lowerConnections.add(lowerConnection); |
| 52 | return this; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String toString() { |
| 57 | return toStringHelper(this) |
| 58 | .add("ceps", ceps) |
| 59 | .add("lowerConnection", lowerConnections) |
| 60 | .toString(); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object o) { |
| 65 | if (this == o) { |
| 66 | return true; |
| 67 | } |
| 68 | if (!(o instanceof TapiConnection)) { |
| 69 | return false; |
| 70 | } |
| 71 | TapiConnection that = (TapiConnection) o; |
| 72 | return Objects.equals(ceps, that.ceps) && |
| 73 | Objects.equals(lowerConnections, that.lowerConnections); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public int hashCode() { |
| 78 | return Objects.hash(ceps, lowerConnections); |
| 79 | } |
| 80 | } |