From 7722d187fc7cf64b18aeb1c14df85f823601383f Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Fri, 30 May 2003 01:15:53 +0000 Subject: [PATCH] Sorted members (this also give us the Javadoc 'Field Details' section in alphabetical order). git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137348 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/SystemUtils.java | 502 +++++++++--------- 1 file changed, 251 insertions(+), 251 deletions(-) diff --git a/src/java/org/apache/commons/lang/SystemUtils.java b/src/java/org/apache/commons/lang/SystemUtils.java index 55603250f..fa83ec890 100644 --- a/src/java/org/apache/commons/lang/SystemUtils.java +++ b/src/java/org/apache/commons/lang/SystemUtils.java @@ -66,20 +66,9 @@ package org.apache.commons.lang; * @author Gary Gregory * @author Michael Becke * @since 1.0 - * @version $Id: SystemUtils.java,v 1.13 2003/05/30 01:12:26 ggregory Exp $ + * @version $Id: SystemUtils.java,v 1.14 2003/05/30 01:15:53 ggregory Exp $ */ public class SystemUtils { - - /** - *

SystemUtils instances should NOT be constructed in standard - * programming. Instead, the class should be used as - * SystemUtils.FILE_SEPARATOR.

- * - *

This constructor is public to permit tools that require a JavaBean - * instance to operate.

- */ - public SystemUtils() { - } //----------------------------------------------------------------------- /** @@ -104,6 +93,164 @@ public class SystemUtils { */ public static final String FILE_SEPARATOR = getSystemProperty("file.separator"); + //----------------------------------------------------------------------- + /** + * Is true if this is Java version 1.1 (also 1.1.x versions). + *

+ * The field will return false if JAVA_VERSION is null. + */ + public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1"); + + /** + * Is true if this is Java version 1.2 (also 1.2.x versions). + *

+ * The field will return false if JAVA_VERSION is null. + */ + public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2"); + + /** + * Is true if this is Java version 1.3 (also 1.3.x versions). + *

+ * The field will return false if JAVA_VERSION is null. + */ + public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3"); + + /** + * Is true if this is Java version 1.4 (also 1.4.x versions). + *

+ * The field will return false if JAVA_VERSION is null. + */ + public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4"); + + /** + * Is true if this is Java version 1.5 (also 1.5.x versions). + *

+ * The field will return false if JAVA_VERSION is null. + */ + public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5"); + + /** + * Is true if this is AIX. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_AIX = getOSMatches("AIX"); + + /** + * Is true if this is HP-UX. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX"); + + /** + * Is true if this is Irix. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_IRIX = getOSMatches("Irix"); + + /** + * Is true if this is Linux. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX"); + // Windows XP returns 'Windows 2000' just for fun... + + /** + * Is true if this is Mac. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_MAC = getOSMatches("Mac"); + + /** + * Is true if this is Mac. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X"); + + /** + * Is true if this is Mac. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_OS2 = getOSMatches("OS/2"); + + /** + * Is true if this is Solaris. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris"); + + /** + * Is true if this is SunOS. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); + + //----------------------------------------------------------------------- + // OS names from http://www.vamphq.com/os.html + // Selected ones included - please advise commons-dev@jakarta.apache.org + // if you want another added or a mistake corrected + + /** + * Is true if this is Windows. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS = getOSMatches("Windows"); + + /** + * Is true if this is Windows 2000. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS_2000 = getOSMatches("Windows", "5.0"); + + /** + * Is true if this is Windows 95. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS_95 = getOSMatches("Windows 9", "4.0"); + // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above + + /** + * Is true if this is Windows 98. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS_98 = getOSMatches("Windows 9", "4.1"); + // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above + + /** + * Is true if this is Windows ME. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS_ME = getOSMatches("Windows", "4.9"); + // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above + + /** + * Is true if this is Windows NT. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS_NT = getOSMatches("Windows NT"); + // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem + + /** + * Is true if this is Windows XP. + *

+ * The field will return false if OS_NAME is null. + */ + public static final boolean IS_OS_WINDOWS_XP = getOSMatches("Windows", "5.1"); + /** * The java.class.path System Property. * Java class path. @@ -270,6 +417,31 @@ public class SystemUtils { */ public static final String JAVA_VERSION = getSystemProperty("java.version"); + //----------------------------------------------------------------------- + /** + * Gets the Java version as a float. + * Example output: + *

+ *

+ * The field will return zero if JAVA_VERSION is null. + */ + public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); + + /** + * Gets the Java version as an int. + * Example output: + *

+ *

+ * The field will return zero if JAVA_VERSION is null. + */ + public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); + /** * The java.vm.info System Property. * Java Virtual Machine implementation info. @@ -402,6 +574,21 @@ public class SystemUtils { */ public static final String PATH_SEPARATOR = getSystemProperty("path.separator"); + /** + * The user.country or user.region System Property. + * User's country code, such as GB. + * First in JDK version 1.2 as user.region. + * Renamed to user.country in 1.4 + *

+ * Defaults to null if the runtime does not have + * security access to read this property or property not specified. + * + * @since Java 1.2 + */ + public static final String USER_COUNTRY = + (getSystemProperty("user.country") == null ? + getSystemProperty("user.region") : getSystemProperty("user.country")); + /** * The user.dir System Property. * User's current working directory. @@ -435,21 +622,6 @@ public class SystemUtils { */ public static final String USER_LANGUAGE = getSystemProperty("user.language"); - /** - * The user.country or user.region System Property. - * User's country code, such as GB. - * First in JDK version 1.2 as user.region. - * Renamed to user.country in 1.4 - *

- * Defaults to null if the runtime does not have - * security access to read this property or property not specified. - * - * @since Java 1.2 - */ - public static final String USER_COUNTRY = - (getSystemProperty("user.country") == null ? - getSystemProperty("user.region") : getSystemProperty("user.country")); - /** * The user.name System Property. * User's account name. @@ -461,223 +633,23 @@ public class SystemUtils { */ public static final String USER_NAME = getSystemProperty("user.name"); - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- /** - * Is true if this is Java version 1.1 (also 1.1.x versions). - *

- * The field will return false if JAVA_VERSION is null. - */ - public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1"); - - /** - * Is true if this is Java version 1.2 (also 1.2.x versions). - *

- * The field will return false if JAVA_VERSION is null. - */ - public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2"); - - /** - * Is true if this is Java version 1.3 (also 1.3.x versions). - *

- * The field will return false if JAVA_VERSION is null. - */ - public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3"); - - /** - * Is true if this is Java version 1.4 (also 1.4.x versions). - *

- * The field will return false if JAVA_VERSION is null. - */ - public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4"); - - /** - * Is true if this is Java version 1.5 (also 1.5.x versions). - *

- * The field will return false if JAVA_VERSION is null. - */ - public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5"); - - //----------------------------------------------------------------------- - /** - * Gets the Java version as a float. - * Example output: + *

Get the Java version number as a float.

+ * + *

Example output:

* - *

- * The field will return zero if JAVA_VERSION is null. - */ - public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); - - /** - * Gets the Java version as an int. - * Example output: - *

- *

- * The field will return zero if JAVA_VERSION is null. - */ - public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); - - //----------------------------------------------------------------------- - // OS names from http://www.vamphq.com/os.html - // Selected ones included - please advise commons-dev@jakarta.apache.org - // if you want another added or a mistake corrected - - /** - * Is true if this is Windows. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS = getOSMatches("Windows"); - - /** - * Is true if this is Windows 95. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS_95 = getOSMatches("Windows 9", "4.0"); - // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above - - /** - * Is true if this is Windows 98. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS_98 = getOSMatches("Windows 9", "4.1"); - // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above - - /** - * Is true if this is Windows ME. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS_ME = getOSMatches("Windows", "4.9"); - // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above - - /** - * Is true if this is Windows NT. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS_NT = getOSMatches("Windows NT"); - - /** - * Is true if this is Windows 2000. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS_2000 = getOSMatches("Windows", "5.0"); - // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem - - /** - * Is true if this is Windows XP. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_WINDOWS_XP = getOSMatches("Windows", "5.1"); - // Windows XP returns 'Windows 2000' just for fun... - - /** - * Is true if this is Mac. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_MAC = getOSMatches("Mac"); - - /** - * Is true if this is Mac. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X"); - - /** - * Is true if this is Linux. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX"); - - /** - * Is true if this is Mac. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_OS2 = getOSMatches("OS/2"); - - /** - * Is true if this is Solaris. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris"); - - /** - * Is true if this is SunOS. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); - - /** - * Is true if this is HP-UX. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX"); - - /** - * Is true if this is AIX. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_AIX = getOSMatches("AIX"); - - /** - * Is true if this is Irix. - *

- * The field will return false if OS_NAME is null. - */ - public static final boolean IS_OS_IRIX = getOSMatches("Irix"); - - //----------------------------------------------------------------------- - /** - * Gets a System property, defaulting to the given value if the property - * cannot be read. * - * @param property the system property name - * @return the system property value or null if security problem + * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead. + * Will be removed in Commons Lang 3.0. + * @return the version, for example 1.31f for JDK 1.3.1 */ - private static String getSystemProperty(String property) { - try { - return System.getProperty(property); - - } catch (SecurityException ex) { - // we are not allowed to look at this property - System.err.println( - "SecurityException thrown when reading system property '" + property - + "' - property value will default to null" - ); - return null; - } - } - - /** - * Decides if the java version matches. - * - * @param versionPrefix the prefix for the java version - * @return true if matches, or false if not or can't determine - */ - private static boolean getJavaVersionMatches(String versionPrefix) { - if (JAVA_VERSION == null) { - return false; - } - return JAVA_VERSION.startsWith(versionPrefix); - } + public static float getJavaVersion() { + return JAVA_VERSION_FLOAT; + } /** *

Get the Java version number as a float.

@@ -731,6 +703,19 @@ public class SystemUtils { } return Integer.parseInt(str); } + + /** + * Decides if the java version matches. + * + * @param versionPrefix the prefix for the java version + * @return true if matches, or false if not or can't determine + */ + private static boolean getJavaVersionMatches(String versionPrefix) { + if (JAVA_VERSION == null) { + return false; + } + return JAVA_VERSION.startsWith(versionPrefix); + } /** * Decides if the operating system matches. @@ -759,23 +744,27 @@ public class SystemUtils { return OS_NAME.startsWith(osNamePrefix) && OS_VERSION.startsWith(osVersionPrefix); } - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- /** - *

Get the Java version number as a float.

- * - *

Example output:

- * + * Gets a System property, defaulting to the given value if the property + * cannot be read. * - * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead. - * Will be removed in Commons Lang 3.0. - * @return the version, for example 1.31f for JDK 1.3.1 + * @param property the system property name + * @return the system property value or null if security problem */ - public static float getJavaVersion() { - return JAVA_VERSION_FLOAT; - } + private static String getSystemProperty(String property) { + try { + return System.getProperty(property); + + } catch (SecurityException ex) { + // we are not allowed to look at this property + System.err.println( + "SecurityException thrown when reading system property '" + property + + "' - property value will default to null" + ); + return null; + } + } /** *

Is the Java version at least the requested version.

@@ -811,4 +800,15 @@ public class SystemUtils { return (JAVA_VERSION_INT >= requiredVersion); } + /** + *

SystemUtils instances should NOT be constructed in standard + * programming. Instead, the class should be used as + * SystemUtils.FILE_SEPARATOR.

+ * + *

This constructor is public to permit tools that require a JavaBean + * instance to operate.

+ */ + public SystemUtils() { + } + }