com.github.lgooddatepicker.zinternaltools

## 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 Summary

Constructors
Constructor and Description
`InternalUtilities()`

### Method Summary

All Methods Static Methods Concrete Methods
`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.
`static boolean` `doesParsedDateMatchText(LocalDate parsedDate, String text, Locale formatLocale)` doesParsedDateMatchText, This compares the numbers in a parsed date, to the original text from which the date was parsed.
`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.
`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.
`static String` `getCompiledJavaMajorVersionFromJavaClassFileAsString(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(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 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 String` `getJavaRunningVersionAsString()` getJavaRunningVersionAsString, Returns a string with the currently running java version.
`static 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(List<T> sourceList)` getMostCommonElementInList, This returns the most common element in the supplied list.
`static LocalDate` `getParsedDateOrNull(String text, DateTimeFormatter displayFormatterAD, DateTimeFormatter displayFormatterBC, ArrayList<DateTimeFormatter> parsingFormatters, Locale formatLocale)` getParsedDateOrNull, This takes text from the date picker text field, and tries to parse it into a java.time.LocalDate instance.
`static LocalTime` `getParsedTimeOrNull(String timeText, DateTimeFormatter formatForDisplayTime, DateTimeFormatter formatForMenuTimes, ArrayList<DateTimeFormatter> formatsForParsing, Locale timePickerLocale)`
`static String` `getProjectVersionString()` getProjectVersionString, Returns a string with the project version number.
`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.
`static Rectangle` `getScreenTotalArea(Window windowOrNull)` getScreenTotalArea, This returns the total area of the screen.
`static Rectangle` `getScreenWorkingArea(Window windowOrNull)` getScreenWorkingArea, This returns the working area of the screen.
`static boolean` `isDateVetoed(DateVetoPolicy policy, LocalDate date)` isDateVetoed, This is a convenience function for checking whether or not a particular date is vetoed.
`static boolean` `isMouseWithinComponent(Component component)` isMouseWithinComponent, This returns true if the mouse is inside of the specified component, otherwise returns false.
`static boolean` `isTimeVetoed(TimeVetoPolicy policy, LocalTime time)`
`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.
`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.

### 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(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:
  `Object.equals(Object)`

#### doesParsedDateMatchText

    public static boolean doesParsedDateMatchText(LocalDate parsedDate,
                                                  String text,
                                                  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 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,
                                                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 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.