[LANG-1510] Add org.apache.commons.lang3.arch.Processor.Arch.getLabel().

This commit is contained in:
Gary Gregory 2019-12-31 22:43:43 -05:00
parent e15a2db167
commit 931101dd65
3 changed files with 39 additions and 8 deletions

View File

@ -91,6 +91,7 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1506" type="add" dev="ggregory" due-to="Gary Gregory">Allow a StopWatch to carry an optional message.</action> <action issue="LANG-1506" type="add" dev="ggregory" due-to="Gary Gregory">Allow a StopWatch to carry an optional message.</action>
<action issue="LANG-1507" type="add" dev="ggregory" due-to="Sam Kruglov, Mark Dacek, Marc Magon, Pascal Schumacher, Rob Tompkins, Bruno P. Kinoshita, Amey Jadiye, Gary Gregory">Add ComparableUtils #398.</action> <action issue="LANG-1507" type="add" dev="ggregory" due-to="Sam Kruglov, Mark Dacek, Marc Magon, Pascal Schumacher, Rob Tompkins, Bruno P. Kinoshita, Amey Jadiye, Gary Gregory">Add ComparableUtils #398.</action>
<action issue="LANG-1508" type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.SystemUtils.getUserName().</action> <action issue="LANG-1508" type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.SystemUtils.getUserName().</action>
<action issue="LANG-1510" type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.lang3.arch.Processor.Arch.getLabel().</action>
</release> </release>
<release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11."> <release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11.">

View File

@ -19,6 +19,7 @@ package org.apache.commons.lang3.arch;
/** /**
* The {@link Processor} represents a microprocessor and defines * The {@link Processor} represents a microprocessor and defines
* some properties like architecture and type of the microprocessor. * some properties like architecture and type of the microprocessor.
*
* @since 3.6 * @since 3.6
*/ */
public class Processor { public class Processor {
@ -29,9 +30,9 @@ public class Processor {
* of the microprocessor. * of the microprocessor.
* The following architectures are defined: * The following architectures are defined:
* <ul> * <ul>
* <li>32 bit</li> * <li>32-bit</li>
* <li>64 bit</li> * <li>64-bit</li>
* <li>unknown</li> * <li>Unknown</li>
* </ul> * </ul>
*/ */
public enum Arch { public enum Arch {
@ -39,17 +40,37 @@ public class Processor {
/** /**
* A 32-bit processor architecture. * A 32-bit processor architecture.
*/ */
BIT_32, BIT_32("32-bit"),
/** /**
* A 64-bit processor architecture. * A 64-bit processor architecture.
*/ */
BIT_64, BIT_64("64-bit"),
/** /**
* An unknown-bit processor architecture. * 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 class Processor {
* <ul> * <ul>
* <li>x86</li> * <li>x86</li>
* <li>ia64</li> * <li>ia64</li>
* <li>ppc</li> * <li>PPC</li>
* <li>unknown</li> * <li>Unknown</li>
* </ul> * </ul>
*/ */
public enum Type { public enum Type {

View File

@ -17,6 +17,7 @@
package org.apache.commons.lang3; package org.apache.commons.lang3;
import org.apache.commons.lang3.arch.Processor; import org.apache.commons.lang3.arch.Processor;
import org.apache.commons.lang3.arch.Processor.Arch;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -95,6 +96,14 @@ public class ArchUtilsTest {
assertTrue(processor.isPPC()); assertTrue(processor.isPPC());
} }
@Test
public void testArchLabels() {
for (Arch arch : Arch.values()) {
// Only test label presence.
assertFalse(arch.getLabel().isEmpty());
}
}
@Test @Test
public void testGetProcessor() { public void testGetProcessor() {
assertNotNull(ArchUtils.getProcessor(X86)); assertNotNull(ArchUtils.getProcessor(X86));