@ Override public Object getKeyMapping ( String key ) { if ( key == null ) { throw new IllegalArgumentException ( "Not supporting null keys" ) ; } // ChunkCacheKey: "C|" + fileName + "|" + chunkId + "|" + bufferSize "|" + indexName + "|" + affinitySegmentId; // FileCacheKey : "M|" + fileName + "|"+ indexName + "|" + affinitySegmentId; // FileListCacheKey : "*|" + indexName + "|" + affinitySegmentId; // FileReadLockKey : "RL|" + fileName + "|"+ indexName + "|" + affinitySegmentId; String [ ] split = singlePipePattern . split ( key ) ; switch ( split [ 0 ] ) { case "C" : { if ( split . length != 6 ) { throw log . keyMappperUnexpectedStringFormat ( key ) ; } final String indexName = split [ 4 ] ; final String fileName = split [ 1 ] ; final int chunkId = toInt ( split [ 2 ] , key ) ; final int bufferSize = toInt ( split [ 3 ] , key ) ; final int affinitySegmentId = toInt ( split [ 5 ] , key ) ; return new ChunkCacheKey ( indexName , fileName , chunkId , bufferSize , affinitySegmentId ) ; } case "M" : { if ( split . length != 4 ) throw log . keyMappperUnexpectedStringFormat ( key ) ; final String indexName = split [ 2 ] ; final String fileName = split [ 1 ] ; final int affinitySegmentId = toInt ( split [ 3 ] , key ) ; return new FileCacheKey ( indexName , fileName , affinitySegmentId ) ; } case "*" : { if ( split . length != 3 ) throw log . keyMappperUnexpectedStringFormat ( key ) ; final String indexName = split [ 1 ] ; final int affinitySegmentId = toInt ( split [ 2 ] , key ) ; return new FileListCacheKey ( indexName , affinitySegmentId ) ; } case "RL" : { if ( split . length != 4 ) throw log . keyMappperUnexpectedStringFormat ( key ) ; final String indexName = split [ 2 ] ; final String fileName = split [ 1 ] ; final int affinitySegmentId = toInt ( split [ 3 ] , key ) ; return new FileReadLockKey ( indexName , fileName , affinitySegmentId ) ; } default : throw log . keyMappperUnexpectedStringFormat ( key ) ; } }
This method has to perform the inverse transformation of the keys used in the Lucene Directory from String to object . So this implementation is strongly coupled to the toString method of each key type .