private boolean inSamePackage(Class<?> c1,Class<?> c2){
  String nameC1=c1.getName();
  String nameC2=c2.getName();
  int indexDotC1=nameC1.lastIndexOf('.');
  int indexDotC2=nameC2.lastIndexOf('.');
  if (indexDotC1 != indexDotC2) {
    return false;
  }
  if (indexDotC1 == -1) {
    return true;
  }
  return nameC1.regionMatches(0,nameC2,0,indexDotC1);
}

private boolean inSamePackage ( Class < ? > c1 , Class < ? > c2 ) { String nameC1 = c1 . getName ( ) ; String nameC2 = c2 . getName ( ) ; int indexDotC1 = nameC1 . lastIndexOf ( '.' ) ; int indexDotC2 = nameC2 . lastIndexOf ( '.' ) ; if ( indexDotC1 != indexDotC2 ) { return false ; } if ( indexDotC1 == - 1 ) { return true ; } return nameC1 . regionMatches ( 0 , nameC2 , 0 , indexDotC1 ) ; }
checks if two classes belong to the same package .
