java: Object1 & Object2 same as Object2 & Object1
===

I try to draw lines between different GridPositions(x,y). Every GridPos has 4 Connections North, East, South, West. The Problem is if I paint a line from GridPos(1,1) to GridPos(2,2) the program will paint also a line in reverse direction between GridPos(2,2) and GridPos(1,1) later.

I tried to solve the problem with this class (WarpGate is the same as GridPos):

    public class GateConnection {
	
	private WarpGate gate1 = null;
	private WarpGate gate2 = null;
	
	public GateConnection(WarpGate gate1, WarpGate gate2) {
		super();
		this.gate1 = gate1;
		this.gate2 = gate2;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		
		int result = prime * ((gate1 == null) ? 0 : gate1.hashCode());
		result += prime * ((gate2 == null) ? 0 : gate2.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		GateConnection other = (GateConnection) obj;
		if ((gate1.equals(other.gate1) || gate1.equals(other.gate2)) && (gate2.equals(other.gate2) || gate2.equals(other.gate1))) {
			return true;
		}
		return false;
	}
	
    }


This Class could be added to an TreeSet and the double painting would be gone but I don't know if the hashValue is always unique.

HashCode of WarpGate (auto-generated by eclipse):

    @Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + gridX;
		result = prime * result + gridY;
		return result;
	}

For now I use an ArrayList. I look if the GateConnection exists, if not then add. But this version takes much more ressources than using a TreeSet.