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