package uk.me.graphe.shared;

public class Edge {
    private Vertex mVertex1;
    private Vertex mVertex2;
    private VertexDirection mDir;

    /**
     * creates an edge without direction
     * 
     * @param v1
     *            the "from" vertex
     * @param v2
     *            the "to" vertex
     */
    public Edge(Vertex v1, Vertex v2) {
        this(v1, v2, VertexDirection.both);
    }

    /**
     * creates an edge
     * 
     * @param v1
     *            the "from" vertex
     * @param v2
     *            the "to" vertex
     * @param dir
     *            the edge direction
     */
    public Edge(Vertex v1, Vertex v2, VertexDirection dir) {
        mVertex1 = v1;
        mVertex2 = v2;
        mDir = dir;
    }

    /**
     * determines if the edge exits a vertex
     * 
     * @param v
     *            the vertex to test against
     * @return true if this edge exits v, else false
     */
    public boolean exits(Vertex v) {
        if (mDir == VertexDirection.both && (v.equals(mVertex1) || v.equals(mVertex2))) return true;
        else return v.equals((mDir == VertexDirection.fromTo) ? mVertex1 : mVertex2);
    }

    /**
     * determines if the edge enters a vertex
     * 
     * @param v
     *            the vertex to test against
     * @return true if this edge enters v, else false
     */
    public boolean enters(Vertex v) {
        if (mDir == VertexDirection.both && (v.equals(mVertex1) || v.equals(mVertex2))) return true;
        else return v.equals((mDir == VertexDirection.toFrom) ? mVertex1 : mVertex2);
    }

    /**
     * gets the from vertex of this edge
     * 
     * @return
     */
    public Vertex getFromVertex() {
        return mVertex1;
    }

    /**
     * gets the to vertex of this edge
     * 
     * @return
     */
    public Vertex getToVertex() {
        return mVertex2;
    }

    /**
     * determines if an edge has a direction
     * 
     * @return
     */
    public boolean hasDirection() {
        return mDir != VertexDirection.both;
    }
    
    public VertexDirection getDirection() {
        return mDir;
    }
    
    @Override
    public boolean equals(Object o) {
        if (o instanceof Edge) {
            Edge cmp = (Edge)o;
            return cmp.mVertex1.equals(mVertex1) && cmp.mVertex2.equals(mVertex2) && cmp.mDir == mDir;
        } else return false;
    }

}

@@ -134,16 +134,45 @@
 on mDir;
+%0A    private int mWeight = 1;
 %0A%0A    /*
@@ -1017,32 +1017,48 @@
 exDirection.both
+%0A               
  && (v.equals(mV
@@ -1106,32 +1106,44 @@
 ue;%0A        else
+%0A           
  return v.equals
@@ -1178,32 +1178,52 @@
 omTo) ? mVertex1
+%0A                   
  : mVertex2);%0A  
@@ -1490,16 +1490,32 @@
 ion.both
+%0A               
  && (v.e
@@ -1575,24 +1575,36 @@
         else
+%0A           
  return v.eq
@@ -1651,16 +1651,36 @@
 mVertex1
+%0A                   
  : mVert
@@ -2151,28 +2151,24 @@
 both;%0A    %7D%0A
-    
 %0A    public 
@@ -2227,20 +2227,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Ov
@@ -2342,16 +2342,17 @@
 = (Edge)
+ 
 o;%0A     
@@ -2394,16 +2394,36 @@
 Vertex1)
+%0A                   
  && cmp.
@@ -2483,16 +2483,28 @@
   %7D else
+%0A           
  return 
@@ -2517,10 +2517,145 @@
 %0A    %7D%0A%0A
+    public void setWeight(int i) %7B%0A        if (i %3E= 0) mWeight = i;%0A    %7D%0A%0A    public int getWeight() %7B%0A        return mWeight;%0A    %7D%0A%0A
 %7D%0A

add weight to edges