org.eclipse.swt.internal
Class Compatibility

java.lang.Object
  extended by org.eclipse.swt.internal.Compatibility

public final class Compatibility
extends java.lang.Object

This class is a placeholder for utility methods commonly used on J2SE platforms but not supported on some J2ME profiles.

It is part of our effort to provide support for both J2SE and J2ME platforms.

IMPORTANT: some of the methods have been modified from their J2SE parents. Refer to the description of each method for specific changes.


Field Summary
static double PI
          Returns the PI constant as a double.
 
Constructor Summary
Compatibility()
           
 
Method Summary
static int ceil(int p, int q)
          Answers the most negative (i.e.
static int cos(int angle, int length)
          Answers the length of the side adjacent to the given angle of a right triangle.
static boolean equalsIgnoreCase(java.lang.String s1, java.lang.String s2)
          Compares two instances of class String ignoring the case of the characters and answers if they are equal.
static void exec(java.lang.String prog)
          Execute a program in a separate platform process if the underlying platform support this.
static void exec(java.lang.String[] progArray)
          Execute progArray[0] in a separate platform process if the underlying platform support this.
static boolean fileExists(java.lang.String parent, java.lang.String child)
          Answers whether the indicated file exists or not.
static int floor(int p, int q)
          Answers the most positive (i.e.
static java.lang.String getMessage(java.lang.String key)
          Returns the NLS'ed message for the given argument.
static java.lang.String getMessage(java.lang.String key, java.lang.Object[] args)
           
static void interrupt()
          Interrupt the current thread.
static boolean isLetter(char c)
          Answers whether the character is a letter.
static boolean isLetterOrDigit(char c)
          Answers whether the character is a letter or a digit.
static boolean isSpaceChar(char c)
          Answers whether the character is a Unicode space character.
static boolean isWhitespace(char c)
          Answers whether the character is a whitespace character.
static java.io.OutputStream newDeflaterOutputStream(java.io.OutputStream stream)
          Create an DeflaterOutputStream if such things are supported.
static java.io.InputStream newFileInputStream(java.lang.String filename)
          Open a file if such things are supported.
static java.io.OutputStream newFileOutputStream(java.lang.String filename)
          Open a file if such things are supported.
static java.io.InputStream newInflaterInputStream(java.io.InputStream stream)
          Create an InflaterInputStream if such things are supported.
static int pow2(int n)
          Returns 2 raised to the power of the argument.
static int round(int p, int q)
          Answers the result of rounding to the closest integer the number obtained by dividing the first argument p by the second argument q.
static int sin(int angle, int length)
          Answers the length of the side opposite to the given angle of a right triangle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PI

public static double PI
Returns the PI constant as a double.

Constructor Detail

Compatibility

public Compatibility()
Method Detail

cos

public static int cos(int angle,
                      int length)
Answers the length of the side adjacent to the given angle of a right triangle. In other words, it returns the integer conversion of length * cos (angle).

IMPORTANT: the j2me version has an additional restriction on the argument. length must be between -32767 and 32767 (inclusive).

Parameters:
angle - the angle in degrees
length - the length of the triangle's hypotenuse
Returns:
the integer conversion of length * cos (angle)

sin

public static int sin(int angle,
                      int length)
Answers the length of the side opposite to the given angle of a right triangle. In other words, it returns the integer conversion of length * sin (angle).

IMPORTANT: the j2me version has an additional restriction on the argument. length must be between -32767 and 32767 (inclusive).

Parameters:
angle - the angle in degrees
length - the length of the triangle's hypotenuse
Returns:
the integer conversion of length * sin (angle)

ceil

public static int ceil(int p,
                       int q)
Answers the most negative (i.e. closest to negative infinity) integer value which is greater than the number obtained by dividing the first argument p by the second argument q.

Parameters:
p - numerator
q - denominator (must be different from zero)
Returns:
the ceiling of the rational number p / q.

fileExists

public static boolean fileExists(java.lang.String parent,
                                 java.lang.String child)
Answers whether the indicated file exists or not.

Parameters:
parent - the file's parent directory
child - the file's name
Returns:
true if the file exists

floor

public static int floor(int p,
                        int q)
Answers the most positive (i.e. closest to positive infinity) integer value which is less than the number obtained by dividing the first argument p by the second argument q.

Parameters:
p - numerator
q - denominator (must be different from zero)
Returns:
the floor of the rational number p / q.

round

public static int round(int p,
                        int q)
Answers the result of rounding to the closest integer the number obtained by dividing the first argument p by the second argument q.

IMPORTANT: the j2me version has an additional restriction on the arguments. p must be within the range 0 - 32767 (inclusive). q must be within the range 1 - 32767 (inclusive).

Parameters:
p - numerator
q - denominator (must be different from zero)
Returns:
the closest integer to the rational number p / q

pow2

public static int pow2(int n)
Returns 2 raised to the power of the argument.

Parameters:
n - an int value between 0 and 30 (inclusive)
Returns:
2 raised to the power of the argument
Throws:
java.lang.IllegalArgumentException -
  • ERROR_INVALID_RANGE - if the argument is not between 0 and 30 (inclusive)

newDeflaterOutputStream

public static java.io.OutputStream newDeflaterOutputStream(java.io.OutputStream stream)
                                                    throws java.io.IOException
Create an DeflaterOutputStream if such things are supported.

Parameters:
stream - the output stream
Returns:
a deflater stream or null
Throws:
java.io.IOException
Since:
3.4

newFileInputStream

public static java.io.InputStream newFileInputStream(java.lang.String filename)
                                              throws java.io.IOException
Open a file if such things are supported.

Parameters:
filename - the name of the file to open
Returns:
a stream on the file if it could be opened.
Throws:
java.io.IOException

newFileOutputStream

public static java.io.OutputStream newFileOutputStream(java.lang.String filename)
                                                throws java.io.IOException
Open a file if such things are supported.

Parameters:
filename - the name of the file to open
Returns:
a stream on the file if it could be opened.
Throws:
java.io.IOException

newInflaterInputStream

public static java.io.InputStream newInflaterInputStream(java.io.InputStream stream)
                                                  throws java.io.IOException
Create an InflaterInputStream if such things are supported.

Parameters:
stream - the input stream
Returns:
a inflater stream or null
Throws:
java.io.IOException
Since:
3.3

isLetter

public static boolean isLetter(char c)
Answers whether the character is a letter.

Parameters:
c - the character
Returns:
true when the character is a letter

isLetterOrDigit

public static boolean isLetterOrDigit(char c)
Answers whether the character is a letter or a digit.

Parameters:
c - the character
Returns:
true when the character is a letter or a digit

isSpaceChar

public static boolean isSpaceChar(char c)
Answers whether the character is a Unicode space character.

Parameters:
c - the character
Returns:
true when the character is a Unicode space character

isWhitespace

public static boolean isWhitespace(char c)
Answers whether the character is a whitespace character.

Parameters:
c - the character to test
Returns:
true if the character is whitespace

exec

public static void exec(java.lang.String prog)
                 throws java.io.IOException
Execute a program in a separate platform process if the underlying platform support this.

The new process inherits the environment of the caller.

Parameters:
prog - the name of the program to execute
Throws:
java.io.IOException - if the program cannot be executed
java.lang.SecurityException - if the current SecurityManager disallows program execution

exec

public static void exec(java.lang.String[] progArray)
                 throws java.io.IOException
Execute progArray[0] in a separate platform process if the underlying platform support this.

The new process inherits the environment of the caller.

Parameters:
progArray - array containing the program to execute and its arguments
Throws:
java.io.IOException - if the program cannot be executed
java.lang.SecurityException - if the current SecurityManager disallows program execution

getMessage

public static java.lang.String getMessage(java.lang.String key)
Returns the NLS'ed message for the given argument. This is only being called from SWT.

Parameters:
key - the key to look up
Returns:
the message for the given key
See Also:
SWT.getMessage(String)

getMessage

public static java.lang.String getMessage(java.lang.String key,
                                          java.lang.Object[] args)

interrupt

public static void interrupt()
Interrupt the current thread.

Note that this is not available on CLDC.


equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String s1,
                                       java.lang.String s2)
Compares two instances of class String ignoring the case of the characters and answers if they are equal.

Parameters:
s1 - string
s2 - string
Returns:
true if the two instances of class String are equal