mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 09:51:38 +02:00
Add Optional version of projecting Behaviour
Change-Id: I3d3411763be1a75a2bdb04fb59c70d9779f1b02a
This commit is contained in:
parent
611a065631
commit
4bec2f3923
@ -73,13 +73,7 @@ public class OpticalDeviceServiceView
|
|||||||
= CacheBuilder.newBuilder()
|
= CacheBuilder.newBuilder()
|
||||||
.weakKeys() // == for Key comparison
|
.weakKeys() // == for Key comparison
|
||||||
.maximumSize(100)
|
.maximumSize(100)
|
||||||
.build(CacheLoader.from(elm -> {
|
.build(CacheLoader.from(elm -> elm.project(OpticalDevice.class)));
|
||||||
if (elm.is(OpticalDevice.class)) {
|
|
||||||
return Optional.of(elm.as(OpticalDevice.class));
|
|
||||||
} else {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Not intended to be instantiated directly
|
// Not intended to be instantiated directly
|
||||||
protected OpticalDeviceServiceView(DeviceService base) {
|
protected OpticalDeviceServiceView(DeviceService base) {
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.onosproject.net.driver;
|
package org.onosproject.net.driver;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,4 +48,20 @@ public interface Projectable {
|
|||||||
*/
|
*/
|
||||||
<B extends Behaviour> boolean is(Class<B> projectionClass);
|
<B extends Behaviour> boolean is(Class<B> projectionClass);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the specified projection of this entity if such projection
|
||||||
|
* is supported.
|
||||||
|
*
|
||||||
|
* @param projectionClass requested projection class
|
||||||
|
* @param <B> type of behaviour
|
||||||
|
* @return projection instance
|
||||||
|
*/
|
||||||
|
default <B extends Behaviour> Optional<B> project(Class<B> projectionClass) {
|
||||||
|
if (is(projectionClass)) {
|
||||||
|
return Optional.of(as(projectionClass));
|
||||||
|
} else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user