All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.byteground.Architecture Maven / Gradle / Ivy

/**
 * Copyright © 2009-2014 ByTeGround, Inc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.byteground;

import java.util.HashMap;
import java.util.Map;

final public class Architecture {
    public static final Architecture UNKNOWN = new Architecture("unknown");
    public static final Architecture _32 = new Architecture("32");
    public static final Architecture _64 = new Architecture("64");
    private static final Architecture[] ARCHITECTURES = new Architecture[]{_32, _64};
    private static final Map ARCHITECTURE_MAP = new HashMap();

    static {
        for (Architecture architecture : ARCHITECTURES) {
            ARCHITECTURE_MAP.put(architecture.name, architecture);
        }
    }

    public static Architecture[] getAll() {
        return ARCHITECTURES;
    }

    public static Architecture getByName(String name) {
        Architecture architecture = ARCHITECTURE_MAP.get(name);
        if (architecture == null)
            return UNKNOWN;
        else
            return architecture;
    }

    public static boolean isCurrent(Architecture architecture) {
        return architecture != null && architecture != UNKNOWN && architecture.equals(getCurrent());
    }

    public static Architecture getCurrent() {
        final String sunArchDataModel = System.getProperty("sun.arch.data.model");
        final Architecture architecture;
        if (sunArchDataModel != null && sunArchDataModel.contains("64")) {
            architecture = _64;
        } else if (sunArchDataModel != null && sunArchDataModel.contains("32")) {
            architecture = _32;
        } else {
            final String osArch = System.getProperty("os.arch");
            if (osArch != null && osArch.contains("64")) {
                architecture = _64;
            } else {
                architecture = _32;
            }
        }
        return architecture;
    }

    private Architecture(String name) {
        this.name = name;
    }

    public String name;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy