static int hops(GeneralNameInterface base,GeneralNameInterface test,int incomparable){
  int baseRtest=base.constrains(test);
switch (baseRtest) {
case GeneralNameInterface.NAME_DIFF_TYPE:
    if (debug != null) {
      debug.println("Builder.hops(): Names are different types");
    }
  return incomparable;
case GeneralNameInterface.NAME_SAME_TYPE:
break;
case GeneralNameInterface.NAME_MATCH:
return 0;
case GeneralNameInterface.NAME_WIDENS:
return (test.subtreeDepth() - base.subtreeDepth());
case GeneralNameInterface.NAME_NARROWS:
return (test.subtreeDepth() - base.subtreeDepth());
default :
return incomparable;
}
if (base.getType() != GeneralNameInterface.NAME_DIRECTORY) {
if (debug != null) {
debug.println("Builder.hops(): hopDistance not implemented " + "for this name type");
}
return incomparable;
}
X500Name baseName=(X500Name)base;
X500Name testName=(X500Name)test;
X500Name commonName=baseName.commonAncestor(testName);
if (commonName == null) {
if (debug != null) {
debug.println("Builder.hops(): Names are in different " + "namespaces");
}
return incomparable;
}
 else {
int commonDistance=commonName.subtreeDepth();
int baseDistance=baseName.subtreeDepth();
int testDistance=testName.subtreeDepth();
return (baseDistance + testDistance - (2 * commonDistance));
}
}

static int hops ( GeneralNameInterface base , GeneralNameInterface test , int incomparable ) { int baseRtest = base . constrains ( test ) ; switch ( baseRtest ) { case GeneralNameInterface . NAME_DIFF_TYPE : if ( debug != null ) { debug . println ( "Builder.hops(): Names are different types" ) ; } return incomparable ; case GeneralNameInterface . NAME_SAME_TYPE : break ; case GeneralNameInterface . NAME_MATCH : return 0 ; case GeneralNameInterface . NAME_WIDENS : return ( test . subtreeDepth ( ) - base . subtreeDepth ( ) ) ; case GeneralNameInterface . NAME_NARROWS : return ( test . subtreeDepth ( ) - base . subtreeDepth ( ) ) ; default : return incomparable ; } if ( base . getType ( ) != GeneralNameInterface . NAME_DIRECTORY ) { if ( debug != null ) { debug . println ( "Builder.hops(): hopDistance not implemented " + "for this name type" ) ; } return incomparable ; } X500Name baseName = ( X500Name ) base ; X500Name testName = ( X500Name ) test ; X500Name commonName = baseName . commonAncestor ( testName ) ; if ( commonName == null ) { if ( debug != null ) { debug . println ( "Builder.hops(): Names are in different " + "namespaces" ) ; } return incomparable ; } else { int commonDistance = commonName . subtreeDepth ( ) ; int baseDistance = baseName . subtreeDepth ( ) ; int testDistance = testName . subtreeDepth ( ) ; return ( baseDistance + testDistance - ( 2 * commonDistance ) ) ; } }
get hop distance of one generalname from another in links where the names need not have an ancestor / descendant relationship . for example , the hop distance from ou = d , ou = c , o = b , c = us to ou = f , ou = e , ou = c , o = b , c = us is 3 : d - > c , c - > e , e - > f . the hop distance from ou = c , o = b , c = us to ou = d , ou = c , o = b , c = us is - 1 : c - > d
