Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-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.net.pi.service; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.pi.runtime.PiEntity; |
| 21 | import org.onosproject.net.pi.runtime.PiEntityType; |
| 22 | import org.onosproject.net.pi.runtime.PiHandle; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Representation of the result of a PD-to-PI translation associated to a PI |
| 28 | * entity handle. |
| 29 | */ |
| 30 | @Beta |
| 31 | public final class PiTranslatedEntity<T extends PiTranslatable, E extends PiEntity> { |
| 32 | |
| 33 | private final T original; |
| 34 | private final E translated; |
| 35 | private final PiHandle<E> handle; |
| 36 | |
| 37 | /** |
| 38 | * Creates a new translated entity. |
| 39 | * |
| 40 | * @param original PD entity |
| 41 | * @param translated PI entity |
| 42 | * @param handle PI entity handle |
| 43 | */ |
| 44 | public PiTranslatedEntity(T original, E translated, PiHandle<E> handle) { |
| 45 | this.original = checkNotNull(original); |
| 46 | this.translated = checkNotNull(translated); |
| 47 | this.handle = checkNotNull(handle); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the type of the translated entity. |
| 52 | * |
| 53 | * @return type of the translated entity |
| 54 | */ |
| 55 | public final PiEntityType entityType() { |
| 56 | return translated.piEntityType(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the original PD entity. |
| 61 | * |
| 62 | * @return instance of PI translatable entity |
| 63 | */ |
| 64 | public final T original() { |
| 65 | return original; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the translated PI entity. |
| 70 | * |
| 71 | * @return PI entity |
| 72 | */ |
| 73 | public final E translated() { |
| 74 | return translated; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns the PI entity handle. |
| 79 | * |
| 80 | * @return PI entity handle |
| 81 | */ |
| 82 | public final PiHandle<E> handle() { |
| 83 | return handle; |
| 84 | } |
| 85 | } |