    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.lang3.arch;
    018
    019/**
    020 * The {@link Processor} represents a microprocessor and defines
    021 * some properties like architecture and type of the microprocessor.
    022 * @since 3.6
    023 */
    024public class Processor {
    025
    026    /**
    027     * The {@link Arch} enum defines the architecture of
    028     * a microprocessor. The architecture represents the bit value
    029     * of the microprocessor.
    030     * The following architectures are defined:
    031     * <ul>
    032     *     <li>32 bit</li>
    033     *     <li>64 bit</li>
    034     *     <li>unknown</li>
    035     * </ul>
    036     */
    037    public enum Arch {
    038
    039        /**
    040         * A 32-bit processor architecture.
    041         */
    042        BIT_32,
    043
    044        /**
    045         * A 64-bit processor architecture.
    046         */
    047        BIT_64,
    048
    049        /**
    050         * An unknown-bit processor architecture.
    051         */
    052        UNKNOWN
    053    }
    054
    055    /**
    056     * The {@link Type} enum defines types of a microprocessor.
    057     * The following types are defined:
    058     * <ul>
    059     *     <li>x86</li>
    060     *     <li>ia64</li>
    061     *     <li>ppc</li>
    062     *     <li>unknown</li>
    063     * </ul>
    064     */
    065    public enum Type {
    066
    067        /**
    068         * Intel x86 series of instruction set architectures.
    069         */
    070        X86,
    071
    072        /**
    073         * Intel Itanium  64-bit architecture.
    074         */
    075        IA_64,
    076
    077        /**
    078         * Apple–IBM–Motorola PowerPC architecture.
    079         */
    080        PPC,
    081
    082        /**
    083         * Unknown architecture.
    084         */
    085        UNKNOWN
    086    }
    087
    088    private final Arch arch;
    089    private final Type type;
    090
    091    /**
    092     * Constructs a {@link Processor} object with the given
    093     * parameters.
    094     *
    095     * @param arch The processor architecture.
    096     * @param type The processor type.
    097     */
    098    public Processor(final Arch arch, final Type type) {
    099        this.arch = arch;
    100        this.type = type;
    101    }
    102
    103    /**
    104     * Returns the processor architecture as an {@link Arch} enum.
    105     * The processor architecture defines, if the processor has
    106     * a 32 or 64 bit architecture.
    107     *
    108     * @return A {@link Arch} enum.
    109     */
    110    public Arch getArch() {
    111        return arch;
    112    }
    113
    114    /**
    115     * Returns the processor type as {@link Type} enum.
    116     * The processor type defines, if the processor is for example
    117     * a x86 or PPA.
    118     *
    119     * @return A {@link Type} enum.
    120     */
    121    public Type getType() {
    122        return type;
    123    }
    124
    125    /**
    126     * Checks if {@link Processor} is 32 bit.
    127     *
    128     * @return <code>true</code>, if {@link Processor} is {@link Arch#BIT_32}, else <code>false</code>.
    129     */
    130    public boolean is32Bit() {
    131        return Arch.BIT_32.equals(arch);
    132    }
    133
    134    /**
    135     * Checks if {@link Processor} is 64 bit.
    136     *
    137     * @return <code>true</code>, if {@link Processor} is {@link Arch#BIT_64}, else <code>false</code>.
    138     */
    139    public boolean is64Bit() {
    140        return Arch.BIT_64.equals(arch);
    141    }
    142
    143    /**
    144     * Checks if {@link Processor} is type of x86.
    145     *
    146     * @return <code>true</code>, if {@link Processor} is {@link Type#X86}, else <code>false</code>.
    147     */
    148    public boolean isX86() {
    149        return Type.X86.equals(type);
    150    }
    151
    152    /**
    153     * Checks if {@link Processor} is type of Intel Itanium.
    154     *
    155     * @return <code>true</code>. if {@link Processor} is {@link Type#IA_64}, else <code>false</code>.
    156     */
    157    public boolean isIA64() {
    158        return Type.IA_64.equals(type);
    159    }
    160
    161    /**
    162     * Checks if {@link Processor} is type of Power PC.
    163     *
    164     * @return <code>true</code>. if {@link Processor} is {@link Type#PPC}, else <code>false</code>.
    165     */
    166    public boolean isPPC() {
    167        return Type.PPC.equals(type);
    168    }
    169
    170}