Class InternalUtilities


  • public class InternalUtilities
    extends java.lang.Object
    InternalUtilities, This class contains static functions that are used by the date picker or the calendar panel. Some of these functions are large, and were separated out of the date picker class or calendar panel class in order to improve the readability of those classes.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean areObjectsEqual​(java.lang.Object a, java.lang.Object b)
      areObjectsEqual, This function exists as a workaround for the fact that Objects.equals() did not exist in Java 1.6.
      static boolean doesParsedDateMatchText​(java.time.LocalDate parsedDate, java.lang.String text, java.util.Locale formatLocale)
      doesParsedDateMatchText, This compares the numbers in a parsed date, to the original text from which the date was parsed.
      static java.time.format.DateTimeFormatter generateDefaultFormatterBCE​(java.util.Locale pickerLocale)
      generateDefaultFormatterBCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing BC dates.
      static java.time.format.DateTimeFormatter generateDefaultFormatterCE​(java.util.Locale pickerLocale)
      generateDefaultFormatterCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing AD dates.
      static java.lang.String getCompiledJavaMajorVersionFromJavaClassFileAsString​(java.io.InputStream classByteStream)
      getCompiledJavaMajorVersionFromJavaClassFileAsString, Given an input stream to a Java class file, this will return the major version of Java that was used to compile the file (as a string).
      static int getCompiledJavaVersionFromJavaClassFile​(java.io.InputStream classByteStream, boolean majorVersionRequested)
      getCompiledJavaVersionFromJavaClassFile, Given an input stream to a Java class file, this will return the major or minor version of Java that was used to compile the file.
      static java.awt.GridBagConstraints getConstraints​(int gridx, int gridy)
      getConstraints, This returns a grid bag constraints object that can be used for placing a component appropriately into a grid bag layout.
      static double getJavaRunningVersionAsDouble()
      getJavaRunningVersionAsDouble, Returns a double with the currently running java version.
      static java.lang.String getJavaRunningVersionAsString()
      getJavaRunningVersionAsString, Returns a string with the currently running java version.
      static java.lang.String getJavaTargetVersionFromPom()
      getJavaTargetVersionFromPom, Returns a string with the java "target" version, as it was specified in the pom file at compile time.
      static <T> T getMostCommonElementInList​(java.util.List<T> sourceList)
      getMostCommonElementInList, This returns the most common element in the supplied list.
      static java.time.LocalDate getParsedDateOrNull​(java.lang.String text, java.time.format.DateTimeFormatter displayFormatterAD, java.time.format.DateTimeFormatter displayFormatterBC, java.util.ArrayList<java.time.format.DateTimeFormatter> parsingFormatters, java.util.Locale formatLocale)
      getParsedDateOrNull, This takes text from the date picker text field, and tries to parse it into a java.time.LocalDate instance.
      static java.time.LocalTime getParsedTimeOrNull​(java.lang.String timeText, java.time.format.DateTimeFormatter formatForDisplayTime, java.time.format.DateTimeFormatter formatForMenuTimes, java.util.ArrayList<java.time.format.DateTimeFormatter> formatsForParsing, java.util.Locale timePickerLocale)  
      static java.lang.String getProjectVersionString()
      getProjectVersionString, Returns a string with the project version number.
      static java.awt.Insets getScreenInsets​(java.awt.Window windowOrNull)
      getScreenInsets, This returns the insets of the screen, which are defined by any task bars that have been set up by the user.
      static java.awt.Rectangle getScreenTotalArea​(java.awt.Window windowOrNull)
      getScreenTotalArea, This returns the total area of the screen.
      static java.awt.Rectangle getScreenWorkingArea​(java.awt.Window windowOrNull)
      getScreenWorkingArea, This returns the working area of the screen.
      static boolean isDateVetoed​(DateVetoPolicy policy, java.time.LocalDate date)
      isDateVetoed, This is a convenience function for checking whether or not a particular date is vetoed.
      static boolean isMouseWithinComponent​(java.awt.Component component)
      isMouseWithinComponent, This returns true if the mouse is inside of the specified component, otherwise returns false.
      static boolean isTimeVetoed​(TimeVetoPolicy policy, java.time.LocalTime time)  
      static java.lang.String safeSubstring​(java.lang.String text, int beginIndex, int endIndexExclusive)
      safeSubstring, This is a version of the substring function which is guaranteed to never throw an exception.
      static void setDefaultTableEditorsClicks​(javax.swing.JTable table, int clickCountToStart)
      setDefaultTableEditorsClicks, This sets the number of clicks required to start the default table editors in the supplied table.
      • Methods inherited from class java.lang.Object

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

      • InternalUtilities

        public InternalUtilities()
    • Method Detail

      • areObjectsEqual

        public static boolean areObjectsEqual​(java.lang.Object a,
                                              java.lang.Object b)
        areObjectsEqual, This function exists as a workaround for the fact that Objects.equals() did not exist in Java 1.6. Returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null, true is returned and if exactly one argument is null, false is returned. Otherwise, equality is determined by using the equals method of the first argument.
        Parameters:
        a - an object
        b - an object to be compared with a for equality
        Returns:
        true if the arguments are equal to each other and false otherwise
        See Also:
        Object.equals(Object)
      • doesParsedDateMatchText

        public static boolean doesParsedDateMatchText​(java.time.LocalDate parsedDate,
                                                      java.lang.String text,
                                                      java.util.Locale formatLocale)
        doesParsedDateMatchText, This compares the numbers in a parsed date, to the original text from which the date was parsed. Specifically this compares the day of the month and the year of the parsed date to the text. On a technical note, this function is not aware of which field is which, but that ambiguity does not prevent it from performing a successful comparison on all tested cases. This will return true if the dates are a match, or otherwise return false. Testing note: This function has been thoroughly tested and gives the proper result with all valid and invalid dates in the years between -10000 and 10000 inclusive. Valid dates are defined as those dates that are returned from the LocalDate class, when using the localDate.plusDays(1) function. Invalid dates are defined as any of the following: The 31st day of February, April, June, September, or November. The 30th day of February. Or the 29th day of February on any year that is not a leap year.
      • getJavaRunningVersionAsDouble

        public static double getJavaRunningVersionAsDouble()
        getJavaRunningVersionAsDouble, Returns a double with the currently running java version.
      • getJavaRunningVersionAsString

        public static java.lang.String getJavaRunningVersionAsString()
        getJavaRunningVersionAsString, Returns a string with the currently running java version.
      • getJavaTargetVersionFromPom

        public static java.lang.String getJavaTargetVersionFromPom()
        getJavaTargetVersionFromPom, Returns a string with the java "target" version, as it was specified in the pom file at compile time.
      • getMostCommonElementInList

        public static <T> T getMostCommonElementInList​(java.util.List<T> sourceList)
        getMostCommonElementInList, This returns the most common element in the supplied list. In the event of a tie, any element that is tied as the "largest element" may be returned. If the list has no elements, or if the list is null, then this will return null. This can also return null if null happens to be the most common element in the source list.
      • getProjectVersionString

        public static java.lang.String getProjectVersionString()
        getProjectVersionString, Returns a string with the project version number.
      • getScreenInsets

        public static java.awt.Insets getScreenInsets​(java.awt.Window windowOrNull)
        getScreenInsets, This returns the insets of the screen, which are defined by any task bars that have been set up by the user. This function accounts for multi-monitor setups. If a window is supplied, then the the monitor that contains the window will be used. If a window is not supplied, then the primary monitor will be used.
      • getScreenTotalArea

        public static java.awt.Rectangle getScreenTotalArea​(java.awt.Window windowOrNull)
        getScreenTotalArea, This returns the total area of the screen. (The total area includes any task bars.) This function accounts for multi-monitor setups. If a window is supplied, then the the monitor that contains the window will be used. If a window is not supplied, then the primary monitor will be used.
      • getScreenWorkingArea

        public static java.awt.Rectangle getScreenWorkingArea​(java.awt.Window windowOrNull)
        getScreenWorkingArea, This returns the working area of the screen. (The working area excludes any task bars.) This function accounts for multi-monitor setups. If a window is supplied, then the the monitor that contains the window will be used. If a window is not supplied, then the primary monitor will be used.
      • generateDefaultFormatterCE

        public static java.time.format.DateTimeFormatter generateDefaultFormatterCE​(java.util.Locale pickerLocale)
        generateDefaultFormatterCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing AD dates. The formatter is generated from the default FormatStyle.LONG formatter in the specified locale.
      • generateDefaultFormatterBCE

        public static java.time.format.DateTimeFormatter generateDefaultFormatterBCE​(java.util.Locale pickerLocale)
        generateDefaultFormatterBCE, This returns a default formatter for the specified locale, that can be used for displaying or parsing BC dates. The formatter is generated from the default FormatStyle.LONG formatter in the specified locale. The resulting format is intended to be nearly identical to the default formatter used for AD dates.
      • getParsedDateOrNull

        public static java.time.LocalDate getParsedDateOrNull​(java.lang.String text,
                                                              java.time.format.DateTimeFormatter displayFormatterAD,
                                                              java.time.format.DateTimeFormatter displayFormatterBC,
                                                              java.util.ArrayList<java.time.format.DateTimeFormatter> parsingFormatters,
                                                              java.util.Locale formatLocale)
        getParsedDateOrNull, This takes text from the date picker text field, and tries to parse it into a java.time.LocalDate instance. If the text cannot be parsed, this will return null. Implementation note: The DateTimeFormatter parsing class was accepting invalid dates like February 31st, and returning the last valid date of the month, like Feb 28. This could be seen as an attempt to be lenient, but in the context of the date picker class it is considered a mistake or a bug. There was no setting to disable that functionality. So, this function calls another function called doesParsedDateMatchText(), to analyze and reject those kinds of mistakes. If the parsed text does not match the day of the month (and year) of the parsed date, then this function will return null.
      • getParsedTimeOrNull

        public static java.time.LocalTime getParsedTimeOrNull​(java.lang.String timeText,
                                                              java.time.format.DateTimeFormatter formatForDisplayTime,
                                                              java.time.format.DateTimeFormatter formatForMenuTimes,
                                                              java.util.ArrayList<java.time.format.DateTimeFormatter> formatsForParsing,
                                                              java.util.Locale timePickerLocale)
      • getConstraints

        public static java.awt.GridBagConstraints getConstraints​(int gridx,
                                                                 int gridy)
        getConstraints, This returns a grid bag constraints object that can be used for placing a component appropriately into a grid bag layout.
      • isDateVetoed

        public static boolean isDateVetoed​(DateVetoPolicy policy,
                                           java.time.LocalDate date)
        isDateVetoed, This is a convenience function for checking whether or not a particular date is vetoed. Note that veto policies do not have any say about null dates, so this function always returns false for null dates.
      • isMouseWithinComponent

        public static boolean isMouseWithinComponent​(java.awt.Component component)
        isMouseWithinComponent, This returns true if the mouse is inside of the specified component, otherwise returns false.
      • isTimeVetoed

        public static boolean isTimeVetoed​(TimeVetoPolicy policy,
                                           java.time.LocalTime time)
      • safeSubstring

        public static java.lang.String safeSubstring​(java.lang.String text,
                                                     int beginIndex,
                                                     int endIndexExclusive)
        safeSubstring, This is a version of the substring function which is guaranteed to never throw an exception. If the supplied string is null then this will return null. If the beginIndex or endIndexExclusive are out of range for the string, then the indexes will be compressed to fit within the bounds of the supplied string. If the beginIndex is greater than or equal to endIndexExclusive, then this will return an empty string.
      • getCompiledJavaVersionFromJavaClassFile

        public static int getCompiledJavaVersionFromJavaClassFile​(java.io.InputStream classByteStream,
                                                                  boolean majorVersionRequested)
                                                           throws java.lang.Exception
        getCompiledJavaVersionFromJavaClassFile, Given an input stream to a Java class file, this will return the major or minor version of Java that was used to compile the file. In a Maven POM file, this is known as the "target" version of Java that was used to compile the file. Getting an input stream for a class file inside a jar file: InputStream input = getClass().getResourceAsStream("/classpath/to/my/file.class");
        Throws:
        java.lang.Exception
      • getCompiledJavaMajorVersionFromJavaClassFileAsString

        public static java.lang.String getCompiledJavaMajorVersionFromJavaClassFileAsString​(java.io.InputStream classByteStream)
                                                                                     throws java.lang.Exception
        getCompiledJavaMajorVersionFromJavaClassFileAsString, Given an input stream to a Java class file, this will return the major version of Java that was used to compile the file (as a string). In a Maven POM file, this is known as the "target" version of Java that was used to compile the file. Getting an input stream for a class file inside a jar file: InputStream input = getClass().getResourceAsStream("/classpath/to/my/file.class");
        Throws:
        java.lang.Exception
      • setDefaultTableEditorsClicks

        public static void setDefaultTableEditorsClicks​(javax.swing.JTable table,
                                                        int clickCountToStart)
        setDefaultTableEditorsClicks, This sets the number of clicks required to start the default table editors in the supplied table. Typically you would set the table editors to start after 1 click or 2 clicks, as desired. The default table editors of the table editors that are supplied by the JTable class, for Objects, Numbers, and Booleans. Note, the editor which is used to edit Objects, is the same editor used for editing Strings.