Class InternalUtilities
java.lang.Object
com.github.lgooddatepicker.zinternaltools.InternalUtilities
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic 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, Returns a double with the currently running java version.static String
getJavaRunningVersionAsString, Returns a string with the currently running java version.static String
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, 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.
-
Constructor Details
-
InternalUtilities
public InternalUtilities()
-
-
Method Details
-
areObjectsEqual
areObjectsEqual, This function exists as a workaround for the fact that Objects.equals() did not exist in Java 1.6. Returnstrue
if the arguments are equal to each other andfalse
otherwise. Consequently, if both arguments arenull
,true
is returned and if exactly one argument isnull
,false
is returned. Otherwise, equality is determined by using theequals
method of the first argument.- Parameters:
a
- an objectb
- an object to be compared witha
for equality- Returns:
true
if the arguments are equal to each other andfalse
otherwise- See Also:
-
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
getJavaRunningVersionAsString, Returns a string with the currently running java version. -
getJavaTargetVersionFromPom
getJavaTargetVersionFromPom, Returns a string with the java "target" version, as it was specified in the pom file at compile time. -
getMostCommonElementInList
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
getProjectVersionString, Returns a string with the project version number. -
getScreenInsets
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
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
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
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
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
getConstraints, This returns a grid bag constraints object that can be used for placing a component appropriately into a grid bag layout. -
isDateVetoed
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
isMouseWithinComponent, This returns true if the mouse is inside of the specified component, otherwise returns false. -
isTimeVetoed
-
safeSubstring
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
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.
-