/** * possible infinite recursion for funs. */ private T getRedirectDestination(T destination) { if (redirects.containsKey(destination)) { destination = getRedirectDestination(redirects.get(destination)); } return destination; }
private T getPacketDestination(PacketCommunicator sourceCommunicator, Packet<?> packet) { if (packet.getDestination() < 0 || packet.getDestination() >= destinationConstants.length) { System.err.println("Invalid destination: " + packet.getDestination() + " sending to Broadcast"); return destinationConstants[0]; } T destination = destinationConstants[packet.getDestination()]; if (redirects.containsKey(destination)) { destination = getRedirectDestination(destination); if (destination != communicatorDestinations.get(sourceCommunicator)) { packet.setDestination(destination.ordinal()); } } return destinationConstants[packet.getDestination()]; }