Sho SHIMIZU

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

Change-Id: I83eed95d53ecc06cd14695cae22bd4e71646040a
...@@ -73,12 +73,12 @@ public final class ContinuousResource implements Resource { ...@@ -73,12 +73,12 @@ public final class ContinuousResource implements Resource {
73 } 73 }
74 74
75 @Override 75 @Override
76 - public boolean isTypeOf(Class<?> ancestorType) { 76 + public boolean isSubTypeOf(Class<?> ancestor) {
77 String typeName = (String) id.components().get(id.components().size() - 1); 77 String typeName = (String) id.components().get(id.components().size() - 1);
78 - boolean foundInLeaf = typeName.equals(ancestorType.getCanonicalName()); 78 + boolean foundInLeaf = typeName.equals(ancestor.getCanonicalName());
79 boolean foundInAncestor = id.components().subList(0, id.components().size()).stream() 79 boolean foundInAncestor = id.components().subList(0, id.components().size()).stream()
80 .map(Object::getClass) 80 .map(Object::getClass)
81 - .filter(x -> x.equals(ancestorType)) 81 + .filter(x -> x.equals(ancestor))
82 .findAny() 82 .findAny()
83 .isPresent(); 83 .isPresent();
84 return foundInAncestor || foundInLeaf; 84 return foundInAncestor || foundInLeaf;
......
...@@ -63,10 +63,10 @@ public final class DiscreteResource implements Resource { ...@@ -63,10 +63,10 @@ public final class DiscreteResource implements Resource {
63 } 63 }
64 64
65 @Override 65 @Override
66 - public boolean isTypeOf(Class<?> ancestorType) { 66 + public boolean isSubTypeOf(Class<?> ancestor) {
67 return id.components().stream() 67 return id.components().stream()
68 .map(Object::getClass) 68 .map(Object::getClass)
69 - .filter(x -> x.equals(ancestorType)) 69 + .filter(x -> x.equals(ancestor))
70 .findAny() 70 .findAny()
71 .isPresent(); 71 .isPresent();
72 } 72 }
......
...@@ -48,13 +48,12 @@ public interface Resource { ...@@ -48,13 +48,12 @@ public interface Resource {
48 ResourceId id(); 48 ResourceId id();
49 49
50 /** 50 /**
51 - * Checks if the type of this instance is the specified type. 51 + * Checks if the type of this instance is the sub-type of the specified type.
52 * 52 *
53 - * @param ancestorType type of resource to be checked. 53 + * @param ancestor type of resource to be checked.
54 * @return true if this resource is under the resource whose type is the given type. 54 * @return true if this resource is under the resource whose type is the given type.
55 */ 55 */
56 - // TODO: find more proper name 56 + boolean isSubTypeOf(Class<?> ancestor);
57 - boolean isTypeOf(Class<?> ancestorType);
58 57
59 /** 58 /**
60 * Returns the volume of this resource. 59 * Returns the volume of this resource.
......
...@@ -90,18 +90,18 @@ public class ResourceTest { ...@@ -90,18 +90,18 @@ public class ResourceTest {
90 } 90 }
91 91
92 @Test 92 @Test
93 - public void testTypeOf() { 93 + public void testSubTypeOf() {
94 DiscreteResource discrete = Resources.discrete(D1, P1, VLAN1).resource(); 94 DiscreteResource discrete = Resources.discrete(D1, P1, VLAN1).resource();
95 - assertThat(discrete.isTypeOf(DeviceId.class), is(true)); 95 + assertThat(discrete.isSubTypeOf(DeviceId.class), is(true));
96 - assertThat(discrete.isTypeOf(PortNumber.class), is(true)); 96 + assertThat(discrete.isSubTypeOf(PortNumber.class), is(true));
97 - assertThat(discrete.isTypeOf(VlanId.class), is(true)); 97 + assertThat(discrete.isSubTypeOf(VlanId.class), is(true));
98 - assertThat(discrete.isTypeOf(Bandwidth.class), is(false)); 98 + assertThat(discrete.isSubTypeOf(Bandwidth.class), is(false));
99 99
100 ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); 100 ContinuousResource continuous = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps());
101 - assertThat(continuous.isTypeOf(DeviceId.class), is(true)); 101 + assertThat(continuous.isSubTypeOf(DeviceId.class), is(true));
102 - assertThat(continuous.isTypeOf(PortNumber.class), is(true)); 102 + assertThat(continuous.isSubTypeOf(PortNumber.class), is(true));
103 - assertThat(continuous.isTypeOf(Bandwidth.class), is(true)); 103 + assertThat(continuous.isSubTypeOf(Bandwidth.class), is(true));
104 - assertThat(continuous.isTypeOf(VlanId.class), is(false)); 104 + assertThat(continuous.isSubTypeOf(VlanId.class), is(false));
105 } 105 }
106 106
107 @Test 107 @Test
......
...@@ -302,7 +302,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { ...@@ -302,7 +302,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
302 private class InternalResourceListener implements ResourceListener { 302 private class InternalResourceListener implements ResourceListener {
303 @Override 303 @Override
304 public void event(ResourceEvent event) { 304 public void event(ResourceEvent event) {
305 - if (event.subject().isTypeOf(PortNumber.class)) { 305 + if (event.subject().isSubTypeOf(PortNumber.class)) {
306 executorService.execute(() -> { 306 executorService.execute(() -> {
307 if (delegate == null) { 307 if (delegate == null) {
308 return; 308 return;
......