MCPcopy Create free account
hub / github.com/apache/commons-lang / ArchUtils

Class ArchUtils

src/main/java/org/apache/commons/lang3/ArchUtils.java:33–149  ·  view source on GitHub ↗

Provides methods for identifying the architecture of the current JVM based on the "os.arch" system property. Important: The "os.arch" system property returns the architecture used by the JVM not of the operating system. @since 3.6

Source from the content-addressed store, hash-verified

31 * @since 3.6
32 */
33public class ArchUtils {
34
35 private static final Map<String, Processor> ARCH_TO_PROCESSOR;
36
37 static {
38 ARCH_TO_PROCESSOR = new HashMap<>();
39 init();
40 }
41
42 /**
43 * Adds the given {@link Processor} with the given key {@link String} to the map.
44 *
45 * @param key The key as {@link String}.
46 * @param processor The {@link Processor} to add.
47 * @throws IllegalStateException If the key already exists.
48 */
49 private static void addProcessor(final String key, final Processor processor) {
50 if (ARCH_TO_PROCESSOR.containsKey(key)) {
51 throw new IllegalStateException("Key " + key + " already exists in processor map");
52 }
53 ARCH_TO_PROCESSOR.put(key, processor);
54 }
55
56 /**
57 * Adds the given {@link Processor} with the given keys to the map.
58 *
59 * @param keys The keys.
60 * @param processor The {@link Processor} to add.
61 * @throws IllegalStateException If the key already exists.
62 */
63 private static void addProcessors(final Processor processor, final String... keys) {
64 Streams.of(keys).forEach(e -> addProcessor(e, processor));
65 }
66
67 /**
68 * Gets a {@link Processor} object of the current JVM.
69 *
70 * <p>
71 * Important: The {@code "os.arch"} system property returns the architecture used by the JVM not of the operating system.
72 * </p>
73 *
74 * @return A {@link Processor} when supported, else {@code null}.
75 */
76 public static Processor getProcessor() {
77 return getProcessor(SystemProperties.getOsArch());
78 }
79
80 /**
81 * 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
82 * property.
83 *
84 * @param value A {@link String} like a value returned by the {@code os.arch} System Property.
85 * @return A {@link Processor} when it exists, else {@code null}.
86 */
87 public static Processor getProcessor(final String value) {
88 return ARCH_TO_PROCESSOR.get(value);
89 }
90

Callers

nothing calls this directly

Calls 1

initMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…