Skip to content

Commit

Permalink
refactor: Standardize utility classes (#2150)
Browse files Browse the repository at this point in the history
Standardizing means that the utility class has a private constructor that throws UnsupportedOperationException to make clear that there is never the intension to have an instance of that class.
  • Loading branch information
sgcr authored Sep 24, 2024
1 parent 950b01b commit b79de56
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/main/java/core/gui/theme/FontUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class FontUtil {

private FontUtil() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

private static String checkInstalledFont(String targetFont, String sample, Font[] allfonts) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/core/gui/theme/ImageUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

public class ImageUtilities {

private ImageUtilities() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/** Hashtable mit Veränderungspfeilgrafiken nach Integer als Key */
private static final Hashtable<Integer,ImageIcon> m_clPfeilCache = new Hashtable<>();
private static final Hashtable<Integer,ImageIcon> m_clPfeilWideCache = new Hashtable<>();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/core/util/CurrencyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class CurrencyUtils {

public static String CURRENCYSYMBOL = "";

private CurrencyUtils() {}
private CurrencyUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
* convert currency value in swedish krone to local currency
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/core/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public class DateTimeUtils {

private static Map<String, String> cl_availableZoneIds;

/**
* Utility class - private constructor enforces non-instantiability.
*/
private DateTimeUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static Map<String, String> getAvailableZoneIds() {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/core/util/ExceptionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
*/
public class ExceptionUtils {

/**
* Utility class - private constructor enforces noninstantiability.
*/
private ExceptionUtils() {
// do nothing
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/core/util/GUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class GUIUtils {

private GUIUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/core/util/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
*/
public class Helper {

private Helper() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
* Form selections
*/
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/core/util/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
*/
public class IOUtils {

/**
* Utility class - private constructor enforces noninstantiability.
*/
private IOUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/core/util/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class MathUtils {

private MathUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

static void checkNonNegative(String role, double x) {
if (!(x >= 0)) {
throw new IllegalArgumentException(role + " (" + x + ") must be >= 0");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/core/util/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* Provides OS-specific utility functions.
*/
public final class OSUtils {

private OSUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static final String OS_NAME = System.getProperty("os.name").toLowerCase();
public enum OS {WINDOWS, LINUX, MAC}
private static OS os = determineOS();
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/core/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
*/
public class StringUtils {

/**
* Utility class - private constructor enforces noninstantiability.
*/
private StringUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/core/util/XMLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

public class XMLUtils {

/**
* Utility class - private constructor enforces noninstantiability.
*/
private XMLUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/module/ifa/PluginIfaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

public class PluginIfaUtils {

private PluginIfaUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

private static String getTeamDetails(int teamID) throws Exception {
return MyConnector.instance().getTeamDetails(teamID);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/module/nthrf/NthrfUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

public class NthrfUtil {

private NthrfUtil() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
* TODO
* @return success of the operation
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/module/teamAnalyzer/ui/RatingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* @author <a href=mailto:[email protected]>Massimiliano Amato</a>
*/
public final class RatingUtil {
/**
* Private default constructor to prevent class instantiation.
*/

private RatingUtil() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

/**
Expand Down

0 comments on commit b79de56

Please sign in to comment.