This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 1903d88e0 Add Processor.Type.getLabel() and Processor.toString()
1903d88e0 is described below

commit 1903d88e0b214fa369fe0c49c71e4c3b480f2f7d
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Aug 21 17:09:48 2022 -0400

    Add Processor.Type.getLabel() and Processor.toString()
---
 src/changes/changes.xml                            |  2 ++
 .../java/org/apache/commons/lang3/ArchUtils.java   |  4 +--
 .../org/apache/commons/lang3/arch/Processor.java   | 41 +++++++++++++++++-----
 .../org/apache/commons/lang3/ArchUtilsTest.java    | 12 ++++++-
 4 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8ef007ff1..2732815f6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -171,6 +171,8 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add Streams.of(Iterable&lt;E&gt;).</action>
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add Streams.of(Iterator&lt;E&gt;).</action>
     <action issue="LANG-1689" type="add" dev="ggregory" due-to="Joseph 
Hendrix, Gary Gregory">Simple support for Optional in ObjectUtils#isEmpty() 
#933.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add Processor.Type.getLabel().</action>
+    <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add Processor.toString().</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Dependabot, 
XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.7 #742, #752, 
#764, #833, #867.</action>
     <action                   type="update" dev="ggregory" 
due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>
diff --git a/src/main/java/org/apache/commons/lang3/ArchUtils.java 
b/src/main/java/org/apache/commons/lang3/ArchUtils.java
index 831dd2456..eaa622a6a 100644
--- a/src/main/java/org/apache/commons/lang3/ArchUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArchUtils.java
@@ -111,7 +111,7 @@ public class ArchUtils {
     }
 
     /**
-     * Returns a {@link Processor} object of the current JVM.
+     * Gets a {@link Processor} object of the current JVM.
      *
      * <p>
      * Important: The os.arch System Property returns the architecture used by 
the JVM
@@ -125,7 +125,7 @@ public class ArchUtils {
     }
 
     /**
-     * Returns a {@link Processor} object the given value {@link String}. The 
{@link String} must be
+     * Gets a {@link Processor} object the given value {@link String}. The 
{@link String} must be
      * like a value returned by the {@code os.arch} System Property.
      *
      * @param value A {@link String} like a value returned by the {@code 
os.arch} System Property.
diff --git a/src/main/java/org/apache/commons/lang3/arch/Processor.java 
b/src/main/java/org/apache/commons/lang3/arch/Processor.java
index c9dcbdf7e..0d3f835fa 100644
--- a/src/main/java/org/apache/commons/lang3/arch/Processor.java
+++ b/src/main/java/org/apache/commons/lang3/arch/Processor.java
@@ -54,8 +54,6 @@ public class Processor {
 
         /**
          * A label suitable for display.
-         *
-         * @since 3.10
          */
         private final String label;
 
@@ -77,7 +75,7 @@ public class Processor {
      * The {@link Type} enum defines types of a microprocessor.
      * The following types are defined:
      * <ul>
-     *     <li>Aarch64</li>
+     *     <li>AArch64</li>
      *     <li>x86</li>
      *     <li>ia64</li>
      *     <li>PPC</li>
@@ -91,27 +89,47 @@ public class Processor {
          *
          * @since 3.13.0
          */
-        AARCH_64,
+        AARCH_64("AArch64"),
 
         /**
          * Intel x86 series of instruction set architectures.
          */
-        X86,
+        X86("x86"),
 
         /**
          * Intel Itanium 64-bit architecture.
          */
-        IA_64,
+        IA_64("IA-64"),
 
         /**
          * Apple–IBM–Motorola PowerPC architecture.
          */
-        PPC,
+        PPC("PPC"),
 
         /**
          * Unknown architecture.
          */
-        UNKNOWN
+        UNKNOWN("Unknown");
+
+        /**
+         * A label suitable for display.
+         */
+        private final String label;
+
+        Type(final String label) {
+            this.label = label;
+        }
+
+        /**
+         * Gets the label suitable for display.
+         *
+         * @return the label.
+         * @since 3.13.0
+         */
+        public String getLabel() {
+            return label;
+        }
+
     }
 
     private final Arch arch;
@@ -207,4 +225,11 @@ public class Processor {
         return Type.X86 == type;
     }
 
+    @Override
+    public String toString() {
+        final StringBuilder builder = new StringBuilder();
+        builder.append(type.getLabel()).append(' ').append(arch.getLabel());
+        return builder.toString();
+    }
+
 }
diff --git a/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
index fbe80f4dc..342e3870b 100644
--- a/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java
@@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.apache.commons.lang3.arch.Processor;
 import org.apache.commons.lang3.arch.Processor.Arch;
+import org.apache.commons.lang3.arch.Processor.Type;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -109,14 +110,23 @@ public class ArchUtilsTest extends AbstractLangTest {
         }
     }
 
+    @Test
+    public void testTypeLabels() {
+        for (final Type type : Type.values()) {
+            // Only test label presence.
+            assertFalse(type.getLabel().isEmpty());
+        }
+    }
+
     @Test
     public void testGetProcessor() {
         assertNotNull(ArchUtils.getProcessor(X86));
         assertNull(ArchUtils.getProcessor("NA"));
+        assertNull(ArchUtils.getProcessor(null));
 
         final Processor processor = ArchUtils.getProcessor();
         assertTrue(processor.isX86());
-
+        assertNotEquals(ObjectUtils.identityToString(processor), 
processor.toString());
     }
 
     @Test

Reply via email to