Class InternalUtilities

java.lang.Object
com.github.lgooddatepicker.zinternaltools.InternalUtilities

public class InternalUtilities extends 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.
  • Constructor Details

    • InternalUtilities

      public InternalUtilities()
  • Method Details

    • areObjectsEqual

      public static boolean areObjectsEqual(Object a, 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:
    • doesParsedDateMatchText

      public static boolean doesParsedDateMatchText(LocalDate parsedDate, String text, DateTimeFormatter usedFormatter)
      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. Testing note: Invalid dates this function should detect are 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 String getJavaRunningVersionAsString()
      getJavaRunningVersionAsString, Returns a string with the currently running java version.
    • getJavaTargetVersionFromPom

      public static 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(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 String getProjectVersionString()
      getProjectVersionString, Returns a string with the project version number.
    • getScreenInsets

      public static Insets getScreenInsets(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 Rectangle getScreenTotalArea(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 Rectangle getScreenWorkingArea(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 DateTimeFormatter generateDefaultFormatterCE(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 DateTimeFormatter generateDefaultFormatterBCE(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 LocalDate getParsedDateOrNull(String text, DateTimeFormatter displayFormatterAD, DateTimeFormatter displayFormatterBC, ArrayList<DateTimeFormatter> parsingFormatters)
      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 LocalTime getParsedTimeOrNull(String timeText, DateTimeFormatter formatForDisplayTime, DateTimeFormatter formatForMenuTimes, ArrayList<DateTimeFormatter> formatsForParsing, Locale timePickerLocale)
    • getConstraints

      public static 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, 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(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, LocalTime time)
    • safeSubstring

      public static String safeSubstring(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(InputStream classByteStream, boolean majorVersionRequested) throws 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:
      Exception
    • getCompiledJavaMajorVersionFromJavaClassFileAsString

      public static String getCompiledJavaMajorVersionFromJavaClassFileAsString(InputStream classByteStream) throws 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:
      Exception
    • setDefaultTableEditorsClicks

      public static void setDefaultTableEditorsClicks(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.