blob: 3f7139edec136d23027b6206ddd626e13878dc9b [file] [log] [blame]
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -08003 *
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.driver;
18
Yuta HIGUCHI4bec2f32017-10-27 18:14:29 -070019import java.util.Optional;
20
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -080021import com.google.common.annotations.Beta;
22
23/**
24 * Abstraction of an entity capable of being projected as another entity.
25 */
26@Beta
27public interface Projectable {
28
29 /**
30 * Returns the specified projection of this entity if such projection
31 * is supported.
32 *
33 * @param projectionClass requested projection class
34 * @param <B> type of behaviour
Thomas Vachuskae3ea9a42016-02-10 17:54:59 -080035 * @return projection instance
36 * @throws IllegalStateException if a driver cannot be found
37 * @throws IllegalArgumentException if the projection is not supported
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -080038 */
39 <B extends Behaviour> B as(Class<B> projectionClass);
40
41 /**
42 * Returns true if this entity is capable of being projected as the
43 * specified class.
44 *
Thomas Vachuska3afbc7f2016-02-01 15:55:38 -080045 * @param projectionClass requested projection class
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -080046 * @param <B> type of behaviour
47 * @return true if the requested projection is supported
48 */
49 <B extends Behaviour> boolean is(Class<B> projectionClass);
50
Yuta HIGUCHI4bec2f32017-10-27 18:14:29 -070051 /**
52 * Returns the specified projection of this entity if such projection
53 * is supported.
54 *
55 * @param projectionClass requested projection class
56 * @param <B> type of behaviour
57 * @return projection instance
58 */
59 default <B extends Behaviour> Optional<B> project(Class<B> projectionClass) {
60 if (is(projectionClass)) {
61 return Optional.of(as(projectionClass));
62 } else {
63 return Optional.empty();
64 }
65 }
66
Thomas Vachuska7b3fe3a2016-02-01 11:26:22 -080067}