public int deleteEntries(PrincipalName service,int etype,int kvno){
  int count=0;
  Map<Integer,Integer> highest=new HashMap<>();
  for (int i=entries.size() - 1; i >= 0; i--) {
    KeyTabEntry e=entries.get(i);
    if (service.match(e.getService())) {
      if (etype == -1 || e.keyType == etype) {
        if (kvno == -2) {
          if (highest.containsKey(e.keyType)) {
            int n=highest.get(e.keyType);
            if (e.keyVersion > n) {
              highest.put(e.keyType,e.keyVersion);
            }
          }
 else {
            highest.put(e.keyType,e.keyVersion);
          }
        }
 else         if (kvno == -1 || e.keyVersion == kvno) {
          entries.removeElementAt(i);
          count++;
        }
      }
    }
  }
  if (kvno == -2) {
    for (int i=entries.size() - 1; i >= 0; i--) {
      KeyTabEntry e=entries.get(i);
      if (service.match(e.getService())) {
        if (etype == -1 || e.keyType == etype) {
          int n=highest.get(e.keyType);
          if (e.keyVersion != n) {
            entries.removeElementAt(i);
            count++;
          }
        }
      }
    }
  }
  return count;
}

public int deleteEntries ( PrincipalName service , int etype , int kvno ) { int count = 0 ; Map < Integer , Integer > highest = new HashMap < > ( ) ; for ( int i = entries . size ( ) - 1 ; i >= 0 ; i -- ) { KeyTabEntry e = entries . get ( i ) ; if ( service . match ( e . getService ( ) ) ) { if ( etype == - 1 || e . keyType == etype ) { if ( kvno == - 2 ) { if ( highest . containsKey ( e . keyType ) ) { int n = highest . get ( e . keyType ) ; if ( e . keyVersion > n ) { highest . put ( e . keyType , e . keyVersion ) ; } } else { highest . put ( e . keyType , e . keyVersion ) ; } } else if ( kvno == - 1 || e . keyVersion == kvno ) { entries . removeElementAt ( i ) ; count ++ ; } } } } if ( kvno == - 2 ) { for ( int i = entries . size ( ) - 1 ; i >= 0 ; i -- ) { KeyTabEntry e = entries . get ( i ) ; if ( service . match ( e . getService ( ) ) ) { if ( etype == - 1 || e . keyType == etype ) { int n = highest . get ( e . keyType ) ; if ( e . keyVersion != n ) { entries . removeElementAt ( i ) ; count ++ ; } } } } } return count ; }
removes entries from the key table .
