Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 17 | |
Simon Hunt | 191c84a | 2015-08-21 08:24:48 -0700 | [diff] [blame^] | 18 | package org.onosproject.ui.topo; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 19 | |
| 20 | import org.onosproject.net.Link; |
| 21 | import org.onosproject.net.LinkKey; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 22 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 26 | * Representation of a link and its inverse, as a partial implementation. |
| 27 | * <p> |
| 28 | * Subclasses will decide how to generate the link highlighting (coloring |
| 29 | * and labeling) for the topology view. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 30 | */ |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 31 | public abstract class BiLink { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 32 | |
| 33 | private final LinkKey key; |
| 34 | private final Link one; |
| 35 | private Link two; |
| 36 | |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 37 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 38 | * Constructs a bi-link for the given key and initial link. It is expected |
| 39 | * that the caller will have used {@link TopoUtils#canonicalLinkKey(Link)} |
| 40 | * to generate the key. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 41 | * |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 42 | * @param key canonical key for this bi-link |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 43 | * @param link first link |
| 44 | */ |
| 45 | public BiLink(LinkKey key, Link link) { |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 46 | this.key = checkNotNull(key); |
| 47 | this.one = checkNotNull(link); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 51 | * Sets the second link for this bi-link. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 52 | * |
| 53 | * @param link second link |
| 54 | */ |
| 55 | public void setOther(Link link) { |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 56 | this.two = checkNotNull(link); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 60 | * Returns the link identifier in the form expected on the Topology View |
| 61 | * in the web client. |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 62 | * |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 63 | * @return link identifier |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 64 | */ |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 65 | public String linkId() { |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 66 | return TopoUtils.compactLinkString(one); |
| 67 | } |
| 68 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Returns the key for this bi-link. |
| 71 | * |
| 72 | * @return the key |
| 73 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 74 | public LinkKey key() { |
| 75 | return key; |
| 76 | } |
| 77 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 78 | /** |
| 79 | * Returns the first link in this bi-link. |
| 80 | * |
| 81 | * @return the first link |
| 82 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 83 | public Link one() { |
| 84 | return one; |
| 85 | } |
| 86 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Returns the second link in this bi-link. |
| 89 | * |
| 90 | * @return the second link |
| 91 | */ |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 92 | public Link two() { |
| 93 | return two; |
| 94 | } |
| 95 | |
Simon Hunt | 4fc8685 | 2015-08-20 17:57:52 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Returns the link highlighting to use, based on this bi-link's current |
| 98 | * state. |
| 99 | * |
| 100 | * @param type optional highlighting type parameter |
| 101 | * @return link highlighting model |
| 102 | */ |
| 103 | public abstract LinkHighlight highlight(Enum<?> type); |
Simon Hunt | a17fa67 | 2015-08-19 18:42:22 -0700 | [diff] [blame] | 104 | } |