public void flip() {
        Wire wire1 = ports[0].myWire;
        Wire wire2 = ports[1].myWire;
        if (wire1 != null) {
            if (wire1.fromPort == ports[0]) {
                wire1.fromPort = ports[1];
            }
            if (wire1.toPort == ports[0]) {
                wire1.toPort = ports[1];
            }
            if (wire1.inPort == ports[0]) {
                wire1.inPort = ports[1];
            }
        }
        if (wire2 != null) {
            if (wire2.fromPort == ports[1]) {
                wire2.fromPort = ports[0];
            }
            if (wire2.toPort == ports[1]) {
                wire2.toPort = ports[0];
            }
            if (wire2.inPort == ports[1]) {
                wire2.inPort = ports[0];
            }
        }
        ports[0].myWire = wire2;
        ports[1].myWire = wire1;
    }