Merge changes I14f284cc,I65bfdb56
authorTony Tkacik <ttkacik@cisco.com>
Thu, 10 Oct 2013 10:21:54 +0000 (10:21 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 10 Oct 2013 10:21:54 +0000 (10:21 +0000)
* changes:
  Added support for identity statement.
  Fixed bug in resolving refine statement. (Bug 111)

12 files changed:
concepts/pom.xml
concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractRegistration.java [new file with mode: 0644]
concepts/src/main/java/org/opendaylight/yangtools/concepts/Builder.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/Identifiable.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/Identifier.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/ListenerRegistration.java [new file with mode: 0644]
concepts/src/main/java/org/opendaylight/yangtools/concepts/Mutable.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/Namespace.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/OrderedSet.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/Path.java
concepts/src/main/java/org/opendaylight/yangtools/concepts/Registration.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java

index d7bcfd52c426acb9e86974215c53e66205934106..890c508d9b2573aaac09b66d8e52870f2fba61e3 100644 (file)
@@ -1,22 +1,22 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
-    <parent>
-        <groupId>org.opendaylight.yangtools</groupId>
-        <artifactId>yangtools</artifactId>
-        <version>0.1.1-SNAPSHOT</version>
-    </parent>
-    <packaging>bundle</packaging>
-    <modelVersion>4.0.0</modelVersion>
-    <artifactId>concepts</artifactId>
-    <name>Concepts</name>
-    <description>Java binding for YANG</description>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
-</project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
+\r
+    <parent>\r
+        <groupId>org.opendaylight.yangtools</groupId>\r
+        <artifactId>yangtools</artifactId>\r
+        <version>0.1.1-SNAPSHOT</version>\r
+    </parent>\r
+    <packaging>bundle</packaging>\r
+    <modelVersion>4.0.0</modelVersion>\r
+    <artifactId>concepts</artifactId>\r
+    <name>Concepts</name>\r
+    <description>Java binding for YANG</description>\r
+\r
+    <build>\r
+        <plugins>\r
+            <plugin>\r
+                <groupId>org.apache.felix</groupId>\r
+                <artifactId>maven-bundle-plugin</artifactId>\r
+            </plugin>\r
+        </plugins>\r
+    </build>\r
+</project>\r
diff --git a/concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractRegistration.java b/concepts/src/main/java/org/opendaylight/yangtools/concepts/AbstractRegistration.java
new file mode 100644 (file)
index 0000000..24b43dd
--- /dev/null
@@ -0,0 +1,38 @@
+package org.opendaylight.yangtools.concepts;\r
+\r
+/**\r
+ * Utility registration handle. It is a convenience for register-style method\r
+ * which can return an AutoCloseable realized by a subclass of this class.\r
+ * Invoking the close() method triggers unregistration of the state the method\r
+ * installed.\r
+ */\r
+public abstract class AbstractRegistration<T> implements Registration<T> {\r
+\r
+    private boolean closed = false;\r
+    private final T instance;\r
+\r
+    public AbstractRegistration(T instance) {\r
+        this.instance = instance;\r
+    }\r
+\r
+    @Override\r
+    public T getInstance() {\r
+        return instance;\r
+    }\r
+\r
+    /**\r
+     * Remove the state referenced by this registration. This method is\r
+     * guaranteed to be called at most once. The referenced state must be\r
+     * retained until this method is invoked.\r
+     */\r
+    protected abstract void removeRegistration();\r
+\r
+    @Override\r
+    public void close() throws Exception {\r
+        if (!closed) {\r
+            closed = true;\r
+            removeRegistration();\r
+        }\r
+    }\r
+\r
+}\r
index dd5859d661f7fd9584a6443a2b1afed8a747aa04..df2fe2912583b7cb9c00725cd1e92d9c50334531 100644 (file)
@@ -1,19 +1,19 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts;
-
-/**
- * Builder object which produces a product.
- * 
- * @param <P> Product of builder
- * 
- * @author Tony Tkacik <ttkacik@cisco.com>
- */
-public interface Builder<P> extends Mutable {
-    P toInstance();
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.concepts;\r
+\r
+/**\r
+ * Builder object which produces a product.\r
+ * \r
+ * @param <P> Product of builder\r
+ * \r
+ * @author Tony Tkacik <ttkacik@cisco.com>\r
+ */\r
+public interface Builder<P> extends Mutable {\r
+    P toInstance();\r
+}\r
index aea084c53803e9b3b5b06b3893d6fc081e92d87f..185a2106f143b21f934921ce6463ada036882472 100644 (file)
@@ -1,12 +1,12 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts;
-
-public interface Identifiable<T> {
-    T getIdentifier();
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.concepts;\r
+\r
+public interface Identifiable<T> {\r
+    T getIdentifier();\r
+}\r
index 148865b850cec84120517d8a6451e66072b6d441..715e798a8d227406b3ef57e49b6fd54cbf589e89 100644 (file)
@@ -1,21 +1,21 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts;
-
-import java.io.Serializable;
-
-/**
- * General identifier interface. It is primarily a marker for all things that
- * identify concepts -- such as names, addresses, classes, etc. We do not
- * require too much, just that the identifiers are serializable (and this
- * transferable).
- */
-public interface Identifier extends Serializable, Immutable {
-
-}
-
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.concepts;\r
+\r
+import java.io.Serializable;\r
+\r
+/**\r
+ * General identifier interface. It is primarily a marker for all things that\r
+ * identify concepts -- such as names, addresses, classes, etc. We do not\r
+ * require too much, just that the identifiers are serializable (and this\r
+ * transferable).\r
+ */\r
+public interface Identifier extends Serializable, Immutable {\r
+\r
+}\r
+\r
diff --git a/concepts/src/main/java/org/opendaylight/yangtools/concepts/ListenerRegistration.java b/concepts/src/main/java/org/opendaylight/yangtools/concepts/ListenerRegistration.java
new file mode 100644 (file)
index 0000000..793e03c
--- /dev/null
@@ -0,0 +1,7 @@
+package org.opendaylight.yangtools.concepts;\r
+\r
+import java.util.EventListener;\r
+\r
+public interface ListenerRegistration<T extends EventListener> extends Registration<T> {\r
+\r
+}\r
index 60c10352df54531df49221d6f312319d99b9f6bc..40266a09473a18d00b3759d439b4d3a7dcab5159 100644 (file)
@@ -1,21 +1,21 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts;
-
-/**
- * Mutable object - object may change it's state during lifecycle.
- * 
- * This interface is mutually exclusive with {@link Immutable}  and other
- * {@link MutationBehaviour}s.
- * 
- * @author Tony Tkacik <ttkacik@cisco.com>
- *
- */
-public interface Mutable extends MutationBehaviour<Mutable>{
-    
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.concepts;\r
+\r
+/**\r
+ * Mutable object - object may change it's state during lifecycle.\r
+ * \r
+ * This interface is mutually exclusive with {@link Immutable}  and other\r
+ * {@link MutationBehaviour}s.\r
+ * \r
+ * @author Tony Tkacik <ttkacik@cisco.com>\r
+ *\r
+ */\r
+public interface Mutable extends MutationBehaviour<Mutable>{\r
+    \r
+}\r
index cb759c05c32908614ac2387253e83f1b454b4342..b66c1c3397f63766bdd1273843978845bfb97848 100644 (file)
@@ -1,12 +1,12 @@
-package org.opendaylight.yangtools.concepts;
-
-import java.util.Set;
-
-public interface Namespace<K,V> {
-    
-    V get(K key);
-    
-    Namespace<K,V> getParent();
-    Set<Namespace<K,V>> getSubnamespaces();
-    Namespace<K,V> getSubnamespace(V key);
-}
+package org.opendaylight.yangtools.concepts;\r
+\r
+import java.util.Set;\r
+\r
+public interface Namespace<K,V> {\r
+    \r
+    V get(K key);\r
+    \r
+    Namespace<K,V> getParent();\r
+    Set<Namespace<K,V>> getSubnamespaces();\r
+    Namespace<K,V> getSubnamespace(V key);\r
+}\r
index 99745b20033b36dde091d3bc6e9fe593af6188c6..af5c094e054d2356d980b087822f554701c4b632 100644 (file)
@@ -1,9 +1,9 @@
-package org.opendaylight.yangtools.concepts;
-import java.util.List;
-import java.util.Set;
-
-
-public interface OrderedSet<E> extends Set<E>,List<E> {
-
-    
-}
+package org.opendaylight.yangtools.concepts;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+\r
+public interface OrderedSet<E> extends Set<E>,List<E> {\r
+\r
+    \r
+}\r
index d73326432d5f97eb6d2279e91de3b9c80cc7fd5d..1da31e858ba6c31e782bd81d99954b623a3815fd 100644 (file)
@@ -1,13 +1,13 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts;
-
-public interface Path<P extends Path<P>> {
-
-    boolean contains(P other);
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.concepts;\r
+\r
+public interface Path<P extends Path<P>> {\r
+\r
+    boolean contains(P other);\r
+}\r
index f6b842421ad247e4c160bab932651652354ba7e8..369ff5366401408dc0deaba35fc22315f1c2cee2 100644 (file)
@@ -1,14 +1,20 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.concepts;
-
-public interface Registration<T> {
-
-    T getInstance();
-    void unregister();
-}
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.yangtools.concepts;\r
+\r
+public interface Registration<T> extends AutoCloseable {\r
+\r
+    T getInstance();\r
+\r
+    /**\r
+     * Unregisters object\r
+     * \r
+     */\r
+    @Override\r
+    public void close() throws Exception;\r
+}\r
index 01ec40381512c99d0129781dcd872ceb6f52547c..62cbb45b93f6bcaecf5b23e6029f75d1cbf937e5 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.binding;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.opendaylight.yangtools.concepts.Builder;\r
-import org.opendaylight.yangtools.concepts.Immutable;\r
-import org.opendaylight.yangtools.concepts.Path;\r
-\r
-/**\r
- * Uniquely identifies data location in the overall of data tree \r
- * modeled by YANG.\r
- * \r
- * \r
- */\r
-public final class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<?>>,Immutable {\r
-\r
-    private final List<PathArgument> path;\r
-    private final Class<T> targetType;\r
-    \r
-    public InstanceIdentifier(Class<T> type) {\r
-        path = Collections.<PathArgument> singletonList(new Item<>(type));\r
-        this.targetType = type;\r
-    }\r
-\r
-    public InstanceIdentifier(List<PathArgument> path, Class<T> type) {\r
-        this.path = Collections.<PathArgument> unmodifiableList(new ArrayList<>(path));\r
-        this.targetType = type;\r
-    }\r
-\r
-    /**\r
-     * \r
-     * @return path\r
-     */\r
-    public List<PathArgument> getPath() {\r
-        return this.path;\r
-    }\r
-\r
-    public Class<T> getTargetType() {\r
-        return this.targetType;\r
-    }\r
-\r
-    @Override\r
-    public String toString() {\r
-        return "InstanceIdentifier [path=" + path + "]";\r
-    }\r
-\r
-    /**\r
-     * Path argument of {@link InstanceIdentifier}.\r
-     * <p>\r
-     * Interface which implementations are used as path components of the\r
-     * path in overall data tree.\r
-     *\r
-     */\r
-    public interface PathArgument {\r
-\r
-        Class<? extends DataObject> getType();\r
-\r
-    }\r
-\r
-    public static final class Item<T extends DataObject> implements PathArgument {\r
-        private final Class<T> type;\r
-\r
-        public Item(Class<T> type) {\r
-            this.type = type;\r
-        }\r
-\r
-        public Class<T> getType() {\r
-            return type;\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + ((type == null) ? 0 : type.hashCode());\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (getClass() != obj.getClass())\r
-                return false;\r
-            Item<?> other = (Item<?>) obj;\r
-            if (type == null) {\r
-                if (other.type != null)\r
-                    return false;\r
-            } else if (!type.equals(other.type))\r
-                return false;\r
-            return true;\r
-        }\r
-        \r
-        @Override\r
-        public String toString() {\r
-            return type.getName();\r
-        }\r
-    }\r
-\r
-    public static final class IdentifiableItem<I extends Identifiable<T> & DataObject, T extends Identifier<I>> implements\r
-            PathArgument {\r
-\r
-        private final T key;\r
-        private final Class<I> type;\r
-\r
-        public IdentifiableItem(Class<I> type, T key) {\r
-            if (type == null)\r
-                throw new IllegalArgumentException("Type must not be null.");\r
-            if (key == null)\r
-                throw new IllegalArgumentException("Key must not be null.");\r
-            this.type = type;\r
-            this.key = key;\r
-        }\r
-\r
-        T getKey() {\r
-            return this.key;\r
-        }\r
-\r
-        @Override\r
-        public Class<I> getType() {\r
-            return this.type;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (obj == null) {\r
-                return false;\r
-            }\r
-            if (obj.hashCode() != hashCode()) {\r
-                return false;\r
-            }\r
-            if (!(obj instanceof IdentifiableItem<?, ?>)) {\r
-                return false;\r
-            }\r
-            IdentifiableItem<?, ?> foreign = (IdentifiableItem<?, ?>) obj;\r
-            return key.equals(foreign.getKey());\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            return key.hashCode();\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            return type.getName() + "[key=" + key + "]";\r
-        }\r
-    }\r
-\r
-    public interface InstanceIdentifierBuilder<T extends DataObject> extends Builder<InstanceIdentifier<T>> {\r
-\r
-        <N extends DataObject> InstanceIdentifierBuilder<N> node(Class<N> container);\r
-\r
-        <N extends Identifiable<K> & DataObject, K extends Identifier<N>> InstanceIdentifierBuilder<N> node(\r
-                Class<N> listItem, K listKey);\r
-\r
-        <N extends ChildOf<? super T>> InstanceIdentifierBuilder<N> child(Class<N> container);\r
-        \r
-        <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> InstanceIdentifierBuilder<N> child(\r
-                Class<N> listItem, K listKey);\r
-\r
-    }\r
-\r
-    @SuppressWarnings("rawtypes")\r
-    public static InstanceIdentifierBuilder<?> builder() {\r
-        return new BuilderImpl();\r
-    }\r
-\r
-    @SuppressWarnings({ "rawtypes", "unchecked" })\r
-    public static InstanceIdentifierBuilder<?> builder(InstanceIdentifier<?> basePath) {\r
-        return new BuilderImpl(basePath.path,basePath.targetType);\r
-    }\r
-\r
-    private static final class BuilderImpl<T extends DataObject> implements InstanceIdentifierBuilder<T> {\r
-\r
-        private List<PathArgument> path;\r
-        private Class<? extends DataObject> target = null;\r
-\r
-        public BuilderImpl() {\r
-            this.path = new ArrayList<>();\r
-        }\r
-        \r
-\r
-        public BuilderImpl(List<? extends PathArgument> prefix,Class<? extends DataObject> target) {\r
-            this.path = new ArrayList<>(prefix);\r
-            this.target = target;\r
-        }\r
-\r
-        @SuppressWarnings({ "unchecked", "rawtypes" })\r
-        @Override\r
-        public InstanceIdentifier<T> toInstance() {\r
-            List<PathArgument> immutablePath = Collections.unmodifiableList(new ArrayList<PathArgument>(path));\r
-            return new InstanceIdentifier(immutablePath, target);\r
-        }\r
-\r
-        @Override\r
-        @SuppressWarnings("unchecked")\r
-        public <N extends DataObject> InstanceIdentifierBuilder<N> node(Class<N> container) {\r
-            target = container;\r
-            path.add(new Item<N>(container));\r
-            return (InstanceIdentifierBuilder<N>) this;\r
-        }\r
-\r
-        @Override\r
-        @SuppressWarnings("unchecked")\r
-        public <N extends DataObject & Identifiable<K> , K extends Identifier<N>> InstanceIdentifierBuilder<N> node(\r
-                Class<N> listItem, K listKey) {\r
-            target = listItem;\r
-            path.add(new IdentifiableItem<N, K>(listItem, listKey));\r
-            return (InstanceIdentifierBuilder<N>) this;\r
-        }\r
-        \r
-        @Override\r
-        public <N extends ChildOf<? super T>> InstanceIdentifierBuilder<N> child(Class<N> container) {\r
-            return node(container);\r
-        }\r
-        \r
-        @Override\r
-        public <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> InstanceIdentifierBuilder<N> child(\r
-                Class<N> listItem, K listKey) {\r
-            return node(listItem,listKey);\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        final int prime = 31;\r
-        int result = 1;\r
-        result = prime * result + ((path == null) ? 0 : path.hashCode());\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj) {\r
-            return true;\r
-        }\r
-        if (obj == null) {\r
-            return false;\r
-        }\r
-        if (getClass() != obj.getClass()) {\r
-            return false;\r
-        }\r
-        InstanceIdentifier<?> other = (InstanceIdentifier<?>) obj;\r
-        if (path == null) {\r
-            if (other.path != null) {\r
-                return false;\r
-            }\r
-        } else if (!path.equals(other.path)) {\r
-            return false;\r
-        }\r
-        return true;\r
-    }\r
-\r
-    @Override\r
-    public boolean contains(final InstanceIdentifier<?> other) {\r
-        if(other == null) {\r
-            throw new IllegalArgumentException("other should not be null");\r
-        }\r
-        final int localSize = this.path.size();\r
-        final List<PathArgument> otherPath = other.getPath();\r
-        if(localSize > other.path.size()) {\r
-            return false;\r
-        }\r
-        for(int i = 0;i<localSize;i++ ) {\r
-            if(!path.get(i).equals(otherPath.get(i))) {\r
-                return false;\r
-            }\r
-        }\r
-        \r
-        return true;\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.binding;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.concepts.Path;
+
+/**
+ * Uniquely identifies data location in the overall of data tree 
+ * modeled by YANG.
+ * 
+ * 
+ */
+public final class InstanceIdentifier<T extends DataObject> implements Path<InstanceIdentifier<?>>,Immutable {
+
+    private final List<PathArgument> path;
+    private final Class<T> targetType;
+    
+    public InstanceIdentifier(Class<T> type) {
+        path = Collections.<PathArgument> singletonList(new Item<>(type));
+        this.targetType = type;
+    }
+
+    public InstanceIdentifier(List<PathArgument> path, Class<T> type) {
+        this.path = Collections.<PathArgument> unmodifiableList(new ArrayList<>(path));
+        this.targetType = type;
+    }
+
+    /**
+     * 
+     * @return path
+     */
+    public List<PathArgument> getPath() {
+        return this.path;
+    }
+
+    public Class<T> getTargetType() {
+        return this.targetType;
+    }
+
+    @Override
+    public String toString() {
+        return "InstanceIdentifier [path=" + path + "]";
+    }
+
+    /**
+     * Path argument of {@link InstanceIdentifier}.
+     * <p>
+     * Interface which implementations are used as path components of the
+     * path in overall data tree.
+     *
+     */
+    public interface PathArgument {
+
+        Class<? extends DataObject> getType();
+
+    }
+
+    public static final class Item<T extends DataObject> implements PathArgument {
+        private final Class<T> type;
+
+        public Item(Class<T> type) {
+            this.type = type;
+        }
+
+        public Class<T> getType() {
+            return type;
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((type == null) ? 0 : type.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            Item<?> other = (Item<?>) obj;
+            if (type == null) {
+                if (other.type != null)
+                    return false;
+            } else if (!type.equals(other.type))
+                return false;
+            return true;
+        }
+        
+        @Override
+        public String toString() {
+            return type.getName();
+        }
+    }
+
+    public static final class IdentifiableItem<I extends Identifiable<T> & DataObject, T extends Identifier<I>> implements
+            PathArgument {
+
+        private final T key;
+        private final Class<I> type;
+
+        public IdentifiableItem(Class<I> type, T key) {
+            if (type == null)
+                throw new IllegalArgumentException("Type must not be null.");
+            if (key == null)
+                throw new IllegalArgumentException("Key must not be null.");
+            this.type = type;
+            this.key = key;
+        }
+
+        public T getKey() {
+            return this.key;
+        }
+
+        @Override
+        public Class<I> getType() {
+            return this.type;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            }
+            if (obj.hashCode() != hashCode()) {
+                return false;
+            }
+            if (!(obj instanceof IdentifiableItem<?, ?>)) {
+                return false;
+            }
+            IdentifiableItem<?, ?> foreign = (IdentifiableItem<?, ?>) obj;
+            return key.equals(foreign.getKey());
+        }
+
+        @Override
+        public int hashCode() {
+            return key.hashCode();
+        }
+
+        @Override
+        public String toString() {
+            return type.getName() + "[key=" + key + "]";
+        }
+    }
+
+    public interface InstanceIdentifierBuilder<T extends DataObject> extends Builder<InstanceIdentifier<T>> {
+
+        <N extends DataObject> InstanceIdentifierBuilder<N> node(Class<N> container);
+
+        <N extends Identifiable<K> & DataObject, K extends Identifier<N>> InstanceIdentifierBuilder<N> node(
+                Class<N> listItem, K listKey);
+
+        <N extends ChildOf<? super T>> InstanceIdentifierBuilder<N> child(Class<N> container);
+        
+        <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> InstanceIdentifierBuilder<N> child(
+                Class<N> listItem, K listKey);
+
+    }
+
+    @SuppressWarnings("rawtypes")
+    public static InstanceIdentifierBuilder<?> builder() {
+        return new BuilderImpl();
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    public static InstanceIdentifierBuilder<?> builder(InstanceIdentifier<?> basePath) {
+        return new BuilderImpl(basePath.path,basePath.targetType);
+    }
+
+    private static final class BuilderImpl<T extends DataObject> implements InstanceIdentifierBuilder<T> {
+
+        private List<PathArgument> path;
+        private Class<? extends DataObject> target = null;
+
+        public BuilderImpl() {
+            this.path = new ArrayList<>();
+        }
+        
+
+        public BuilderImpl(List<? extends PathArgument> prefix,Class<? extends DataObject> target) {
+            this.path = new ArrayList<>(prefix);
+            this.target = target;
+        }
+
+        @SuppressWarnings({ "unchecked", "rawtypes" })
+        @Override
+        public InstanceIdentifier<T> toInstance() {
+            List<PathArgument> immutablePath = Collections.unmodifiableList(new ArrayList<PathArgument>(path));
+            return new InstanceIdentifier(immutablePath, target);
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public <N extends DataObject> InstanceIdentifierBuilder<N> node(Class<N> container) {
+            target = container;
+            path.add(new Item<N>(container));
+            return (InstanceIdentifierBuilder<N>) this;
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public <N extends DataObject & Identifiable<K> , K extends Identifier<N>> InstanceIdentifierBuilder<N> node(
+                Class<N> listItem, K listKey) {
+            target = listItem;
+            path.add(new IdentifiableItem<N, K>(listItem, listKey));
+            return (InstanceIdentifierBuilder<N>) this;
+        }
+        
+        @Override
+        public <N extends ChildOf<? super T>> InstanceIdentifierBuilder<N> child(Class<N> container) {
+            return node(container);
+        }
+        
+        @Override
+        public <N extends Identifiable<K> & ChildOf<? super T>, K extends Identifier<N>> InstanceIdentifierBuilder<N> child(
+                Class<N> listItem, K listKey) {
+            return node(listItem,listKey);
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((path == null) ? 0 : path.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        InstanceIdentifier<?> other = (InstanceIdentifier<?>) obj;
+        if (path == null) {
+            if (other.path != null) {
+                return false;
+            }
+        } else if (!path.equals(other.path)) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public boolean contains(final InstanceIdentifier<?> other) {
+        if(other == null) {
+            throw new IllegalArgumentException("other should not be null");
+        }
+        final int localSize = this.path.size();
+        final List<PathArgument> otherPath = other.getPath();
+        if(localSize > other.path.size()) {
+            return false;
+        }
+        for(int i = 0;i<localSize;i++ ) {
+            if(!path.get(i).equals(otherPath.get(i))) {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+}