Sho SHIMIZU

Refactor: Rename Resource#isTypeOf() to isSubTypeOf()

Change-Id: I83eed95d53ecc06cd14695cae22bd4e71646040a
......@@ -73,12 +73,12 @@ public final class ContinuousResource implements Resource {
}
@Override
public boolean isTypeOf(Class<?> ancestorType) {
public boolean isSubTypeOf(Class<?> ancestor) {
String typeName = (String) id.components().get(id.components().size() - 1);
boolean foundInLeaf = typeName.equals(ancestorType.getCanonicalName());
boolean foundInLeaf = typeName.equals(ancestor.getCanonicalName());
boolean foundInAncestor = id.components().subList(0, id.components().size()).stream()
.map(Object::getClass)
.filter(x -> x.equals(ancestorType))
.filter(x -> x.equals(ancestor))
.findAny()
.isPresent();
return foundInAncestor || foundInLeaf;
......
......@@ -63,10 +63,10 @@ public final class DiscreteResource implements Resource {
}
@Override
public boolean isTypeOf(Class<?> ancestorType) {
public boolean isSubTypeOf(Class<?> ancestor) {
return id.components().stream()
.map(Object::getClass)
.filter(x -> x.equals(ancestorType))
.filter(x -> x.equals(ancestor))
.findAny()
.isPresent();
}
......
......@@ -48,13 +48,12 @@ public interface Resource {
ResourceId id();
/**
* Checks if the type of this instance is the specified type.
* Checks if the type of this instance is the sub-type of the specified type.
*
* @param ancestorType type of resource to be checked.
* @param ancestor type of resource to be checked.
* @return true if this resource is under the resource whose type is the given type.
*/
// TODO: find more proper name
boolean isTypeOf(Class<?> ancestorType);
boolean isSubTypeOf(Class<?> ancestor);
/**
* Returns the volume of this resource.
......
......@@ -90,18 +90,18 @@ public class ResourceTest {
}
@Test
public void testTypeOf() {
public void testSubTypeOf() {
DiscreteResource discrete = Resources.discrete(D1, P1, VLAN1).resource();
assertThat(discrete.isTypeOf(DeviceId.class), is(true));
assertThat(discrete.isTypeOf(PortNumber.class), is(true));
assertThat(discrete.isTypeOf(VlanId.class), is(true));
assertThat(discrete.isTypeOf(Bandwidth.class), is(false));
assertThat(discrete.isSubTypeOf(DeviceId.class), is(true));
assertThat(discrete.isSubTypeOf(PortNumber.class), is(true));
assertThat(discrete.isSubTypeOf(VlanId.class), is(true));
assertThat(discrete.isSubTypeOf(Bandwidth.class), is(false));
ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps());
assertThat(continuous.isTypeOf(DeviceId.class), is(true));
assertThat(continuous.isTypeOf(PortNumber.class), is(true));
assertThat(continuous.isTypeOf(Bandwidth.class), is(true));
assertThat(continuous.isTypeOf(VlanId.class), is(false));
assertThat(continuous.isSubTypeOf(DeviceId.class), is(true));
assertThat(continuous.isSubTypeOf(PortNumber.class), is(true));
assertThat(continuous.isSubTypeOf(Bandwidth.class), is(true));
assertThat(continuous.isSubTypeOf(VlanId.class), is(false));
}
@Test
......
......@@ -302,7 +302,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
private class InternalResourceListener implements ResourceListener {
@Override
public void event(ResourceEvent event) {
if (event.subject().isTypeOf(PortNumber.class)) {
if (event.subject().isSubTypeOf(PortNumber.class)) {
executorService.execute(() -> {
if (delegate == null) {
return;
......