/** * Determines the distance to the given network node. The distance is determined as the number of internal network * nodes that must be traversed in order to send a packet from one node to the other plus one. * * @param networkNode * the node to determine the distance for * @return the distance to the given network node or <code>Integer.MAX_VALUE</code> if the given node is not part of * this node's network topology */ public int getDistance(final NetworkNode networkNode) { int steps = 0; NetworkNode tmp = this; while (tmp != null) { final int distance = tmp.isPredecessorOrSelfOf(networkNode); if (distance >= 0) { return (steps + distance); } tmp = tmp.getParentNode(); ++steps; } return Integer.MAX_VALUE; }
/** * Determines the distance to the given network node. The distance is determined as the number of internal network * nodes that must be traversed in order to send a packet from one node to the other plus one. * * @param networkNode * the node to determine the distance for * @return the distance to the given network node or <code>Integer.MAX_VALUE</code> if the given node is not part of * this node's network topology */ public int getDistance(final NetworkNode networkNode) { int steps = 0; NetworkNode tmp = this; while (tmp != null) { final int distance = tmp.isPredecessorOrSelfOf(networkNode); if (distance >= 0) { return (steps + distance); } tmp = tmp.getParentNode(); ++steps; } return Integer.MAX_VALUE; }