Class Util


  • public class Util
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean enableLog  
      private static java.util.regex.Pattern escapeAssertionRegex  
      private static java.util.regex.Pattern evalReg  
      private static org.slf4j.Logger LOGGER  
      private static java.lang.String md5AlgorithmName  
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean array2DEquals​(java.util.List<java.util.List<java.lang.String>> a, java.util.List<java.util.List<java.lang.String>> b)
      array2DEquals determines whether two 2-dimensional string arrays are identical.
      static boolean arrayEquals​(java.util.List<java.lang.String> a, java.util.List<java.lang.String> b)
      arrayEquals determines whether two string arrays are identical.
      static java.util.List<java.lang.String> arrayRemoveDuplicates​(java.util.List<java.lang.String> s)
      arrayRemoveDuplicates removes any duplicated elements in a string array preserving the order.
      static java.lang.String arrayToString​(java.util.List<java.lang.String> s)
      arrayToString gets a printable string for a string array.
      static java.lang.String convertInSyntax​(java.lang.String expString)
      convertInSyntax Convert 'in' to 'include' to fit aviatorscript,because aviatorscript don't support native 'in' syntax
      static java.lang.String escapeAssertion​(java.lang.String s)
      escapeAssertion escapes the dots in the assertion, because the expression evaluation doesn't support such variable names.
      private static java.security.MessageDigest getDigest​(java.lang.String algorithm)  
      static boolean hasEval​(java.lang.String exp)  
      static boolean isJsonString​(java.lang.String str)
      Helper method to check if a string is a valid JSON
      static void logEnforce​(java.lang.Object[] request, boolean result, java.util.List<java.lang.String> explain)
      logEnforce prints the log of Enforce.
      static void logPrint​(java.lang.String v)
      logPrint prints the log.
      static void logPrintf​(java.lang.String format, java.lang.String... v)
      logPrintf prints the log with the format.
      static void logPrintfError​(java.lang.String format, java.lang.Object... v)
      logPrintf prints the log with the format as an error.
      static void logPrintfError​(java.lang.String message, java.lang.Throwable t)
      logPrintf prints the log with the format as an error.
      static void logPrintfWarn​(java.lang.String format, java.lang.Object... v)
      logPrintf prints the log with the format as a warning.
      static java.lang.String md5​(java.lang.String data)  
      static java.lang.String paramsToString​(java.lang.String[] s)
      paramsToString gets a printable string for variable number of parameters.
      static java.lang.String removeComments​(java.lang.String s)
      removeComments removes the comments starting with # in the text.
      static java.lang.String replaceEval​(java.lang.String s, java.lang.String replacement)  
      static boolean setEquals​(java.util.List<java.lang.String> a, java.util.List<java.lang.String> b)
      setEquals determines whether two string sets are identical.
      static java.lang.String[] splitCommaDelimited​(java.lang.String s)
      splitCommaDelimited splits a comma-delimited string according to the default processing method of the CSV file into a string array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • enableLog

        public static boolean enableLog
      • evalReg

        private static java.util.regex.Pattern evalReg
      • escapeAssertionRegex

        private static java.util.regex.Pattern escapeAssertionRegex
      • LOGGER

        private static org.slf4j.Logger LOGGER
      • md5AlgorithmName

        private static final java.lang.String md5AlgorithmName
        See Also:
        Constant Field Values
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • logPrint

        public static void logPrint​(java.lang.String v)
        logPrint prints the log.
        Parameters:
        v - the log.
      • logPrintf

        public static void logPrintf​(java.lang.String format,
                                     java.lang.String... v)
        logPrintf prints the log with the format.
        Parameters:
        format - the format of the log.
        v - the log.
      • logPrintfWarn

        public static void logPrintfWarn​(java.lang.String format,
                                         java.lang.Object... v)
        logPrintf prints the log with the format as a warning.
        Parameters:
        format - the format of the log.
        v - the log.
      • logPrintfError

        public static void logPrintfError​(java.lang.String format,
                                          java.lang.Object... v)
        logPrintf prints the log with the format as an error.
        Parameters:
        format - the format of the log.
        v - the log.
      • logPrintfError

        public static void logPrintfError​(java.lang.String message,
                                          java.lang.Throwable t)
        logPrintf prints the log with the format as an error.
        Parameters:
        message - the message accompanying the exception
        t - the exception (throwable) to log
      • logEnforce

        public static void logEnforce​(java.lang.Object[] request,
                                      boolean result,
                                      java.util.List<java.lang.String> explain)
        logEnforce prints the log of Enforce.
        Parameters:
        request - the Enforce request.
        result - the Enforce result.
        explain - to explain enforcement by matched rules.
      • escapeAssertion

        public static java.lang.String escapeAssertion​(java.lang.String s)
        escapeAssertion escapes the dots in the assertion, because the expression evaluation doesn't support such variable names.
        Parameters:
        s - the value of the matcher and effect assertions.
        Returns:
        the escaped value.
      • convertInSyntax

        public static java.lang.String convertInSyntax​(java.lang.String expString)
        convertInSyntax Convert 'in' to 'include' to fit aviatorscript,because aviatorscript don't support native 'in' syntax
        Parameters:
        expString - the value of the matcher
        Returns:
        the 'include' expression.
      • removeComments

        public static java.lang.String removeComments​(java.lang.String s)
        removeComments removes the comments starting with # in the text.
        Parameters:
        s - a line in the model.
        Returns:
        the line without comments.
      • arrayEquals

        public static boolean arrayEquals​(java.util.List<java.lang.String> a,
                                          java.util.List<java.lang.String> b)
        arrayEquals determines whether two string arrays are identical.
        Parameters:
        a - the first array.
        b - the second array.
        Returns:
        whether a equals to b.
      • array2DEquals

        public static boolean array2DEquals​(java.util.List<java.util.List<java.lang.String>> a,
                                            java.util.List<java.util.List<java.lang.String>> b)
        array2DEquals determines whether two 2-dimensional string arrays are identical.
        Parameters:
        a - the first 2-dimensional array.
        b - the second 2-dimensional array.
        Returns:
        whether a equals to b.
      • arrayRemoveDuplicates

        public static java.util.List<java.lang.String> arrayRemoveDuplicates​(java.util.List<java.lang.String> s)
        arrayRemoveDuplicates removes any duplicated elements in a string array preserving the order.
        Parameters:
        s - the array.
        Returns:
        the array without duplicates.
      • arrayToString

        public static java.lang.String arrayToString​(java.util.List<java.lang.String> s)
        arrayToString gets a printable string for a string array.
        Parameters:
        s - the array.
        Returns:
        the string joined by the array elements.
      • paramsToString

        public static java.lang.String paramsToString​(java.lang.String[] s)
        paramsToString gets a printable string for variable number of parameters.
        Parameters:
        s - the parameters.
        Returns:
        the string joined by the parameters.
      • splitCommaDelimited

        public static java.lang.String[] splitCommaDelimited​(java.lang.String s)
        splitCommaDelimited splits a comma-delimited string according to the default processing method of the CSV file into a string array. It assumes that any number of whitespace might exist before or after the token and that tokens do not include whitespace as part of their value unless they are enclosed by double quotes.
        Parameters:
        s - the string.
        Returns:
        the array with the string tokens.
      • setEquals

        public static boolean setEquals​(java.util.List<java.lang.String> a,
                                        java.util.List<java.lang.String> b)
        setEquals determines whether two string sets are identical.
        Parameters:
        a - the first set.
        b - the second set.
        Returns:
        whether a equals to b.
      • hasEval

        public static boolean hasEval​(java.lang.String exp)
      • replaceEval

        public static java.lang.String replaceEval​(java.lang.String s,
                                                   java.lang.String replacement)
      • md5

        public static java.lang.String md5​(java.lang.String data)
      • getDigest

        private static java.security.MessageDigest getDigest​(java.lang.String algorithm)
      • isJsonString

        public static boolean isJsonString​(java.lang.String str)
        Helper method to check if a string is a valid JSON
        Parameters:
        str - the string to be checked.
        Returns:
        whether the string is a valid