Skip to content

Commit

Permalink
Remove dependency on Jetbrains annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
leewyatt committed May 21, 2024
1 parent 61e0284 commit cb7a4af
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 42 deletions.
6 changes: 0 additions & 6 deletions gemsfx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@

<dependencies>

<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>net.synedra</groupId>
<artifactId>validatorfx</artifactId>
Expand Down
26 changes: 12 additions & 14 deletions gemsfx/src/main/java/com/dlsc/gemsfx/util/EnumUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.dlsc.gemsfx.util;

import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Utility class for working with enums.
Expand All @@ -26,7 +24,7 @@ private EnumUtil() {
* <p> Example: 1. null -> ""
* <p> Example: 2. MY_ENUM_VALUE -> My enum value
*/
public static <T extends Enum<T>> String formatEnumNameAsCapitalized(@Nullable T enumValue) {
public static <T extends Enum<T>> String formatEnumNameAsCapitalized(T enumValue) {
return formatEnumNameAsCapitalized(enumValue, "");
}

Expand All @@ -41,7 +39,7 @@ public static <T extends Enum<T>> String formatEnumNameAsCapitalized(@Nullable T
* <p> Example: 1. null -> nullDefaultValue
* <p> Example: 2. Example: MY_ENUM_VALUE -> My enum value
*/
public static <T extends Enum<T>> String formatEnumNameAsCapitalized(@Nullable T enumValue, @Nullable String nullDefaultValue) {
public static <T extends Enum<T>> String formatEnumNameAsCapitalized(T enumValue, String nullDefaultValue) {
return enumValue == null ? nullDefaultValue : formatEnumNameAsCapitalized(enumValue.name());
}

Expand All @@ -55,7 +53,7 @@ public static <T extends Enum<T>> String formatEnumNameAsCapitalized(@Nullable T
* <p> Example: 1. null -> ""
* <p> Example: 2. Example: MY_ENUM_VALUE -> My enum value
*/
public static <T extends Enum<T>> String formatEnumNameAsCapitalized(@Nullable String enumName) {
public static <T extends Enum<T>> String formatEnumNameAsCapitalized(String enumName) {
return enumName == null ? "" : StringUtils.capitalize(enumName.replace("_", " ").toLowerCase());
}

Expand All @@ -68,7 +66,7 @@ public static <T extends Enum<T>> String formatEnumNameAsCapitalized(@Nullable S
* <p> Example: 1. null -> ""
* <p> Example: 2. MY_ENUM_VALUE -> My Enum Value
*/
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable T enumValue) {
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(T enumValue) {
return formatEnumNameAsTitleCase(enumValue, "");
}

Expand All @@ -82,7 +80,7 @@ public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable T e
* <p> Example: 1. null -> nullDefaultValue
* <p> Example: 2. MY_ENUM_VALUE -> My Enum Value
*/
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable T enumValue, @Nullable String nullDefaultValue) {
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(T enumValue, String nullDefaultValue) {
return formatEnumNameAsTitleCase(enumValue == null ? null : enumValue.name(), nullDefaultValue);
}

Expand All @@ -95,7 +93,7 @@ public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable T e
* <p> Example: 1. null -> ""
* <p> Example: 2. MY_ENUM_VALUE -> My Enum Value
*/
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable String enumName) {
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(String enumName) {
return formatEnumNameAsTitleCase(enumName, "");
}

Expand All @@ -109,7 +107,7 @@ public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable Str
* <p> Example: 1. null -> nullDefaultValue
* <p> Example: 2. MY_ENUM_VALUE -> My Enum Value
*/
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable String enumName, @Nullable String nullDefaultValue) {
public static <T extends Enum<T>> String formatEnumNameAsTitleCase(String enumName, String nullDefaultValue) {
if (enumName == null) {
return nullDefaultValue;
}
Expand Down Expand Up @@ -142,7 +140,7 @@ public static <T extends Enum<T>> String formatEnumNameAsTitleCase(@Nullable Str
* <p> Example: 1. null -> ""
* <p> Example: 2. MY_ENUM_VALUE -> MY ENUM VALUE
*/
public static <T extends Enum<T>> String formatEnumNameAsSpacedWords(@Nullable T enumValue) {
public static <T extends Enum<T>> String formatEnumNameAsSpacedWords(T enumValue) {
return enumValue == null ? "" : enumValue.name().replace("_", " ");
}

Expand All @@ -155,7 +153,7 @@ public static <T extends Enum<T>> String formatEnumNameAsSpacedWords(@Nullable T
* <p> Example: 1. null -> ""
* <p> Example: 2. MY_ENUM_VALUE -> MY ENUM VALUE
*/
public static <T extends Enum<T>> String formatEnumNameAsSpacedWords(@Nullable String enumName) {
public static <T extends Enum<T>> String formatEnumNameAsSpacedWords(String enumName) {
return enumName == null ? "" : enumName.replace("_", " ");
}

Expand All @@ -167,16 +165,16 @@ public static <T extends Enum<T>> String formatEnumNameAsSpacedWords(@Nullable S
* @return A string suitable for use as a CSS class name.
* Example: MY_ENUM_VALUE -> my-enum-value
*/
public static <T extends Enum<T>> String convertToStyleClassName(@NotNull T enumValue) {
public static <T extends Enum<T>> String convertToStyleClassName(T enumValue) {
return enumValue.name().toLowerCase().replace("_", "-");
}

public static <T extends Enum<T>> String[] convertAllToStylesClassName(@NotNull Class<T> enumClass) {
public static <T extends Enum<T>> String[] convertAllToStylesClassName(Class<T> enumClass) {
T[] enumConstants = enumClass.getEnumConstants();
return convertAllToStylesClassName(enumConstants);
}

public static <T extends Enum<T>> String[] convertAllToStylesClassName(@NotNull T[] enumValues) {
public static <T extends Enum<T>> String[] convertAllToStylesClassName(T[] enumValues) {
String[] styles = new String[enumValues.length];
for (int i = 0; i < enumValues.length; i++) {
styles[i] = convertToStyleClassName(enumValues[i]);
Expand Down
26 changes: 12 additions & 14 deletions gemsfx/src/main/java/com/dlsc/gemsfx/util/UIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;
Expand All @@ -26,7 +24,7 @@ private UIUtil() {
* @param node The node to add the style class to.
* @param styleClass The style class to add.
*/
public static void addClassIfAbsent(@Nullable Node node, @NotNull String styleClass) {
public static void addClassIfAbsent(Node node, String styleClass) {
Optional.ofNullable(node).ifPresent(n -> {
if (!n.getStyleClass().contains(styleClass)) {
n.getStyleClass().add(styleClass);
Expand All @@ -40,7 +38,7 @@ public static void addClassIfAbsent(@Nullable Node node, @NotNull String styleCl
* @param node The node to add the style classes to.
* @param styleClasses The style classes to add.
*/
public static void addClassesIfAbsent(@NotNull Node node, @NotNull String... styleClasses) {
public static void addClassesIfAbsent(Node node, String... styleClasses) {
List<String> list = Arrays.stream(styleClasses)
.filter(styleClass -> !node.getStyleClass().contains(styleClass))
.toList();
Expand All @@ -55,7 +53,7 @@ public static void addClassesIfAbsent(@NotNull Node node, @NotNull String... sty
* @param node The node to toggle the style on.
* @param styleClass The style class to add or remove.
*/
public static void toggleClass(@NotNull Node node, @NotNull String styleClass) {
public static void toggleClass(Node node, String styleClass) {
if (node.getStyleClass().contains(styleClass)) {
node.getStyleClass().remove(styleClass);
} else {
Expand All @@ -72,7 +70,7 @@ public static void toggleClass(@NotNull Node node, @NotNull String styleClass) {
* @param styleClass The style class to add or remove.
* @param condition The condition that determines whether to add or remove the style.
*/
public static void toggleClassOnCondition(@NotNull Node node, @NotNull String styleClass, boolean condition) {
public static void toggleClassOnCondition(Node node, String styleClass, boolean condition) {
if (condition) {
addClassIfAbsent(node, styleClass);
} else {
Expand All @@ -90,7 +88,7 @@ public static void toggleClassOnCondition(@NotNull Node node, @NotNull String st
* @param stylesToRemove A list of styles to be removed from the node, except for the styleToAdd.
* @param styleToAdd The style to be added to the node, if it's not already present.
*/
public static void updateStyles(@NotNull Node node, @NotNull List<String> stylesToRemove, @NotNull String styleToAdd) {
public static void updateStyles(Node node, List<String> stylesToRemove, String styleToAdd) {
// Add the style if it's not already present
addClassIfAbsent(node, styleToAdd);

Expand All @@ -109,7 +107,7 @@ public static void updateStyles(@NotNull Node node, @NotNull List<String> styles
* @param stylesToRemove An array of styles to be removed from the node, except for the styleToAdd.
* @param styleToAdd The style to be added to the node, if it's not already present.
*/
public static void updateStyles(@NotNull Node node, @NotNull String[] stylesToRemove, @NotNull String styleToAdd) {
public static void updateStyles(Node node, String[] stylesToRemove, String styleToAdd) {
updateStyles(node, Arrays.asList(stylesToRemove), styleToAdd);
}

Expand All @@ -120,7 +118,7 @@ public static void updateStyles(@NotNull Node node, @NotNull String[] stylesToRe
* @param enumValue The enum value determining the style to apply.
* <p> Example If Dir.UP is passed, add "up" style and removes {"down", "left", "right"} styles.
*/
public static <T extends Enum<T>> void updateStyleFromEnum(@NotNull Node node, @NotNull T enumValue) {
public static <T extends Enum<T>> void updateStyleFromEnum(Node node, T enumValue) {
updateStyles(node, EnumUtil.convertAllToStylesClassName(enumValue.getClass()), EnumUtil.convertToStyleClassName(enumValue));
}

Expand All @@ -131,21 +129,21 @@ public static <T extends Enum<T>> void updateStyleFromEnum(@NotNull Node node, @
* @param enumClass The enum class whose associated styles will be removed.
* <p> Example If Dir.class is passed, removes all styles {"up","down","left", "right"}.
*/
public static <T extends Enum<T>> void clearStylesByEnum(@NotNull Node node, @NotNull Class<T> enumClass) {
public static <T extends Enum<T>> void clearStylesByEnum(Node node, Class<T> enumClass) {
node.getStyleClass().removeAll(EnumUtil.convertAllToStylesClassName(enumClass));
}

/**
* Returns the height of the top and bottom insets combined.
*/
public static double getInsetsHeight(@Nullable Insets insets) {
public static double getInsetsHeight(Insets insets) {
return insets == null ? 0 : insets.getTop() + insets.getBottom();
}

/**
* Returns the width of the left and right insets combined.
*/
public static double getInsetsWidth(@Nullable Insets insets) {
public static double getInsetsWidth(Insets insets) {
return insets == null ? 0 : insets.getLeft() + insets.getRight();
}

Expand All @@ -167,7 +165,7 @@ public static double getInsetsWidth(@Nullable Insets insets) {
* @param camelCaseString The camelCase string to be converted.
* @return A string in natural language format, with appropriate spaces and capitalization.
*/
public static String camelCaseToNaturalCase(@NotNull String camelCaseString) {
public static String camelCaseToNaturalCase(String camelCaseString) {
return StringUtils.capitalize(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(camelCaseString), " "));
}

Expand Down Expand Up @@ -197,7 +195,7 @@ public static void copyToClipboard(String copyContent) {
* @return {@code true} if the event is a single stable primary button click, {@code false} otherwise.
* @throws NullPointerException if the event is null.
*/
public static boolean clickOnNode(@NotNull MouseEvent event) {
public static boolean clickOnNode(MouseEvent event) {
return event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 1 && event.isStillSincePress();
}

Expand Down
2 changes: 0 additions & 2 deletions gemsfx/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
requires com.dlsc.pickerfx;
requires com.dlsc.unitfx;

requires static org.jetbrains.annotations;

exports com.dlsc.gemsfx;
exports com.dlsc.gemsfx.daterange;
exports com.dlsc.gemsfx.incubator;
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.controlsfx</groupId>
Expand Down

0 comments on commit cb7a4af

Please sign in to comment.