Package ninja.utils

Class SwissKnife


  • public class SwissKnife
    extends Object
    A helper class that contains a lot of random stuff that helps to get things done.
    Author:
    ra
    • Constructor Detail

      • SwissKnife

        public SwissKnife()
    • Method Detail

      • loadConfigurationInUtf8

        public static org.apache.commons.configuration.PropertiesConfiguration loadConfigurationInUtf8​(String fileOrUrlOrClasspathUrl)
        This is important: We load stuff as UTF-8. We are using in the default Apache Commons loading mechanism. With two little tweaks: 1. We don't accept any delimimter by default 2. We are reading in UTF-8 More about that: http://commons.apache.org/configuration/userguide/howto_filebased .html#Loading From the docs: - If the combination from base path and file name is a full URL that points to an existing file, this URL will be used to load the file. - If the combination from base path and file name is an absolute file name and this file exists, it will be loaded. - If the combination from base path and file name is a relative file path that points to an existing file, this file will be loaded. - If a file with the specified name exists in the user's home directory, this file will be loaded. - Otherwise the file name is interpreted as a resource name, and it is checked whether the data file can be loaded from the classpath.
        Parameters:
        fileOrUrlOrClasspathUrl - Location of the file. Can be on file system, or on the classpath. Will both work.
        Returns:
        A PropertiesConfiguration or null if there were problems getting it.
      • getRealClassNameLowerCamelCase

        public static String getRealClassNameLowerCamelCase​(Object object)
        Returns the lower class name. Eg. A class named MyObject will become "myObject".
        Parameters:
        object - Object for which to return the lowerCamelCaseName
        Returns:
        the lowerCamelCaseName of the Object
      • doesClassExist

        public static boolean doesClassExist​(String nameWithPackage,
                                             Object instanceToGetClassloaderFrom)
        Used to check whether a class exists on the classpath.
        Parameters:
        nameWithPackage - for instance com.example.conf.GloablFilters
        instanceToGetClassloaderFrom - usually "this" if you call this method.
        Returns:
        true if class exists, false if not.