Browse Source

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

JNI-132
heck 1 year ago
parent
commit
086c915987
1 changed files with 18 additions and 6 deletions
  1. +18
    -6
      src/java/foundation/pEp/jniadapter/Utils.java

+ 18
- 6
src/java/foundation/pEp/jniadapter/Utils.java View File

@ -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