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

com.hfg.util.OS Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.util;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

//==============================================================================
/**
 Operating system detection class.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //============================================================================== // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //============================================================================== public class OS implements Comparable { private String mName; private static Map mValueMap = new HashMap<>(); private static OS mCurrentOS; public static OS Windows = new OS("Windows"); public static OS Mac = new OS("Mac OS X"); public static OS UNIX = new OS("UNIX"); public static OS Solaris = new OS("Solaris"); public static OS Unknown = new OS("Unknown"); //--------------------------------------------------------------------------- private OS(String inName) { mName = inName; mValueMap.put(mName, this); } //--------------------------------------------------------------------------- @Override public String toString() { return name(); } //--------------------------------------------------------------------------- public String name() { return mName; } //--------------------------------------------------------------------------- @Override public int hashCode() { return name().hashCode(); } //--------------------------------------------------------------------------- @Override public boolean equals(Object inObj2) { return (inObj2 != null && inObj2 instanceof OS && 0 == compareTo((OS) inObj2)); } //--------------------------------------------------------------------------- public int compareTo(OS inObj2) { return CompareUtil.compare(name(), inObj2.name()); } //--------------------------------------------------------------------------- public static Collection values() { return Collections.unmodifiableCollection(mValueMap.values()); } //--------------------------------------------------------------------------- public static OS valueOf(String inString) { return mValueMap.get(inString); } //--------------------------------------------------------------------------- public static synchronized OS value() { if (null == mCurrentOS) { String sysProperty = System.getProperty("os.name").toLowerCase(); if (sysProperty.contains("mac")) { mCurrentOS = OS.Mac; } else if (sysProperty.contains("win")) { mCurrentOS = OS.Windows; } else if (sysProperty.contains("sunos")) { mCurrentOS = OS.Solaris; } else if (sysProperty.contains("ix") || (sysProperty.contains("ux"))) { mCurrentOS = OS.UNIX; } else { mCurrentOS = OS.Unknown; } } return mCurrentOS; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy