blob: 4ca094bec588caed3af99af43cc14670996598b5 [file] [log] [blame]
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -08001/*
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
17package org.onosproject.net.pi.service;
18
19import com.google.common.annotations.Beta;
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080020import org.onosproject.net.pi.runtime.PiEntity;
21import org.onosproject.net.pi.runtime.PiEntityType;
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080022import org.onosproject.net.pi.runtime.PiHandle;
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080023
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080027 * Representation of the result of a PD-to-PI translation associated to a PI
28 * entity handle.
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080029 */
30@Beta
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080031public final class PiTranslatedEntity<T extends PiTranslatable, E extends PiEntity> {
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080032
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080033 private final T original;
34 private final E translated;
35 private final PiHandle<E> handle;
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080036
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080037 /**
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) {
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080045 this.original = checkNotNull(original);
46 this.translated = checkNotNull(translated);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080047 this.handle = checkNotNull(handle);
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080048 }
49
50 /**
51 * Returns the type of the translated entity.
52 *
53 * @return type of the translated entity
54 */
55 public final PiEntityType entityType() {
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080056 return translated.piEntityType();
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080057 }
58
59 /**
60 * Returns the original PD entity.
61 *
62 * @return instance of PI translatable entity
63 */
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080064 public final T original() {
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080065 return original;
66 }
67
68 /**
69 * Returns the translated PI entity.
70 *
71 * @return PI entity
72 */
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080073 public final E translated() {
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080074 return translated;
75 }
76
77 /**
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080078 * Returns the PI entity handle.
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080079 *
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080080 * @return PI entity handle
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080081 */
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080082 public final PiHandle<E> handle() {
83 return handle;
Carmelo Cascone1a7e4f92017-11-20 23:04:02 -080084 }
85}