public static int compareField(JsonObject jsonObj1,JsonObject jsonObj2,String field){
  if (SIGNATURE_FIELDS.contains(field)) {
    String val1=getSignatureFieldValueAsString(jsonObj1,field);
    String val2=getSignatureFieldValueAsString(jsonObj2,field);
    if (val1 != null && val2 != null)     return val1.compareTo(val2);
    return 0;
  }
  JsonElement val1=jsonObj1.get(field);
  JsonElement val2=jsonObj2.get(field);
  if (val1 != null && val2 != null) {
    if (val1.isJsonPrimitive() && val2.isJsonPrimitive()) {
      JsonPrimitive primVal1=(JsonPrimitive)val1;
      JsonPrimitive primVal2=(JsonPrimitive)val2;
      if (primVal1.isNumber() && primVal2.isNumber()) {
        int int1=primVal1.getAsInt();
        int int2=primVal2.getAsInt();
        return int2 - int1;
      }
    }
    String str1=val1.getAsString();
    String str2=val2.getAsString();
    return str1.compareTo(str2);
  }
  return 0;
}

public static int compareField ( JsonObject jsonObj1 , JsonObject jsonObj2 , String field ) { if ( SIGNATURE_FIELDS . contains ( field ) ) { String val1 = getSignatureFieldValueAsString ( jsonObj1 , field ) ; String val2 = getSignatureFieldValueAsString ( jsonObj2 , field ) ; if ( val1 != null && val2 != null ) return val1 . compareTo ( val2 ) ; return 0 ; } JsonElement val1 = jsonObj1 . get ( field ) ; JsonElement val2 = jsonObj2 . get ( field ) ; if ( val1 != null && val2 != null ) { if ( val1 . isJsonPrimitive ( ) && val2 . isJsonPrimitive ( ) ) { JsonPrimitive primVal1 = ( JsonPrimitive ) val1 ; JsonPrimitive primVal2 = ( JsonPrimitive ) val2 ; if ( primVal1 . isNumber ( ) && primVal2 . isNumber ( ) ) { int int1 = primVal1 . getAsInt ( ) ; int int2 = primVal2 . getAsInt ( ) ; return int2 - int1 ; } } String str1 = val1 . getAsString ( ) ; String str2 = val2 . getAsString ( ) ; return str1 . compareTo ( str2 ) ; } return 0 ; }
given two json objects , compares the values of the given field and returns - a negative integer if the first field value is less than the second - a positive integer if the first field value is greater than the second - zero if the first field value is equal to the second
