From 931101dd6528f23deadb71d21a4a06f0e8653fe4 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Tue, 31 Dec 2019 22:43:43 -0500 Subject: [PATCH] [LANG-1510] Add org.apache.commons.lang3.arch.Processor.Arch.getLabel(). --- src/changes/changes.xml | 1 + .../apache/commons/lang3/arch/Processor.java | 37 +++++++++++++++---- .../apache/commons/lang3/ArchUtilsTest.java | 9 +++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d311e529d..33b938eab 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -91,6 +91,7 @@ The type attribute can be add,update,fix,remove. Allow a StopWatch to carry an optional message. Add ComparableUtils #398. Add org.apache.commons.lang3.SystemUtils.getUserName(). + Add org.apache.commons.lang3.arch.Processor.Arch.getLabel(). 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 194e0cbf6..965c64186 100644 --- a/src/main/java/org/apache/commons/lang3/arch/Processor.java +++ b/src/main/java/org/apache/commons/lang3/arch/Processor.java @@ -19,6 +19,7 @@ /** * The {@link Processor} represents a microprocessor and defines * some properties like architecture and type of the microprocessor. + * * @since 3.6 */ public class Processor { @@ -29,9 +30,9 @@ public class Processor { * of the microprocessor. * The following architectures are defined: *
    - *
  • 32 bit
  • - *
  • 64 bit
  • - *
  • unknown
  • + *
  • 32-bit
  • + *
  • 64-bit
  • + *
  • Unknown
  • *
*/ public enum Arch { @@ -39,17 +40,37 @@ public enum Arch { /** * A 32-bit processor architecture. */ - BIT_32, + BIT_32("32-bit"), /** * A 64-bit processor architecture. */ - BIT_64, + BIT_64("64-bit"), /** * An unknown-bit processor architecture. */ - UNKNOWN + UNKNOWN("Unknown"); + + /** + * A label suitable for display. + * + * @since 3.10 + */ + private final String label; + + private Arch(final String label) { + this.label = label; + } + + /** + * Gets the label suitable for display. + * + * @return the label. + */ + public String getLabel() { + return label; + } } /** @@ -58,8 +79,8 @@ public enum Arch { *
    *
  • x86
  • *
  • ia64
  • - *
  • ppc
  • - *
  • unknown
  • + *
  • PPC
  • + *
  • Unknown
  • *
*/ public enum Type { diff --git a/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java index c1d2a904e..55724ff98 100644 --- a/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArchUtilsTest.java @@ -17,6 +17,7 @@ package org.apache.commons.lang3; import org.apache.commons.lang3.arch.Processor; +import org.apache.commons.lang3.arch.Processor.Arch; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -95,6 +96,14 @@ public void testArch() { assertTrue(processor.isPPC()); } + @Test + public void testArchLabels() { + for (Arch arch : Arch.values()) { + // Only test label presence. + assertFalse(arch.getLabel().isEmpty()); + } + } + @Test public void testGetProcessor() { assertNotNull(ArchUtils.getProcessor(X86));