You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by ha...@apache.org on 2018/08/15 06:29:40 UTC

[5/5] clerezza git commit: CLEREZZA-1026: Rename impl.utils to api.impl; rename packages within api and api.impl

CLEREZZA-1026: Rename impl.utils to api.impl; rename packages within api and api.impl


Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/d1ee24ce
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/d1ee24ce
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/d1ee24ce

Branch: refs/heads/reunited
Commit: d1ee24ce72a552f2f5d250d13265d5f6d0d9bf61
Parents: e64bd26
Author: Hasan <ha...@apache.org>
Authored: Wed Aug 15 08:28:35 2018 +0200
Committer: Hasan <ha...@apache.org>
Committed: Wed Aug 15 08:28:35 2018 +0200

----------------------------------------------------------------------
 api.impl/pom.xml                                |  80 ++++
 .../apache/clerezza/api/impl/AbstractGraph.java | 307 +++++++++++++++
 .../api/impl/AbstractImmutableGraph.java        | 112 ++++++
 .../clerezza/api/impl/AbstractLiteral.java      |  61 +++
 .../clerezza/api/impl/DelayedNotificator.java   | 113 ++++++
 .../apache/clerezza/api/impl/LiteralImpl.java   |  82 ++++
 .../clerezza/api/impl/LockingIterator.java      |  73 ++++
 .../clerezza/api/impl/PlainLiteralImpl.java     |  80 ++++
 .../apache/clerezza/api/impl/TripleImpl.java    | 100 +++++
 .../clerezza/api/impl/TypedLiteralImpl.java     |  79 ++++
 .../api/impl/WatchableGraphWrapper.java         | 290 ++++++++++++++
 .../clerezza/api/impl/debug/ReadLockDebug.java  |  85 +++++
 .../debug/ReentrantReadWriteLockTracker.java    | 133 +++++++
 .../clerezza/api/impl/debug/WriteLockDebug.java |  89 +++++
 .../api/impl/graphmatching/GraphMatcher.java    | 140 +++++++
 .../GraphNotIsomorphicException.java            |  28 ++
 .../graphmatching/GroupMappingIterator.java     | 101 +++++
 .../api/impl/graphmatching/HashMatching.java    | 268 +++++++++++++
 .../api/impl/graphmatching/MappingIterator.java |  76 ++++
 .../impl/graphmatching/PermutationIterator.java | 107 ++++++
 .../clerezza/api/impl/graphmatching/Utils.java  |  82 ++++
 .../graphmatching/collections/IntHashMap.java   | 377 +++++++++++++++++++
 .../graphmatching/collections/IntHashSet.java   |  62 +++
 .../graphmatching/collections/IntIterator.java  |  30 ++
 .../impl/graphmatching/collections/IntSet.java  |  35 ++
 .../apache/clerezza/api/impl/package-info.java  |  21 ++
 .../clerezza/api/impl/simple/SimpleGraph.java   | 219 +++++++++++
 .../api/impl/simple/SimpleImmutableGraph.java   |  80 ++++
 .../clerezza/api/impl/simple/SimpleMGraph.java  |  56 +++
 .../impl/graphmatching/GraphMatcherTest.java    | 208 ++++++++++
 .../impl/graphmatching/HashMatchingTest.java    |  51 +++
 .../graphmatching/PermutationIteratorTest.java  |  77 ++++
 .../api/impl/graphmatching/Utils4Testing.java   |  51 +++
 .../api/impl/simple/PlainLiteralImplTest.java   |  71 ++++
 .../api/impl/simple/SimpleGraphTest.java        | 109 ++++++
 .../api/impl/simple/TripleImplTest.java         |  57 +++
 .../api/impl/simple/TypedLiteralImplTest.java   |  67 ++++
 api/pom.xml                                     |  38 +-
 .../java/org/apache/clerezza/api/BlankNode.java |  41 ++
 .../org/apache/clerezza/api/BlankNodeOrIRI.java |  30 ++
 .../java/org/apache/clerezza/api/Graph.java     |  86 +++++
 .../main/java/org/apache/clerezza/api/IRI.java  |  83 ++++
 .../org/apache/clerezza/api/ImmutableGraph.java |  55 +++
 .../java/org/apache/clerezza/api/Language.java  |  63 ++++
 .../java/org/apache/clerezza/api/Literal.java   |  93 +++++
 .../java/org/apache/clerezza/api/RDFTerm.java   |  32 ++
 .../java/org/apache/clerezza/api/Triple.java    |  57 +++
 .../org/apache/clerezza/api/WatchableGraph.java |  91 +++++
 .../org/apache/clerezza/api/event/AddEvent.java |  37 ++
 .../apache/clerezza/api/event/FilterTriple.java |  86 +++++
 .../apache/clerezza/api/event/GraphEvent.java   |  59 +++
 .../clerezza/api/event/GraphListener.java       |  43 +++
 .../apache/clerezza/api/event/RemoveEvent.java  |  37 ++
 .../org/apache/clerezza/api/package-info.java   |  21 ++
 .../apache/clerezza/commons/rdf/BlankNode.java  |  41 --
 .../clerezza/commons/rdf/BlankNodeOrIRI.java    |  30 --
 .../org/apache/clerezza/commons/rdf/Graph.java  |  88 -----
 .../org/apache/clerezza/commons/rdf/IRI.java    |  83 ----
 .../clerezza/commons/rdf/ImmutableGraph.java    |  55 ---
 .../apache/clerezza/commons/rdf/Language.java   |  63 ----
 .../apache/clerezza/commons/rdf/Literal.java    |  93 -----
 .../apache/clerezza/commons/rdf/RDFTerm.java    |  32 --
 .../org/apache/clerezza/commons/rdf/Triple.java |  57 ---
 .../clerezza/commons/rdf/WatchableGraph.java    |  94 -----
 .../clerezza/commons/rdf/event/AddEvent.java    |  37 --
 .../commons/rdf/event/FilterTriple.java         |  86 -----
 .../clerezza/commons/rdf/event/GraphEvent.java  |  59 ---
 .../commons/rdf/event/GraphListener.java        |  43 ---
 .../clerezza/commons/rdf/event/RemoveEvent.java |  37 --
 .../clerezza/commons/rdf/package-info.java      |  21 --
 impl.utils/pom.xml                              |  85 -----
 .../commons/rdf/impl/utils/AbstractGraph.java   | 316 ----------------
 .../rdf/impl/utils/AbstractImmutableGraph.java  | 112 ------
 .../commons/rdf/impl/utils/AbstractLiteral.java |  61 ---
 .../rdf/impl/utils/DelayedNotificator.java      | 113 ------
 .../commons/rdf/impl/utils/LiteralImpl.java     |  82 ----
 .../commons/rdf/impl/utils/LockingIterator.java |  73 ----
 .../rdf/impl/utils/PlainLiteralImpl.java        |  80 ----
 .../commons/rdf/impl/utils/TripleImpl.java      | 100 -----
 .../rdf/impl/utils/TypedLiteralImpl.java        |  80 ----
 .../rdf/impl/utils/WatchableGraphWrapper.java   | 289 --------------
 .../rdf/impl/utils/debug/ReadLockDebug.java     |  85 -----
 .../debug/ReentrantReadWriteLockTracker.java    | 133 -------
 .../rdf/impl/utils/debug/WriteLockDebug.java    |  89 -----
 .../impl/utils/graphmatching/GraphMatcher.java  | 140 -------
 .../GraphNotIsomorphicException.java            |  28 --
 .../graphmatching/GroupMappingIterator.java     | 102 -----
 .../impl/utils/graphmatching/HashMatching.java  | 268 -------------
 .../utils/graphmatching/MappingIterator.java    |  76 ----
 .../graphmatching/PermutationIterator.java      | 107 ------
 .../rdf/impl/utils/graphmatching/Utils.java     |  82 ----
 .../graphmatching/collections/IntHashMap.java   | 377 -------------------
 .../graphmatching/collections/IntHashSet.java   |  62 ---
 .../graphmatching/collections/IntIterator.java  |  30 --
 .../utils/graphmatching/collections/IntSet.java |  35 --
 .../commons/rdf/impl/utils/package-info.java    |  21 --
 .../rdf/impl/utils/simple/SimpleGraph.java      | 218 -----------
 .../impl/utils/simple/SimpleImmutableGraph.java |  79 ----
 .../rdf/impl/utils/simple/SimpleMGraph.java     |  57 ---
 .../utils/graphmatching/GraphMatcherTest.java   | 211 -----------
 .../utils/graphmatching/HashMatchingTest.java   |  51 ---
 .../graphmatching/PermutationIteratorTest.java  |  78 ----
 .../impl/utils/graphmatching/Utils4Testing.java |  51 ---
 .../impl/utils/simple/PlainLiteralImplTest.java |  71 ----
 .../rdf/impl/utils/simple/SimpleGraphTest.java  | 109 ------
 .../rdf/impl/utils/simple/TripleImplTest.java   |  57 ---
 .../impl/utils/simple/TypedLiteralImplTest.java |  67 ----
 107 files changed, 4988 insertions(+), 5015 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/pom.xml
----------------------------------------------------------------------
diff --git a/api.impl/pom.xml b/api.impl/pom.xml
new file mode 100644
index 0000000..871beb6
--- /dev/null
+++ b/api.impl/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+-->
+
+<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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    
+    <parent>
+        <groupId>org.apache.clerezza</groupId>
+        <artifactId>clerezza</artifactId>
+        <version>8-SNAPSHOT</version>
+        <relativePath />
+    </parent>
+
+    <artifactId>api.impl</artifactId>
+    <packaging>bundle</packaging>
+    <name>Clerezza API Implementation</name>
+    <description>
+        This module implements Apache Clerezza API
+    </description>
+
+    <issueManagement>
+        <system>jira</system>
+        <url>http://issues.apache.org/jira/browse/CLEREZZA</url>
+    </issueManagement>
+    
+    <inceptionYear>2015</inceptionYear>
+    <scm>
+        <connection>scm:git:https://git-wip-us.apache.org/repos/asf/clerezza.git</connection>
+        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/clerezza.git</developerConnection>
+        <url>https://git-wip-us.apache.org/repos/asf/clerezza.git</url>
+      <tag>HEAD</tag>
+  </scm>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.apache.clerezza.api.impl.*</Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.clerezza</groupId>
+            <artifactId>api</artifactId>
+            <version>8-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java
new file mode 100644
index 0000000..ab236b6
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractGraph.java
@@ -0,0 +1,307 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.util.AbstractCollection;
+import java.util.Collection;
+import java.util.Iterator;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.ImmutableGraph;
+import org.apache.clerezza.api.impl.simple.SimpleImmutableGraph;
+import org.apache.clerezza.api.impl.debug.ReentrantReadWriteLockTracker;
+
+/**
+ * An abstract implementation of <code>Graph</code> implementing
+ * <code>iterator</code> and <code>contains</code> calling <code>filter</code>.
+ *
+ * @author reto
+ */
+public abstract class AbstractGraph extends AbstractCollection<Triple>
+        implements Graph {
+
+    
+    private static final String DEBUG_MODE = "rdfLocksDebugging";
+    private final ReadWriteLock lock;
+
+    private final Lock readLock;
+    private final Lock writeLock;
+
+    /**
+     * Constructs a LocalbleMGraph for an Graph.
+     *
+     * @param providedMGraph a non-lockable graph
+     */
+    public AbstractGraph() {
+        {
+            String debugMode = System.getProperty(DEBUG_MODE);
+            if (debugMode != null && debugMode.toLowerCase().equals("true")) {
+                lock = new ReentrantReadWriteLockTracker();
+            } else {
+                lock = new ReentrantReadWriteLock();
+            }
+        }
+        readLock = lock.readLock();
+        writeLock = lock.writeLock();
+    }
+    
+    public AbstractGraph(final ReadWriteLock lock) {
+        this.lock = lock;
+        readLock = lock.readLock();
+        writeLock = lock.writeLock();
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return lock;
+    }
+
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        readLock.lock();
+        try {
+            return performGetImmutableGraph();
+        } finally {
+            readLock.unlock();
+        }
+    }
+    
+    public ImmutableGraph performGetImmutableGraph() {
+        return new SimpleImmutableGraph(this);
+    }
+
+    @Override
+    public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        readLock.lock();
+        try {
+            return new LockingIterator(performFilter(subject, predicate, object), lock);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public int size() {
+        readLock.lock();
+        try {
+            return performSize();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean isEmpty() {
+        readLock.lock();
+        try {
+            return performIsEmpty();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    @SuppressWarnings("element-type-mismatch")
+    public boolean contains(Object o) {
+        readLock.lock();
+        try {
+            return performContains(o);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public Iterator<Triple> iterator() {
+        readLock.lock();
+        try {
+            return new LockingIterator(performIterator(), lock);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public Object[] toArray() {
+        readLock.lock();
+        try {
+            return performToArray();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public <T> T[] toArray(T[] a) {
+        readLock.lock();
+        try {
+            return performToArray(a);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        readLock.lock();
+        try {
+            return performContainsAll(c);
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        writeLock.lock();
+        try {
+            return performAdd(e);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        writeLock.lock();
+        try {
+            return performRemove(o);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        writeLock.lock();
+        try {
+            return performAddAll(c);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        writeLock.lock();
+        try {
+            return performRemoveAll(c);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        writeLock.lock();
+        try {
+            return performRetainAll(c);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    @Override
+    public void clear() {
+        writeLock.lock();
+        try {
+            performClear();
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+    
+    @Override
+    public boolean equals(Object obj) {
+        /*if (obj == null) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
+        if (obj.getClass() != getClass()) {
+            return false;
+        }*/
+        return this == obj;
+    }
+
+
+    protected abstract Iterator<Triple> performFilter(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+
+    protected abstract int performSize();
+
+    protected boolean performIsEmpty() {
+        return super.isEmpty();
+    }
+
+    protected Object[] performToArray() {
+        return super.toArray();
+    }
+
+    protected boolean performRemove(Object o) {
+        return super.remove(o);
+    }
+
+    protected boolean performAddAll(Collection<? extends Triple> c) {
+        return super.addAll(c);
+    }
+
+    protected boolean performRemoveAll(Collection<?> c) {
+        return super.removeAll(c);
+    }
+
+    protected boolean performRetainAll(Collection<?> c) {
+        return super.retainAll(c);
+    }
+
+    protected void performClear() {
+        super.clear();
+    }
+
+    protected boolean performContains(Object o) {
+        return super.contains(o);
+    }
+
+    protected Iterator<Triple> performIterator() {
+        return performFilter(null, null, null);
+    }
+
+    protected boolean performContainsAll(Collection<?> c) {
+        return super.containsAll(c);
+    }
+
+    protected <T> T[] performToArray(T[] a) {
+        return super.toArray(a);
+    }
+
+    protected boolean performAdd(Triple e) {
+        return super.add(e);
+    }
+
+ 
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java
new file mode 100644
index 0000000..c46f0fc
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractImmutableGraph.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.clerezza.api.impl.graphmatching.GraphMatcher;
+import org.apache.clerezza.api.BlankNode;
+import org.apache.clerezza.api.ImmutableGraph;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+
+/**
+ * <code>AbstractGraph</code> is an abstract implementation of <code>ImmutableGraph</code> 
+ * implementing the <code>equals</code> and the <code>hashCode</code> methods.
+ * 
+ * @author reto
+ * 
+ */
+public abstract class AbstractImmutableGraph extends AbstractGraph
+        implements ImmutableGraph {
+
+    public final synchronized int hashCode() {
+        int result = 0;
+        for (Iterator<Triple> iter = iterator(); iter.hasNext();) {
+            result += getBlankNodeBlindHash(iter.next());
+        }
+        return result;
+    }
+
+    /**
+     * @param triple
+     * @return hash without BNode hashes
+     */
+    private int getBlankNodeBlindHash(Triple triple) {
+        int hash = triple.getPredicate().hashCode();
+        RDFTerm subject = triple.getSubject();
+
+        if (!(subject instanceof BlankNode)) {
+            hash ^= subject.hashCode() >> 1;
+        }
+        RDFTerm object = triple.getObject();
+        if (!(object instanceof BlankNode)) {
+            hash ^= object.hashCode() << 1;
+        }
+
+        return hash;
+    }
+
+    @Override
+    public boolean add(Triple e) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+
+    @Override
+    public void clear() {
+        throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
+    }
+    
+    
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        return this;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof ImmutableGraph)) {
+            return false;
+        }
+        if (hashCode() != obj.hashCode()) {
+            return false;
+        }
+        return GraphMatcher.getValidMapping(this, (ImmutableGraph) obj) != null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java
new file mode 100644
index 0000000..48e3221
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/AbstractLiteral.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import org.apache.clerezza.api.Literal;
+
+/**
+ *
+ * @author developer
+ */
+public abstract class AbstractLiteral implements Literal {
+
+    @Override
+    public int hashCode() {
+        int result = 0;
+        if (getLanguage() != null) {
+            result = getLanguage().hashCode();
+        }
+        result += getLexicalForm().hashCode();
+        result += getDataType().hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof Literal) {
+            Literal other = (Literal) obj;
+            
+            if (getLanguage() == null) {
+                if (other.getLanguage() != null) {
+                    return false;
+                }
+            } else {
+                if (!getLanguage().equals(other.getLanguage())) {
+                    return false;
+                }
+            }
+            boolean res = getDataType().equals(other.getDataType()) && getLexicalForm().equals(other.getLexicalForm());
+            return res;
+        } else {
+            return false;
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java
new file mode 100644
index 0000000..39d52f5
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/DelayedNotificator.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.clerezza.api.event.GraphEvent;
+import org.apache.clerezza.api.event.GraphListener;
+
+
+/**
+ *
+ * @author reto
+ */
+class DelayedNotificator {
+
+    private static final Logger log = Logger.getLogger(DelayedNotificator.class.getName());
+    private static Timer timer = new Timer("Event delivery timer",true);
+
+    static class ListenerHolder {
+
+        long delay;
+        List<GraphEvent> events = null;
+        WeakReference<GraphListener> listenerRef;
+
+        public ListenerHolder(GraphListener listener, long delay) {
+            this.listenerRef = new WeakReference<GraphListener>(listener);
+            this.delay = delay;
+        }
+
+        private void registerEvent(GraphEvent event) {
+            synchronized (this) {
+                if (events == null) {
+                    events = new ArrayList<GraphEvent>();
+                    events.add(event);
+                    timer.schedule(new TimerTask() {
+
+                        @Override
+                        public void run() {
+                            List<GraphEvent> eventsLocal;
+                            synchronized (ListenerHolder.this) {
+                                eventsLocal = events;
+                                events = null;
+                            }
+                            GraphListener listener = listenerRef.get();
+                            if (listener == null) {
+                                log.fine("Ignoring garbage collected listener");
+                            } else {
+                                try {
+                                    listener.graphChanged(eventsLocal);
+                                } catch (Exception e) {
+                                    log.log(Level.WARNING, "Exception delivering ImmutableGraph event", e);
+                                }
+                            }
+                        }
+                    }, delay);
+                } else {
+                    events.add(event);
+                }
+            }
+        }
+    }
+    
+    private final Map<GraphListener, ListenerHolder> map = Collections.synchronizedMap(
+            new WeakHashMap<GraphListener, ListenerHolder>());
+
+    void addDelayedListener(GraphListener listener, long delay) {
+        map.put(listener, new ListenerHolder(listener, delay));
+    }
+
+    /**
+     * removes a Listener, this doesn't prevent the listenerRef from receiving
+     * events alreay scheduled.
+     *
+     * @param listenerRef
+     */
+    void removeDelayedListener(GraphListener listener) {
+        map.remove(listener);
+    }
+
+    /**
+     * if the listenerRef has not been registered as delayed listenerRef te events is
+     * forwarded synchroneously
+     * @param event
+     */
+    void sendEventToListener(GraphListener listener, GraphEvent event) {
+        ListenerHolder holder = map.get(listener);
+        if (holder == null) {
+            listener.graphChanged(Collections.singletonList(event));
+        } else {
+            holder.registerEvent(event);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java
new file mode 100644
index 0000000..e8ac986
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/LiteralImpl.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.io.Serializable;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Language;
+
+/**
+ *
+ * @author reto
+ */
+public class LiteralImpl extends AbstractLiteral implements  Serializable {
+    private String lexicalForm;
+    private IRI dataType;
+    private int hashCode;
+    private Language language;
+
+    /**
+     * @param lexicalForm 
+     * @param dataType 
+     * @param Language the language of this literal
+     */
+    public LiteralImpl(String lexicalForm, IRI dataType, Language language) {
+        this.lexicalForm = lexicalForm;
+        this.dataType = dataType;
+        this.language = language;
+        this.hashCode = super.hashCode();
+    }
+    
+    public IRI getDataType() {
+        return dataType;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
+     */
+    @Override
+    public String getLexicalForm() {
+        return lexicalForm;
+    }
+
+    @Override
+    public int hashCode() {
+        return hashCode;
+    }
+    
+
+    @Override
+    public String toString() {
+        StringBuffer result = new StringBuffer();
+        result.append('\"');
+        result.append(getLexicalForm());
+        result.append('\"');
+        result.append("^^");
+        result.append(getDataType());
+        return result.toString();
+    }
+
+    @Override
+    public Language getLanguage() {
+        return language;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java
new file mode 100644
index 0000000..84b73de
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/LockingIterator.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.util.Iterator;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.clerezza.api.Triple;
+
+/**
+ * Wrapps an iterator<Triple> reading entering a read-lock on every invocation
+ * of hasNext and next
+ * @author reto
+ */
+class LockingIterator implements Iterator<Triple> {
+
+    private Iterator<Triple> base;
+    private Lock readLock;
+    private Lock writeLock;
+
+    public LockingIterator(Iterator<Triple> iterator, ReadWriteLock lock) {
+        base = iterator;
+        readLock = lock.readLock();
+        writeLock = lock.writeLock();
+    }
+
+    @Override
+    public boolean hasNext() {
+        readLock.lock();
+        try {
+            return base.hasNext();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public Triple next() {
+        readLock.lock();
+        try {
+            return base.next();
+        } finally {
+            readLock.unlock();
+        }
+    }
+
+    @Override
+    public void remove() {
+        writeLock.lock();
+        try {
+            base.remove();
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java
new file mode 100644
index 0000000..012aeca
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/PlainLiteralImpl.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.io.Serializable;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Language;
+import org.apache.clerezza.api.Literal;
+
+/**
+ *
+ * @author reto
+ */
+public class PlainLiteralImpl extends AbstractLiteral implements Literal, Serializable {
+
+    private final String lexicalForm;
+    private final Language language;
+
+    public PlainLiteralImpl(String value) {
+        this(value, null);
+    }
+
+    public PlainLiteralImpl(String value, Language language) {
+        if (value == null) {
+            throw new IllegalArgumentException("The literal string cannot be null");
+        }
+        this.lexicalForm = value;
+        this.language = language;
+        if (language == null) {
+            dataType = XSD_STRING;
+        } else {
+            dataType = RDF_LANG_STRING;
+        }
+    }
+
+    @Override
+    public String getLexicalForm() {
+        return lexicalForm;
+    }
+
+    @Override
+    public Language getLanguage() {
+        return language;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder result = new StringBuilder();
+        result.append('\"').append(lexicalForm).append('\"');
+        if (language != null) {
+            result.append("@").append(language.toString());
+        }
+        return result.toString();
+    }
+
+    @Override
+    public IRI getDataType() {
+        return dataType;
+    }
+    private final IRI dataType;
+    private static final IRI XSD_STRING = new IRI("http://www.w3.org/2001/XMLSchema#string");
+    private static final IRI RDF_LANG_STRING = new IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/TripleImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/TripleImpl.java
new file mode 100644
index 0000000..1f67d39
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/TripleImpl.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.IRI;
+
+/**
+ *
+ * @author reto
+ */
+public class TripleImpl implements Triple {
+
+    private final BlankNodeOrIRI subject;
+    private final IRI predicate;
+    private final RDFTerm object;
+
+    /**
+     * Creates a new <code>TripleImpl</code>.
+     *
+     * @param subject  the subject.
+     * @param predicate  the predicate.
+     * @param object  the object.
+     * @throws IllegalArgumentException  if an attribute is <code>null</code>.
+     */
+    public TripleImpl(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+        if (subject == null) {
+            throw new IllegalArgumentException("Invalid subject: null");
+        } else if (predicate == null) {
+            throw new IllegalArgumentException("Invalid predicate: null");
+        } else if (object == null) {
+            throw new IllegalArgumentException("Invalid object: null");
+        }
+        this.subject = subject;
+        this.predicate = predicate;
+        this.object = object;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof Triple)) {
+            return false;
+        }
+        final Triple other = (Triple) obj;
+        if (!this.subject.equals(other.getSubject())) {
+            return false;
+        }
+        if (!this.predicate.equals(other.getPredicate())) {
+            return false;
+        }
+        if (!this.object.equals(other.getObject())) {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return (subject.hashCode() >> 1) ^ predicate.hashCode() ^ (object.hashCode() << 1);
+    }
+
+    @Override
+    public BlankNodeOrIRI getSubject() {
+        return subject;
+    }
+
+    public IRI getPredicate() {
+        return predicate;
+    }
+
+    public RDFTerm getObject() {
+        return object;
+    }
+
+    @Override
+    public String toString() {
+        return subject + " " + predicate + " " + object + ".";
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java
new file mode 100644
index 0000000..0be7ab3
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/TypedLiteralImpl.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.io.Serializable;
+
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.Language;
+
+/**
+ *
+ * @author reto
+ */
+public class TypedLiteralImpl extends AbstractLiteral implements  Serializable {
+    private String lexicalForm;
+    private IRI dataType;
+    private int hashCode;
+
+    /**
+     * @param lexicalForm 
+     * @param dataType 
+     */
+    public TypedLiteralImpl(String lexicalForm, IRI dataType) {
+        this.lexicalForm = lexicalForm;
+        this.dataType = dataType;
+        this.hashCode = super.hashCode();
+    }
+    
+    public IRI getDataType() {
+        return dataType;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
+     */
+    @Override
+    public String getLexicalForm() {
+        return lexicalForm;
+    }
+
+    @Override
+    public int hashCode() {
+        return hashCode;
+    }
+    
+
+    @Override
+    public String toString() {
+        StringBuffer result = new StringBuffer();
+        result.append('\"');
+        result.append(getLexicalForm());
+        result.append('\"');
+        result.append("^^");
+        result.append(getDataType());
+        return result.toString();
+    }
+
+    @Override
+    public Language getLanguage() {
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java
new file mode 100644
index 0000000..5533c9b
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/WatchableGraphWrapper.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.clerezza.api.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.concurrent.locks.ReadWriteLock;
+
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.ImmutableGraph;
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.WatchableGraph;
+import org.apache.clerezza.api.event.AddEvent;
+import org.apache.clerezza.api.event.FilterTriple;
+import org.apache.clerezza.api.event.GraphEvent;
+import org.apache.clerezza.api.event.GraphListener;
+import org.apache.clerezza.api.event.RemoveEvent;
+
+/**
+ *
+ * @author developer
+ */
+public class WatchableGraphWrapper implements WatchableGraph {
+    
+    final Graph wrapped;
+
+    public WatchableGraphWrapper(Graph wrapped) {
+        this.wrapped = wrapped;
+    }
+    
+       
+    //all listeners
+    private final Set<ListenerConfiguration> listenerConfigs = Collections.synchronizedSet(
+            new HashSet<ListenerConfiguration>());
+    private DelayedNotificator delayedNotificator = new DelayedNotificator();
+
+    @Override
+    public Iterator<Triple> iterator() {
+        return filter(null, null, null);
+    }
+
+    @Override
+    public boolean contains(Object o) {
+        if (!(o instanceof Triple)) {
+            return false;
+        }
+        Triple t = (Triple) o;
+        return filter(t.getSubject(), t.getPredicate(), t.getObject()).hasNext();
+    }
+
+    @Override
+    public Iterator<Triple> filter(BlankNodeOrIRI subject, IRI predicate,
+                                   RDFTerm object) {
+        final Iterator<Triple> baseIter = wrapped.filter(subject, predicate, object);
+        return new Iterator<Triple>() {
+
+            Triple currentTriple = null;
+
+            @Override
+            public boolean hasNext() {
+                return baseIter.hasNext();
+            }
+
+            @Override
+            public Triple next() {
+                currentTriple = baseIter.next();
+                return currentTriple;
+            }
+
+            @Override
+            public void remove() {
+                baseIter.remove();
+                dispatchEvent(new RemoveEvent(WatchableGraphWrapper.this, currentTriple));
+            }
+        };
+    }
+
+    @Override
+    public boolean add(Triple triple) {
+        boolean success = performAdd(triple);
+        if (success) {
+            dispatchEvent(new AddEvent(this, triple));
+        }
+        return success;
+    }
+
+    /**
+     * A subclass of <code>AbstractGraph</code> should override 
+     * this method instead of <code>add</code> for Graph event support to be
+     * added.
+     * 
+     * @param e The triple to be added to the triple collection
+     * @return
+     */
+    protected boolean performAdd(Triple e) {
+        return wrapped.add(e);
+    }
+
+    @Override
+    public boolean remove(Object o) {
+        Triple triple = (Triple) o;
+        boolean success = performRemove(triple);
+        if (success) {
+            dispatchEvent(new RemoveEvent(this, triple));
+        }
+        return success;
+    }
+
+    @Override
+    public boolean removeAll(Collection<?> c) {
+        boolean modified = false;
+        for (Iterator<? extends Object> it = c.iterator(); it.hasNext();) {
+            Object object = it.next();
+            if (remove(object)) {
+                modified = true;
+            }
+        }
+        return modified;
+    }
+
+    /**
+     * A subclass of <code>AbstractGraph</code> should override 
+     * this method instead of <code>remove</code> for ImmutableGraph event support to be
+     * added.
+     * 
+     * @param o The triple to be removed from the triple collection
+     * @return
+     */
+    protected boolean performRemove(Triple triple) {
+        Iterator<Triple> e = filter(null, null, null);
+        while (e.hasNext()) {
+            if (triple.equals(e.next())) {
+                e.remove();
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Dispatches a <code>GraphEvent</code> to all registered listeners for which
+     * the specified <code>Triple</code> matches the <code>FilterTriple</code>s
+     * of the listeners.
+     * 
+     * @param triple The Triple that was modified
+     * @param type The type of modification
+     */
+    protected void dispatchEvent(GraphEvent event) {
+        synchronized(listenerConfigs) {
+            Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
+            while (iter.hasNext()) {
+                ListenerConfiguration config = iter.next();
+                GraphListener registeredListener = config.getListener();
+                if (registeredListener == null) {
+                    iter.remove();
+                    continue;
+                }
+                if (config.getFilter().match(event.getTriple())) {
+                    delayedNotificator.sendEventToListener(registeredListener, event);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void addGraphListener(GraphListener listener, FilterTriple filter) {
+        addGraphListener(listener, filter, 0);
+    }
+
+    @Override
+    public void addGraphListener(GraphListener listener, FilterTriple filter,
+            long delay) {
+        listenerConfigs.add(new ListenerConfiguration(listener, filter));
+        if (delay > 0) {
+            delayedNotificator.addDelayedListener(listener, delay);
+        }
+    }
+
+    @Override
+    public void removeGraphListener(GraphListener listener) {
+        synchronized(listenerConfigs) {
+            Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
+            while (iter.hasNext()) {
+                ListenerConfiguration listenerConfig = iter.next();
+                GraphListener registeredListener = listenerConfig.getListener();
+                if ((registeredListener == null) || (registeredListener.equals(listener))) {
+                    iter.remove();
+                }
+            }
+        }
+        delayedNotificator.removeDelayedListener(listener);
+    }
+
+    @Override
+    public ImmutableGraph getImmutableGraph() {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
+    @Override
+    public ReadWriteLock getLock() {
+        return wrapped.getLock();
+    }
+
+    @Override
+    public int size() {
+        return wrapped.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return wrapped.isEmpty();
+    }
+
+    @Override
+    public Object[] toArray() {
+        return wrapped.toArray();
+    }
+
+    @Override
+    public <T> T[] toArray(T[] a) {
+        return wrapped.toArray(a);
+    }
+
+    @Override
+    public boolean containsAll(Collection<?> c) {
+        return wrapped.containsAll(c);
+    }
+
+    @Override
+    public boolean addAll(Collection<? extends Triple> c) {
+        return wrapped.addAll(c);
+    }
+
+    @Override
+    public boolean retainAll(Collection<?> c) {
+        return wrapped.retainAll(c);
+    }
+
+    @Override
+    public void clear() {
+        wrapped.clear();
+    }
+
+    private static class ListenerConfiguration {
+
+        private WeakReference<GraphListener> listenerRef;
+        private FilterTriple filter;
+
+        private ListenerConfiguration(GraphListener listener, FilterTriple filter) {
+            this.listenerRef = new WeakReference<GraphListener>(listener);
+            this.filter = filter;
+        }
+
+        /**
+         * @return the listener
+         */
+        GraphListener getListener() {
+            GraphListener listener = listenerRef.get();
+            return listener;
+        }
+
+        /**
+         * @return the filter
+         */
+        FilterTriple getFilter() {
+            return filter;
+        }
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReadLockDebug.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReadLockDebug.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReadLockDebug.java
new file mode 100644
index 0000000..f826dee
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReadLockDebug.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.api.impl.debug;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
+
+/**
+ *
+ * @author mir
+ */
+public class ReadLockDebug extends ReadLock {
+
+    ReentrantReadWriteLockTracker lock;
+    StackTraceElement[] stackTrace;
+
+    ReadLock readLock;
+    public ReadLockDebug(ReentrantReadWriteLockTracker lock) {
+        super(lock);
+        this.lock = lock;
+        this.readLock = lock.realReadLock();
+    }
+
+    @Override
+    public void lock() {
+        readLock.lock();
+        lock.addLockedReadLock(this);
+        stackTrace = Thread.currentThread().getStackTrace();
+    }
+
+    @Override
+    public void lockInterruptibly() throws InterruptedException {
+        readLock.lockInterruptibly();
+    }
+
+    @Override
+    public Condition newCondition() {
+        return readLock.newCondition();
+    }
+
+    @Override
+    public String toString() {
+        return readLock.toString();
+    }
+
+    @Override
+    public boolean tryLock() {
+        return readLock.tryLock();
+    }
+
+    @Override
+    public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
+        return readLock.tryLock(timeout, unit);
+    }
+
+    @Override
+    public void unlock() {
+        readLock.unlock();
+        lock.removeReadLock(this);
+        stackTrace = null;
+    }
+
+    public StackTraceElement[] getStackTrace() {
+        return stackTrace;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReentrantReadWriteLockTracker.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReentrantReadWriteLockTracker.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReentrantReadWriteLockTracker.java
new file mode 100644
index 0000000..94e8a6c
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/ReentrantReadWriteLockTracker.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.api.impl.debug;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+/**
+ *
+ * @author mir
+ */
+public class ReentrantReadWriteLockTracker extends ReentrantReadWriteLock {
+
+
+    private Set<ReadLockDebug> lockedReadLocks = Collections.synchronizedSet(new HashSet<ReadLockDebug>());
+    private final WriteLockDebug writeLock = new WriteLockDebug(this);
+    @Override
+    protected Thread getOwner() {
+        return super.getOwner();
+    }
+
+    @Override
+    protected Collection<Thread> getQueuedReaderThreads() {
+        return super.getQueuedReaderThreads();
+    }
+
+    @Override
+    protected Collection<Thread> getQueuedThreads() {
+        return super.getQueuedThreads();
+    }
+
+    @Override
+    protected Collection<Thread> getQueuedWriterThreads() {
+        return super.getQueuedWriterThreads();
+    }
+
+    @Override
+    public int getReadHoldCount() {
+        return super.getReadHoldCount();
+    }
+
+    @Override
+    public int getReadLockCount() {
+        return super.getReadLockCount();
+    }
+
+    @Override
+    public int getWaitQueueLength(Condition condition) {
+        return super.getWaitQueueLength(condition);
+    }
+
+    @Override
+    protected Collection<Thread> getWaitingThreads(Condition condition) {
+        return super.getWaitingThreads(condition);
+    }
+
+    @Override
+    public int getWriteHoldCount() {
+        return super.getWriteHoldCount();
+    }
+
+    @Override
+    public boolean hasWaiters(Condition condition) {
+        return super.hasWaiters(condition);
+    }
+
+    @Override
+    public boolean isWriteLocked() {
+        return super.isWriteLocked();
+    }
+
+    @Override
+    public boolean isWriteLockedByCurrentThread() {
+        return super.isWriteLockedByCurrentThread();
+    }
+
+    @Override
+    public ReadLock readLock() {
+        return new ReadLockDebug(this);
+    }
+
+    ReadLock realReadLock() {
+        return super.readLock();
+    }
+
+    WriteLock realWriteLock() {
+        return super.writeLock();
+    }
+
+    @Override
+    public String toString() {
+        return super.toString();
+    }
+
+    @Override
+    public WriteLockDebug writeLock() {
+        return writeLock;
+    }
+
+    void addLockedReadLock(ReadLockDebug lock) {
+        lockedReadLocks.add(lock);
+    }
+
+    void removeReadLock(ReadLockDebug lock) {
+        lockedReadLocks.remove(lock);
+    }
+
+    public Set<ReadLockDebug> getLockedReadLocks() {
+        return lockedReadLocks;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/WriteLockDebug.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/WriteLockDebug.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/WriteLockDebug.java
new file mode 100644
index 0000000..82301a3
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/debug/WriteLockDebug.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.api.impl.debug;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+
+/**
+ *
+ * @author mir
+ */
+public class WriteLockDebug extends WriteLock {
+
+    private ReentrantReadWriteLockTracker lock;
+    private WriteLock writeLock;
+    private StackTraceElement[] stackTrace;
+
+    public WriteLockDebug(ReentrantReadWriteLockTracker lock) {
+        super(lock);
+        this.lock = lock;
+        this.writeLock = lock.realWriteLock();
+    }
+
+    @Override
+    public int getHoldCount() {
+        return writeLock.getHoldCount();
+    }
+
+    @Override
+    public boolean isHeldByCurrentThread() {
+        return writeLock.isHeldByCurrentThread();
+    }
+
+    @Override
+    public void lock() {
+        writeLock.lock();
+        stackTrace = Thread.currentThread().getStackTrace();
+    }
+
+    @Override
+    public void lockInterruptibly() throws InterruptedException {
+        writeLock.lockInterruptibly();
+    }
+
+    @Override
+    public Condition newCondition() {
+        return writeLock.newCondition();
+    }
+
+    @Override
+    public boolean tryLock() {
+        return writeLock.tryLock();
+    }
+
+    @Override
+    public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
+        return writeLock.tryLock(timeout, unit);
+    }
+
+    @Override
+    public void unlock() {
+        writeLock.unlock();
+        stackTrace = null;
+    }
+
+    public StackTraceElement[] getStackTrace() {
+        return stackTrace;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
new file mode 100644
index 0000000..9180ae0
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphMatcher.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.api.impl.graphmatching;
+
+
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.clerezza.api.BlankNode;
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+import org.apache.clerezza.api.impl.TripleImpl;
+import org.apache.clerezza.api.impl.simple.SimpleMGraph;
+
+/**
+ * @author reto
+ * 
+ */
+public class GraphMatcher {
+
+
+    private final static Logger log = Logger.getLogger(GraphMatcher.class.getName());
+
+    /**
+     * get a mapping from g1 to g2 or null if the graphs are not isomorphic. The
+     * returned map maps each <code>BNode</code>s from g1 to one
+     * of g2. If the graphs are ground graphs the method return an empty map if
+     * the ImmutableGraph are equals and null otherwise.
+     * <p/>
+     * NOTE: This method does not returned mapping from blank nodes to grounded
+     * nodes, a bnode in g1 is not a vraiable that may match any node, but must
+     * match a bnode in g2.
+     * <p/>
+     *
+     * On the algorithm:<br/>
+     * - In a first step it checked if every grounded triple in g1 matches one
+     * in g2<br/>
+     * - [optional] blank node blind matching</br>
+     * - in a map mbng1 bnode of g1 is mapped to a set of of its
+     * properties and inverse properties, this is the predicate and the object
+     * or subject respectively, analoguosly in mbgn2 every bnode of g2<br/>
+     * - based on the incoming and outgoing properties a hash is calculated for
+     * each bnode, in the first step when calculating the hash  aconstant value
+     * is taken for the bnodes that might be subject or object in the (inverse properties)
+     * - hash-classes:
+     * 
+     * @param g1
+     * @param g2
+     * @return a Set of NodePairs
+     */
+    public static Map<BlankNode, BlankNode> getValidMapping(Graph og1, Graph og2) {
+        Graph g1 = new SimpleMGraph(og1);
+        Graph g2 = new SimpleMGraph(og2);
+        if (!Utils.removeGrounded(g1,g2)) {
+            return null;
+        }
+        final HashMatching hashMatching;
+        try {
+            hashMatching = new HashMatching(g1, g2);
+        } catch (GraphNotIsomorphicException ex) {
+            return null;
+        }
+        Map<BlankNode, BlankNode> matchings = hashMatching.getMatchings();
+        if (g1.size() > 0) {
+            //start trial an error matching
+            //TODO (CLEREZZA-81) at least in the situation where one matching
+            //group is big (approx > 5) we should switch back to hash-based matching
+            //after a first guessed matching, rather than try all permutations
+            Map<BlankNode, BlankNode> remainingMappings = trialAndErrorMatching(g1, g2, hashMatching.getMatchingGroups());
+            if (remainingMappings == null) {
+                return null;
+            } else {
+                matchings.putAll(remainingMappings);
+            }
+        }
+        return matchings;
+    }
+
+    private static Map<BlankNode, BlankNode> trialAndErrorMatching(Graph g1, Graph g2,
+            Map<Set<BlankNode>, Set<BlankNode>> matchingGroups) {
+        if (log.isLoggable(Level.FINE)) {
+            Set<BlankNode> bn1  = Utils.getBNodes(g1);
+            log.log(Level.FINE,"doing trial and error matching for {0}"+" bnodes, "+"in graphs of size: {1}.", new Object[]{bn1.size(), g1.size()});
+        }
+        Iterator<Map<BlankNode, BlankNode>> mappingIter
+                = GroupMappingIterator.create(matchingGroups);
+        while (mappingIter.hasNext()) {
+            Map<BlankNode, BlankNode> map = mappingIter.next();
+            if (checkMapping(g1, g2, map)) {
+                return map;
+            }
+        }
+        return null;
+    }
+
+    private static boolean checkMapping(Graph g1, Graph g2, Map<BlankNode, BlankNode> map) {
+        for (Triple triple : g1) {
+            if (!g2.contains(map(triple, map))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private static Triple map(Triple triple, Map<BlankNode, BlankNode> map) {
+        final BlankNodeOrIRI oSubject = triple.getSubject();
+
+        BlankNodeOrIRI subject = oSubject instanceof BlankNode ?
+            map.get((BlankNode)oSubject) : oSubject;
+
+        RDFTerm oObject = triple.getObject();
+        RDFTerm object = oObject instanceof BlankNode ?
+            map.get((BlankNode)oObject) : oObject;
+        return new TripleImpl(subject, triple.getPredicate(), object);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphNotIsomorphicException.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphNotIsomorphicException.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphNotIsomorphicException.java
new file mode 100644
index 0000000..3137098
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GraphNotIsomorphicException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.api.impl.graphmatching;
+
+/**
+ *
+ * @author reto
+ */
+class GraphNotIsomorphicException extends Exception {
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GroupMappingIterator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GroupMappingIterator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GroupMappingIterator.java
new file mode 100644
index 0000000..1d271bf
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/GroupMappingIterator.java
@@ -0,0 +1,101 @@
+/*
+ *  Copyright 2010 reto.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+
+package org.apache.clerezza.api.impl.graphmatching;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * Iterates over all mappings from each element of every Set<T> to each
+ * elemenent of their corresponding Set<U>.
+ *
+ * @author reto
+ */
+class GroupMappingIterator<T,U> implements Iterator<Map<T, U>> {
+
+    private Iterator<Map<T, U>> firstPartIter;
+    private Map<T, U> currentFirstPart;
+    final private Map<Set<T>, Set<U>> restMap;
+    private Iterator<Map<T, U>> currentRestPartIter;
+
+    static <T,U> Iterator<Map<T, U>> create(Map<Set<T>, Set<U>> matchingGroups) {
+        if (matchingGroups.size() > 1) {
+            return new GroupMappingIterator<T, U>(matchingGroups);
+        } else {
+            if (matchingGroups.size() == 0) {
+                return new ArrayList<Map<T, U>>(0).iterator();
+            }
+            Map.Entry<Set<T>, Set<U>> entry = matchingGroups.entrySet().iterator().next();
+            return new MappingIterator<T,U>(entry.getKey(),
+                        entry.getValue());
+        }
+    }
+
+    private GroupMappingIterator(Map<Set<T>, Set<U>> matchingGroups) {
+        if (matchingGroups.size() == 0) {
+            throw new IllegalArgumentException("matchingGroups must not be empty");
+        }
+        restMap = new HashMap<Set<T>, Set<U>>();
+        boolean first = true;
+        for (Map.Entry<Set<T>, Set<U>> entry : matchingGroups.entrySet()) {
+            if (first) {
+                firstPartIter = new MappingIterator<T,U>(entry.getKey(),
+                        entry.getValue());
+                first = false;
+            } else {
+                restMap.put(entry.getKey(), entry.getValue());
+            }
+        }
+        currentRestPartIter = create(restMap);
+        currentFirstPart = firstPartIter.next();
+    }
+
+    @Override
+    public boolean hasNext() {
+        return firstPartIter.hasNext() || currentRestPartIter.hasNext();
+    }
+
+    @Override
+    public Map<T, U> next() {
+        Map<T, U> restPart;
+        if (currentRestPartIter.hasNext()) {
+            restPart = currentRestPartIter.next();
+        } else {
+            if (firstPartIter.hasNext()) {
+                currentFirstPart = firstPartIter.next();
+                currentRestPartIter = create(restMap);
+                restPart = currentRestPartIter.next();
+            } else {
+                throw new NoSuchElementException();
+            }
+        }
+        Map<T, U> result = new HashMap<T, U>(restPart);
+        result.putAll(currentFirstPart);
+        return result;
+    }
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/HashMatching.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/HashMatching.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/HashMatching.java
new file mode 100644
index 0000000..13b8436
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/HashMatching.java
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.api.impl.graphmatching;
+
+
+import org.apache.clerezza.api.BlankNode;
+import org.apache.clerezza.api.Graph;
+import org.apache.clerezza.api.IRI;
+import org.apache.clerezza.api.impl.TripleImpl;
+import org.apache.clerezza.api.impl.graphmatching.collections.IntIterator;
+import org.apache.clerezza.api.impl.graphmatching.collections.IntHashMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.clerezza.api.BlankNodeOrIRI;
+import org.apache.clerezza.api.RDFTerm;
+import org.apache.clerezza.api.Triple;
+
+/**
+ *
+ * @author reto
+ */
+public class HashMatching {
+
+    private Map<BlankNode, BlankNode> matchings = new HashMap<BlankNode, BlankNode>();
+    private Map<Set<BlankNode>, Set<BlankNode>> matchingGroups;
+
+    /**
+     * tc1 and tc2 will be modified: the triples containing no unmatched bnode
+     * will be removed
+     *
+     * @param tc1
+     * @param tc2
+     * @throws GraphNotIsomorphicException
+     */
+    HashMatching(Graph tc1, Graph tc2) throws GraphNotIsomorphicException {
+        int foundMatchings = 0;
+        int foundMatchingGroups = 0;
+        Map<BlankNode, Integer> bNodeHashMap = new HashMap<BlankNode, Integer>();
+        while (true) {
+            bNodeHashMap = matchByHashes(tc1, tc2, bNodeHashMap);
+            if (bNodeHashMap == null) {
+                throw new GraphNotIsomorphicException();
+            }
+            if (matchings.size() == foundMatchings) {
+                if (!(matchingGroups.size() > foundMatchingGroups)) {
+                    break;
+                }
+            }
+            foundMatchings = matchings.size();
+            foundMatchingGroups = matchingGroups.size();
+        }
+    }
+
+    /**
+     *
+     * @return a map containing set of which each bnodes mappes one of the other set
+     */
+    public Map<Set<BlankNode>, Set<BlankNode>> getMatchingGroups() {
+        return matchingGroups;
+    }
+
+    public Map<BlankNode, BlankNode> getMatchings() {
+        return matchings;
+    }
+
+    
+    private static IntHashMap<Set<BlankNode>> getHashNodes(Map<BlankNode,
+            Set<Property>> bNodePropMap, Map<BlankNode, Integer> bNodeHashMap) {
+        IntHashMap<Set<BlankNode>> result = new IntHashMap<Set<BlankNode>>();
+        for (Map.Entry<BlankNode, Set<Property>> entry : bNodePropMap.entrySet()) {
+            int hash = computeHash(entry.getValue(), bNodeHashMap);
+            Set<BlankNode> bNodeSet = result.get(hash);
+            if (bNodeSet == null) {
+                bNodeSet = new HashSet<BlankNode>();
+                result.put(hash,bNodeSet);
+            }
+            bNodeSet.add(entry.getKey());
+        }
+        return result;
+    }
+    /*
+     * returns a Map from bnodes to hash that can be used for future
+     * refinements, this could be separate for each ImmutableGraph.
+     *
+     * triples no longer containing an unmatched bnodes ae removed.
+     *
+     * Note that the matched node are not guaranteed to be equals, but only to
+     * be the correct if the graphs are isomorphic.
+     */
+    private Map<BlankNode, Integer> matchByHashes(Graph g1, Graph g2,
+            Map<BlankNode, Integer> bNodeHashMap) {
+        Map<BlankNode, Set<Property>> bNodePropMap1  = getBNodePropMap(g1);
+        Map<BlankNode, Set<Property>> bNodePropMap2  = getBNodePropMap(g2);
+        IntHashMap<Set<BlankNode>> hashNodeMap1 = getHashNodes(bNodePropMap1, bNodeHashMap);
+        IntHashMap<Set<BlankNode>> hashNodeMap2 = getHashNodes(bNodePropMap2, bNodeHashMap);
+        if (!hashNodeMap1.keySet().equals(hashNodeMap2.keySet())) {
+            return null;
+        }
+
+        matchingGroups = new HashMap<Set<BlankNode>, Set<BlankNode>>();
+        IntIterator hashIter = hashNodeMap1.keySet().intIterator();
+        while (hashIter.hasNext()) {
+            int hash = hashIter.next();
+            Set<BlankNode> nodes1 = hashNodeMap1.get(hash);
+            Set<BlankNode> nodes2 = hashNodeMap2.get(hash);
+            if (nodes1.size() != nodes2.size()) {
+                return null;
+            }
+            if (nodes1.size() != 1) {
+                matchingGroups.put(nodes1, nodes2);
+                continue;
+            }
+            final BlankNode bNode1 = nodes1.iterator().next();
+            final BlankNode bNode2 = nodes2.iterator().next();
+            matchings.put(bNode1,bNode2);
+            //in the graphs replace node occurences with grounded node,
+            BlankNodeOrIRI mappedNode = new MappedNode(bNode1, bNode2);
+            replaceNode(g1,bNode1, mappedNode);
+            replaceNode(g2, bNode2, mappedNode);
+            //remove grounded triples
+            if (!Utils.removeGrounded(g1,g2)) {
+                return null;
+            }
+        }
+        Map<BlankNode, Integer> result = new HashMap<BlankNode, Integer>();
+        addInverted(result, hashNodeMap1);
+        addInverted(result, hashNodeMap2);
+        return result;
+    }
+    private static int computeHash(Set<Property> propertySet, Map<BlankNode, Integer> bNodeHashMap) {
+        int result = 0;
+        for (Property property : propertySet) {
+            result += property.hashCode(bNodeHashMap);
+        }
+        return result;
+    }
+    private static Map<BlankNode, Set<Property>> getBNodePropMap(Graph g) {
+        Set<BlankNode> bNodes = Utils.getBNodes(g);
+        Map<BlankNode, Set<Property>> result = new HashMap<BlankNode, Set<Property>>();
+        for (BlankNode bNode : bNodes) {
+            result.put(bNode, getProperties(bNode, g));
+        }
+        return result;
+    }
+    private static Set<Property> getProperties(BlankNode bNode, Graph g) {
+        Set<Property> result = new HashSet<Property>();
+        Iterator<Triple> ti = g.filter(bNode, null, null);
+        while (ti.hasNext()) {
+            Triple triple = ti.next();
+            result.add(new ForwardProperty(triple.getPredicate(), triple.getObject()));
+        }
+        ti = g.filter(null, null, bNode);
+        while (ti.hasNext()) {
+            Triple triple = ti.next();
+            result.add(new BackwardProperty(triple.getSubject(), triple.getPredicate()));
+        }
+        return result;
+    }
+    private static int nodeHash(RDFTerm resource, Map<BlankNode, Integer> bNodeHashMap) {
+        if (resource instanceof BlankNode) {
+            Integer mapValue = bNodeHashMap.get((BlankNode)resource);
+            if (mapValue == null) {
+                return 0;
+            } else {
+                return mapValue;
+            }
+        } else {
+            return resource.hashCode();
+        }
+    }
+    private static void replaceNode(Graph graph, BlankNode bNode, BlankNodeOrIRI replacementNode) {
+        Set<Triple> triplesToRemove = new HashSet<Triple>();
+        for (Triple triple : graph) {
+            Triple replacementTriple = getReplacement(triple, bNode, replacementNode);
+            if (replacementTriple != null) {
+                triplesToRemove.add(triple);
+                graph.add(replacementTriple);
+            }
+        }
+        graph.removeAll(triplesToRemove);
+    }
+    private static Triple getReplacement(Triple triple, BlankNode bNode, BlankNodeOrIRI replacementNode) {
+        if (triple.getSubject().equals(bNode)) {
+            if (triple.getObject().equals(bNode)) {
+                return new TripleImpl(replacementNode, triple.getPredicate(), replacementNode);
+            } else {
+                return new TripleImpl(replacementNode, triple.getPredicate(), triple.getObject());
+            }
+        } else {
+            if (triple.getObject().equals(bNode)) {
+                return new TripleImpl(triple.getSubject(), triple.getPredicate(), replacementNode);
+            } else {
+                return null;
+            }
+        }
+    }
+    private static void addInverted(Map<BlankNode, Integer> result, IntHashMap<Set<BlankNode>> hashNodeMap) {
+        for (int hash : hashNodeMap.keySet()) {
+            Set<BlankNode> bNodes = hashNodeMap.get(hash);
+            for (BlankNode bNode : bNodes) {
+                result.put(bNode, hash);
+            }
+        }
+    }
+    
+    private static class BackwardProperty implements Property {
+        private BlankNodeOrIRI subject;
+        private IRI predicate;
+    
+        public BackwardProperty(BlankNodeOrIRI subject, IRI predicate) {
+            this.subject = subject;
+            this.predicate = predicate;
+        }
+    
+        @Override
+        public int hashCode(Map<BlankNode, Integer> bNodeHashMap) {
+            return  0xFF ^ predicate.hashCode() ^ nodeHash(subject, bNodeHashMap);
+        }
+    
+    }
+    private static class ForwardProperty implements Property {
+        private IRI predicate;
+        private RDFTerm object;
+    
+        public ForwardProperty(IRI predicate, RDFTerm object) {
+            this.predicate = predicate;
+            this.object = object;
+        }
+    
+        @Override
+        public int hashCode(Map<BlankNode, Integer> bNodeHashMap) {
+            return predicate.hashCode() ^ nodeHash(object, bNodeHashMap);
+        }
+    }
+    private static class MappedNode implements BlankNodeOrIRI {
+        private BlankNode bNode1, bNode2;
+    
+        public MappedNode(BlankNode bNode1, BlankNode bNode2) {
+            this.bNode1 = bNode1;
+            this.bNode2 = bNode2;
+        }
+        
+    }
+    private static interface Property {
+        public int hashCode(Map<BlankNode, Integer> bNodeHashMap);
+    }
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/d1ee24ce/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/MappingIterator.java
----------------------------------------------------------------------
diff --git a/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/MappingIterator.java b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/MappingIterator.java
new file mode 100644
index 0000000..6c5c245
--- /dev/null
+++ b/api.impl/src/main/java/org/apache/clerezza/api/impl/graphmatching/MappingIterator.java
@@ -0,0 +1,76 @@
+package org.apache.clerezza.api.impl.graphmatching;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * An iterator over all possible mapping beetween the elemnets of two sets of
+ * the same size, each mapping maps each element from set1 to a disctinct one of
+ * set2.
+ *
+ *
+ *
+ * @author reto
+ */
+class MappingIterator<T,U> implements Iterator<Map<T, U>> {
+
+    private List<T> list1;
+    private Iterator<List<U>> permutationList2Iterator;
+
+
+    public MappingIterator(Set<T> set1, Set<U> set2) {
+        if (set1.size() != set2.size()) {
+            throw new IllegalArgumentException();
+        }
+        this.list1 = new ArrayList<T>(set1);
+        permutationList2Iterator = new PermutationIterator<U>(
+                new ArrayList<U>(set2));
+    }
+
+    @Override
+    public boolean hasNext() {
+        return permutationList2Iterator.hasNext();
+    }
+
+    @Override
+    public Map<T, U> next() {
+        List<U> list2 = permutationList2Iterator.next();
+        Map<T, U> result = new HashMap<T, U>(list1.size());
+        for (int i = 0; i < list1.size(); i++) {
+            result.put(list1.get(i), list2.get(i));
+        }
+        return result;
+    }
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+
+
+}