Refactor Resoruce/ResourceId sub-types

isTypeOf() and isSubTypeOf() of Resource is delegated to ResourceId

Change-Id: Ief39f4967b8fb43ec0cb35dbd44bd2a7dde93680
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ContinuousResourceId.java b/core/api/src/main/java/org/onosproject/net/newresource/ContinuousResourceId.java
index 8a042c8..f372c59 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ContinuousResourceId.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ContinuousResourceId.java
@@ -52,6 +52,23 @@
         return name;
     }
 
+    @Override
+    boolean isTypeOf(Class<?> type) {
+        String typeName = (String) lastComponent();
+        return typeName.equals(type.getCanonicalName());
+    }
+
+    @Override
+    boolean isSubTypeOf(Class<?> ancestor) {
+        String typeName = (String) lastComponent();
+        boolean foundInLeaf = typeName.equals(ancestor.getCanonicalName());
+        boolean foundInAncestor = components.subList(0, components.size()).stream()
+                .filter(x -> ancestor.isAssignableFrom(x.getClass()))
+                .findAny()
+                .isPresent();
+        return foundInAncestor || foundInLeaf;
+    }
+
     /**
      * {@inheritDoc}
      *
@@ -86,6 +103,10 @@
         }
     }
 
+    private Object lastComponent() {
+        return components.get(components.size() - 1);
+    }
+
     @Override
     public int hashCode() {
         return components.hashCode();