private int findIndexByKey ( Object key ) { // Traverse the vector from the back. Given proper locking done at // a higher level, this will ensure that the cache gets to the same // element in the presence of duplicates. // Traversing the vector from the first element causes a problem since // elements are inserted at the end of the vector (for efficiency). // Consequently after inserting duplicate element 1.2, if another // operation is performed on the same key 1, we will get to 1.1 instead // of 1.2 for ( int i = ( size ( ) - 1 ) ; i >= 0 ; -- i ) { Element element = ( Element ) get ( i ) ; if ( element . key . equals ( key ) ) { return i ; } } return - 1 ; }
Return the index of the element with the specified key