]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreutils/enums/EnumUtils.java
Continued:
[jcore-utils.git] / src / org / mxchange / jcoreutils / enums / EnumUtils.java
diff --git a/src/org/mxchange/jcoreutils/enums/EnumUtils.java b/src/org/mxchange/jcoreutils/enums/EnumUtils.java
new file mode 100644 (file)
index 0000000..0d34b32
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2022 Roland Häder<roland@mxchange.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcoreutils.enums;
+
+/**
+ * A utilities class for enumerations
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class EnumUtils {
+
+       /**
+        * Compares two enumerations with each other in a null-safe manner
+        * <p>
+        * @param enum1 Enumeration 1
+        * @param enum2 Enumeration 2
+        * <p>
+        * @return Comparison value
+        */
+       public static int compare (final Enum<?> enum1, final Enum<?> enum2) {
+               // Check parameters on null
+               if (enum1 == enum2) {
+                       // Both are equal
+                       return 0;
+               } else if (null == enum1) {
+                       // Left one is null
+                       return -1;
+               } else if (null == enum2) {
+                       // Right one is null
+                       return 1;
+               }
+
+               // Compare both enumeration's names
+               return enum1.name().compareTo(enum2.name());
+       }
+
+       /**
+        * No instances from utility classes
+        */
+       private EnumUtils () {
+       }
+
+}