protected void removeNeighborFromRoutingTable(final TrustGraphNodeId neighbor) {

        /* find the neighbor that the node being removed is mapped to
         * ie the route neighbor -> mergeVal
         */
        final TrustGraphNodeId mergeVal = routingTable.get(neighbor);

        // if it is mapped to itself, just remove it and return.
        if (mergeVal.equals(neighbor)) {
            routingTable.remove(neighbor);
            // this should only happen when there was only a single entry.
            if (!routingTable.isEmpty()) {
                assert false;//routingTable.isEmpty();
            }
            return;
        }

        /* If it wasn't mapped to itself, find the neighbor that is
         * currently mapped to the neighbor being removed, ie the 
         * route mergeKey -> neighbor.
         */
        TrustGraphNodeId mergeKey = null;
        for (Map.Entry<TrustGraphNodeId,TrustGraphNodeId> e : routingTable.entrySet()) {
            if (e.getValue().equals(neighbor)) {
                mergeKey = e.getKey();
                break;
            }
        }
        assert mergeKey != null;

        /**
         * Atomically merge the route X->neighbor, neighbor->Y into the
         * route X->Y.This preserves the ability to route to Y. Finally,
         * remove the mapping neighbor->Y.
         */
        routingTable.replace(mergeKey, mergeVal);
        routingTable.remove(neighbor);

    }
protected void removeNeighborFromRoutingTable ( final TrustGraphNodeId neighbor ) { final TrustGraphNodeId mergeVal = routingTable . get ( neighbor ) ; if ( mergeVal . equals ( neighbor ) ) { routingTable . remove ( neighbor ) ; if ( ! routingTable . isEmpty ( ) ) { assert false ; } return ; } TrustGraphNodeId mergeKey = null ; for ( Map . Entry < TrustGraphNodeId , TrustGraphNodeId > e : routingTable . entrySet ( ) ) { if ( e . getValue ( ) . equals ( neighbor ) ) { mergeKey = e . getKey ( ) ; break ; } } assert mergeKey != null ; routingTable . replace ( mergeKey , mergeVal ) ; routingTable . remove ( neighbor ) ; }
Internal helper method.

implements the policy for removing a single node from the routing table.

If the node is mapped to itself, the route is removed. Otherwise this
operation merges the two routes of the form X -> neighbor ,
neighbor -> Y into X -> Y.

If the table does not contain the referenced neighbor,
this operation has no effect.

Assumes any necessary locking is done externally.