/*
  Copyright (C) 2012-2013 the original author or authors.

  See the LICENSE.txt file distributed with this work for additional
  information regarding copyright ownership.

  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 jcommon.graph;

/**
 * Factory and implementation of a dependency graph that can topologically sort vertices that are {@link Object}s.
 *
 * @see DirectedAcyclicGraph
 */
public class ObjectGraph extends DirectedAcyclicGraph<ObjectVertex> {
  /**
   * @see DirectedAcyclicGraph#DirectedAcyclicGraph()
   */
  protected ObjectGraph() {
    super();
  }

  /**
   * @see DirectedAcyclicGraph#copy()
   */
  public ObjectGraph copyAsObjectGraph() {
    return copyGraph(this);
  }

  /**
   * @see DirectedAcyclicGraph#build(jcommon.graph.IVertex[])
   */
  public static ObjectGraph buildFromObjects(final Object...vertices) {
    final ObjectGraph g = new ObjectGraph();
    for(Object v : vertices)
      g.addVertex(v);
    return g;
  }

  /**
   * @see DirectedAcyclicGraph#create()
   */
  public static ObjectGraph createForObjects() {
    return buildFromObjects();
  }

  /**
   * @see DirectedAcyclicGraph#addVertex(jcommon.graph.IVertex)
   */
  public ObjectGraph addVertex(final Object vertex) {
    super.addVertex(ObjectVertex.from(vertex));
    return this;
  }

  /**
   * @see DirectedAcyclicGraph#removeVertex(jcommon.graph.IVertex)
   */
  public ObjectGraph removeVertex(final Object vertex) {
    super.removeVertex(ObjectVertex.from(vertex));
    return this;
  }

  /**
   * @see DirectedAcyclicGraph#addEdge(jcommon.graph.IVertex, jcommon.graph.IVertex)
   */
  public ObjectGraph addEdge(final ObjectVertex from, final ObjectVertex to) {
    super.addEdge(ObjectVertex.from(from), ObjectVertex.from(to));
    return this;
  }

  /**
   * @see DirectedAcyclicGraph#removeEdge(jcommon.graph.IVertex, jcommon.graph.IVertex)
   */
  public ObjectGraph removeEdge(final ObjectVertex from, final ObjectVertex to) {
    super.removeEdge(ObjectVertex.from(from), ObjectVertex.from(to));
    return this;
  }
}

@@ -945,22 +945,17 @@
 icGraph%3C
-Object
+I
 Vertex%3E 
@@ -2131,38 +2131,32 @@
 dge(final Object
-Vertex
  from, final Obj
@@ -2162,85 +2162,213 @@
 ject
-Vertex to) %7B%0A    super.addEdge(ObjectVertex.from(from), ObjectVertex.from(to)
+ to) %7B%0A    final IVertex t = (to instanceof IVertex) ? (IVertex)to : ObjectVertex.from(to);%0A    final IVertex f = (from instanceof IVertex) ? (IVertex)from : ObjectVertex.from(from);%0A    super.addEdge(f, t
 );%0A 
@@ -2532,22 +2532,16 @@
 l Object
-Vertex
  from, f
@@ -2551,22 +2551,16 @@
 l Object
-Vertex
  to) %7B%0A 
@@ -2566,71 +2566,205 @@
     
-super.removeEdge(ObjectVertex.from(from), ObjectVertex.from(to)
+final IVertex t = (to instanceof IVertex) ? (IVertex)to : ObjectVertex.from(to);%0A    final IVertex f = (from instanceof IVertex) ? (IVertex)from : ObjectVertex.from(from);%0A    super.removeEdge(f, t
 );%0A 

Fix issue #1.