X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Frserv%2FMatch.java;fp=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Frserv%2FMatch.java;h=5a036551a4ada06c7a62d4a1026f8379e28e13b9;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=e4eb239d2aa233ff1edb0fe56fffa26cbfb3239b;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/Match.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/Match.java index e4eb239d..5a036551 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/Match.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/rserv/Match.java @@ -34,178 +34,178 @@ import java.util.Set; * */ public class Match { - private Map params; - private byte[] values[]; - private Integer vars[]; - private boolean wildcard; + private Map params; + private byte[] values[]; + private Integer vars[]; + private boolean wildcard; - - /* - * These two methods are pairs of searching performance for variables Spark Style. - * setParams evaluates the target path, and sets a HashMap that will return an Integer. - * the Keys are both :key and key so that there will be no string operations during - * a transaction - * - * For the Integer, if the High Order is 0, then it is just one value. If High Order >0, then it is - * a multi-field option, i.e. ending with a wild-card. - */ - public Match(String path) { - // IF DEBUG: System.out.print("\n[" + path + "]"); - params = new HashMap<>(); - if(path!=null) { - String[] pa = path.split("/"); - values = new byte[pa.length][]; - vars = new Integer[pa.length]; - - int val = 0; - String key; - for(int i=0;i1) { - /* remove * from value */ - int newlength = values[i].length-1; - byte[] real = new byte[newlength]; - System.arraycopy(values[i],0,real,0,newlength); - values[i]=real; - } else { - vars[i]=0; // this is actually a variable, if it only contains a "*" - } - } - // vars[i]=null; - } - } - } - } + + /* + * These two methods are pairs of searching performance for variables Spark Style. + * setParams evaluates the target path, and sets a HashMap that will return an Integer. + * the Keys are both :key and key so that there will be no string operations during + * a transaction + * + * For the Integer, if the High Order is 0, then it is just one value. If High Order >0, then it is + * a multi-field option, i.e. ending with a wild-card. + */ + public Match(String path) { + // IF DEBUG: System.out.print("\n[" + path + "]"); + params = new HashMap<>(); + if(path!=null) { + String[] pa = path.split("/"); + values = new byte[pa.length][]; + vars = new Integer[pa.length]; + + int val = 0; + String key; + for(int i=0;i1) { + /* remove * from value */ + int newlength = values[i].length-1; + byte[] real = new byte[newlength]; + System.arraycopy(values[i],0,real,0,newlength); + values[i]=real; + } else { + vars[i]=0; // this is actually a variable, if it only contains a "*" + } + } + // vars[i]=null; + } + } + } + } - /* - * This is the second of the param evaluation functions. First, we look up to see if there is - * any reference by key in the params Map created by the above. - * - * The resulting Integer, if not null, is split high/low order into start and end. - * We evaluate the string for '/', rather than splitting into String[] to avoid the time/mem needed - * We traverse to the proper field number for slash, evaluate the end (whether wild card or no), - * and return the substring. - * - * The result is something less than .003 milliseconds per evaluation - * - */ - public String param(String path,String key) { - Integer val = params.get(key); // :key or key - if(val!=null) { - int start = val & 0xFFFF; - int end = (val >> 16) & 0xFFFF; - int idx = -1; - int i; - for(i=0;i> 16) & 0xFFFF; + int idx = -1; + int i; + for(i=0;i0?(pabytes[0]=='/'):false; - // IF DEBUG: System.out.println("\n -- " + path + " --"); - for(int i=0;rv && i=lastField) { // checking here allows there to be a non-functional ending / - rv = false; - break; - } - if(values[field]==null) { // it's a variable, just look for /s - if(wildcard && field==lastField-1) return true;// we've made it this far. We accept all remaining characters - Integer val = vars[field]; - int start = val & 0xFFFF; - int end = (val >> 16) & 0xFFFF; - if(end==0)end=start+1; - int k = i; - for(int j=start; ji)i=k-1; // if we've incremented, have to accommodate the outer for loop incrementing as well - fieldMatched = false; // reset - fieldIdx = 0; - } else { - // IF DEBUG: System.out.print((char)pabytes[i]); - if(pabytes[i]=='/') { // end of field, eval if Field is matched - // if double slash, check if supposed to be empty - if(fieldIdx==0 && values[field].length==0) { - fieldMatched = true; - } - rv = fieldMatched && ++field getParamNames() { - return params.keySet(); - } + int lastField = values.length; + int lastByte = pabytes.length; + boolean fieldMatched = false; // = lastByte>0?(pabytes[0]=='/'):false; + // IF DEBUG: System.out.println("\n -- " + path + " --"); + for(int i=0;rv && i=lastField) { // checking here allows there to be a non-functional ending / + rv = false; + break; + } + if(values[field]==null) { // it's a variable, just look for /s + if(wildcard && field==lastField-1) return true;// we've made it this far. We accept all remaining characters + Integer val = vars[field]; + int start = val & 0xFFFF; + int end = (val >> 16) & 0xFFFF; + if(end==0)end=start+1; + int k = i; + for(int j=start; ji)i=k-1; // if we've incremented, have to accommodate the outer for loop incrementing as well + fieldMatched = false; // reset + fieldIdx = 0; + } else { + // IF DEBUG: System.out.print((char)pabytes[i]); + if(pabytes[i]=='/') { // end of field, eval if Field is matched + // if double slash, check if supposed to be empty + if(fieldIdx==0 && values[field].length==0) { + fieldMatched = true; + } + rv = fieldMatched && ++field getParamNames() { + return params.keySet(); + } } \ No newline at end of file