Browse Source

JNI-132 - Add URIHash() and URITrim()

JNI-132
heck 4 years ago
parent
commit
086c915987
  1. 24
      src/java/foundation/pEp/jniadapter/Utils.java

24
src/java/foundation/pEp/jniadapter/Utils.java

@ -116,12 +116,24 @@ public class Utils {
}
public static boolean URIEqual(String left, String right) {
Pattern pattern = Pattern.compile("^.*?://");
Matcher leftMatcher = pattern.matcher(left.trim());
String leftRelevant = leftMatcher.replaceAll("");
Matcher rightMatcher = pattern.matcher(right.trim());
String rightRelevant = rightMatcher.replaceAll("");
if(left == right) return true;
if(left == null) return false;
if(right == null) return false;
return URITrim(left).equals(URITrim(right));
}
// Returns the hash of a string that represents a URI
// Returns 0 if uri i null
public static int URIHash(String uri) {
if(uri == null) {
return 0;
}
return URITrim(uri).hashCode();
}
return rightRelevant.equals(leftRelevant);
private static String URITrim(String uri) {
Pattern pattern = Pattern.compile("^.*?://");
Matcher leftMatcher = pattern.matcher(uri.trim());
return leftMatcher.replaceAll("");
}
}

Loading…
Cancel
Save