@ Override public Pair < Integer , Integer > pPredecessor ( int partition , int token ) { Integer partForToken = m_tokensMap . get ( ) . get ( token ) ; if ( partForToken != null && partForToken == partition ) { Map . Entry < Integer , Integer > predecessor = m_tokensMap . get ( ) . headMap ( token ) . lastEntry ( ) ; if ( predecessor == null ) { predecessor = m_tokensMap . get ( ) . lastEntry ( ) ; } if ( predecessor . getKey ( ) != token ) { return Pair . of ( predecessor . getKey ( ) , predecessor . getValue ( ) ) ; } else { // given token is the only one on the ring, umpossible throw new RuntimeException ( "There is only one token on the hash ring" ) ; } } else { // given token doesn't map to partition throw new IllegalArgumentException ( "The given token " + token + " does not map to partition " + partition ) ; } }
Find the predecessor of the given token on the ring .