public int convertTo ( StringToUniqueIntegerMap other , int localId ) { if ( other == null ) { throw new IllegalStateException ( "Other map is null" ) ; } String localKey = store . reverseGet ( localId ) ; if ( localKey == null ) { throw new IllegalArgumentException ( "Cannot convert an id that is not registered locally." ) ; } Integer foreignId = null ; if ( other == this ) { return localId ; } else if ( other == parent ) { foreignId = thisToParentMap . get ( localId ) ; } else if ( other . parent == this ) { foreignId = other . parentToThisMap . get ( localId ) ; } // Cache hit if ( foreignId != null ) { return foreignId ; } Integer integerForeignId = other . store . get ( localKey ) ; // The other map doesn't have an entry for this key if ( integerForeignId == null ) { integerForeignId = other . register ( localKey ) ; } // Add the key/value pair to the cache if ( other == parent ) { thisToParentMap . set ( localId , integerForeignId ) ; parentToThisMap . set ( integerForeignId , localId ) ; } else if ( other . parent == this ) { other . thisToParentMap . set ( integerForeignId , localId ) ; other . parentToThisMap . set ( localId , integerForeignId ) ; } return integerForeignId ; }
Converts an id local to this map to a foreign id local to another map .