org.eclipse.jface.util
Class Util
java.lang.Object
org.eclipse.jface.util.Util
-
public final class Util
- extends
Object
A static class providing utility methods to all of JFace.
-
Since:
- 3.1
|
Method Summary
|
static void
|
assertInstance
(
Object object,
Class c)
Verifies that the given object is an instance of the given class. |
static int
|
compare
(boolean left,
boolean right)
Compares two boolean values. |
static int
|
compare
(
Comparable[] left,
Comparable[] right)
Compares two arrays of comparable objects -- accounting for
null. |
static int
|
compare
(
Comparable left,
Comparable right)
Compares to comparable objects -- defending against null. |
static int
|
compare
(int left,
int right)
Compares two integer values. |
static int
|
compare
(
List left,
List right)
Compares two lists -- account for null. |
static boolean
|
endsWith
(
Object[] left,
Object[] right,
boolean equals)
Tests whether the first array ends with the second array. |
static boolean
|
equals
(
Object[] leftArray,
Object[] rightArray)
Tests whether two arrays of objects are equal to each other. |
static boolean
|
equals
(
Object left,
Object right)
Checks whether the two objects are null -- allowing for
null. |
static
String
|
getWS
()
Common WS query helper method. |
static int
|
hashCode
(int i)
Provides a hash code based on the given integer value. |
static int
|
hashCode
(
Object object)
Provides a hash code for the object -- defending against
null. |
static int
|
hashCode
(
Object[] objects)
Computes the hash code for an array of objects, but with defense against
null. |
static boolean
|
isCarbon
()
Common WS query helper method. |
static boolean
|
isCocoa
()
Common WS query helper method. |
static boolean
|
isGtk
()
Common WS query helper method. |
static boolean
|
isLinux
()
Common WS query helper method. |
static boolean
|
isMac
()
Common WS query helper method. |
static boolean
|
isMotif
()
Common WS query helper method. |
static boolean
|
isPhoton
()
Common WS query helper method. |
static boolean
|
isWin32
()
Common WS query helper method. |
static boolean
|
isWindows
()
Common WS query helper method. |
static boolean
|
isWpf
()
Common WS query helper method. |
static
String
|
replaceAll
(
String src,
String find,
String replacement)
Foundation replacement for String.replaceAll(*). |
static boolean
|
startsWith
(
Object[] left,
Object[] right,
boolean equals)
Checks whether the second array is a subsequence of the first array, and
that they share common starting elements. |
static
String
|
toString
(
Object[] array)
Converts an array into a string representation that is suitable for
debugging. |
static
String
|
translateString
(
ResourceBundle resourceBundle,
String key,
String defaultString)
Provides a translation of a particular key from the resource bundle. |
|
Methods inherited from class java.lang.
Object
|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
|
EMPTY_SORTED_SET
public static final
SortedSet EMPTY_SORTED_SET
- An unmodifiable, empty, sorted set. This value is guaranteed to never
change and never be
null.
ZERO_LENGTH_STRING
public static final
String ZERO_LENGTH_STRING
- A common zero-length string. It avoids needing write
NON-NLS
next to code fragments. It's also a bit clearer to read.
-
See Also:
-
Constant Field Values
WS_WIN32
public static final
String WS_WIN32
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_MOTIF
public static final
String WS_MOTIF
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_GTK
public static final
String WS_GTK
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_PHOTON
public static final
String WS_PHOTON
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_CARBON
public static final
String WS_CARBON
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_COCOA
public static final
String WS_COCOA
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_WPF
public static final
String WS_WPF
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
WS_UNKNOWN
public static final
String WS_UNKNOWN
- Windowing system constant.
-
Since:
- 3.5
-
See Also:
-
Constant Field Values
assertInstance
public static final void assertInstance(
Object object,
Class c)
- Verifies that the given object is an instance of the given class.
-
-
Parameters:
-
object - The object to check; may be null. -
c - The class which the object should be; must not be
null.
compare
public static final int compare(boolean left,
boolean right)
- Compares two boolean values.
false is considered to be
"less than" true.
-
-
Parameters:
-
left - The left value to compare -
right - The right value to compare
-
Returns:
-
-1 if the left is false and the
right is true. 1 if the opposite
is true. If they are equal, then it returns 0.
compare
public static final int compare(int left,
int right)
- Compares two integer values.
-
-
Parameters:
-
left - The left value to compare -
right - The right value to compare
-
Returns:
-
left - right
compare
public static final int compare(
Comparable left,
Comparable right)
- Compares to comparable objects -- defending against
null.
-
-
Parameters:
-
left - The left object to compare; may be null. -
right - The right object to compare; may be null.
-
Returns:
- The result of the comparison.
null is considered
to be the least possible value.
compare
public static final int compare(
Comparable[] left,
Comparable[] right)
- Compares two arrays of comparable objects -- accounting for
null.
-
-
Parameters:
-
left - The left array to be compared; may be null. -
right - The right array to be compared; may be null.
-
Returns:
- The result of the comparison.
null is considered
to be the least possible value. A shorter array is considered
less than a longer array.
compare
public static final int compare(
List left,
List right)
- Compares two lists -- account for
null. The lists must
contain comparable objects.
-
-
Parameters:
-
left - The left list to compare; may be null. This
list must only contain instances of Comparable. -
right - The right list to compare; may be null. This
list must only contain instances of Comparable.
-
Returns:
- The result of the comparison.
null is considered
to be the least possible value. A shorter list is considered less
than a longer list.
endsWith
public static final boolean endsWith(
Object[] left,
Object[] right,
boolean equals)
- Tests whether the first array ends with the second array.
-
-
Parameters:
-
left - The array to check (larger); may be null. -
right - The array that should be a subsequence (smaller); may be
null. -
equals - Whether the two array are allowed to be equal.
-
Returns:
-
true if the second array is a subsequence of the
array list, and they share end elements.
equals
public static final boolean equals(
Object left,
Object right)
- Checks whether the two objects are
null -- allowing for
null.
-
-
Parameters:
-
left - The left object to compare; may be null. -
right - The right object to compare; may be null.
-
Returns:
-
true if the two objects are equivalent;
false otherwise.
equals
public static final boolean equals(
Object[] leftArray,
Object[] rightArray)
- Tests whether two arrays of objects are equal to each other. The arrays
must not be
null, but their elements may be
null.
-
-
Parameters:
-
leftArray - The left array to compare; may be null, and
may be empty and may contain null elements. -
rightArray - The right array to compare; may be null, and
may be empty and may contain null elements.
-
Returns:
-
true if the arrays are equal length and the
elements at the same position are equal; false
otherwise.
hashCode
public static final int hashCode(int i)
- Provides a hash code based on the given integer value.
-
-
Parameters:
-
i - The integer value
-
Returns:
-
i
hashCode
public static final int hashCode(
Object object)
- Provides a hash code for the object -- defending against
null.
-
-
Parameters:
-
object - The object for which a hash code is required.
-
Returns:
-
object.hashCode or 0 if
object if null.
hashCode
public static final int hashCode(
Object[] objects)
- Computes the hash code for an array of objects, but with defense against
null.
-
-
Parameters:
-
objects - The array of objects for which a hash code is needed; may be
null.
-
Returns:
- The hash code for
objects; or 0 if
objects is null.
startsWith
public static final boolean startsWith(
Object[] left,
Object[] right,
boolean equals)
- Checks whether the second array is a subsequence of the first array, and
that they share common starting elements.
-
-
Parameters:
-
left - The first array to compare (large); may be null. -
right - The second array to compare (small); may be null. -
equals - Whether it is allowed for the two arrays to be equivalent.
-
Returns:
-
true if the first arrays starts with the second
list; false otherwise.
toString
public static final
String toString(
Object[] array)
- Converts an array into a string representation that is suitable for
debugging.
-
-
Parameters:
-
array - The array to convert; may be null.
-
Returns:
- The string representation of the array; never
null.
translateString
public static final
String translateString(
ResourceBundle resourceBundle,
String key,
String defaultString)
- Provides a translation of a particular key from the resource bundle.
-
-
Parameters:
-
resourceBundle - The key to look up in the resource bundle; should not be
null. -
key - The key to look up in the resource bundle; should not be
null. -
defaultString - The value to return if the resource cannot be found; may be
null.
-
Returns:
- The value of the translated resource at
key. If
the key cannot be found, then it is simply the
defaultString.
replaceAll
public static final
String replaceAll(
String src,
String find,
String replacement)
- Foundation replacement for String.replaceAll(*).
-
-
Parameters:
-
src - the starting string. -
find - the string to find. -
replacement - the string to replace.
-
Returns:
- The new string.
-
Since:
- 3.4
isWindows
public static final boolean isWindows()
- Common WS query helper method.
-
-
Returns:
-
true for windows platforms -
Since:
- 3.5
isMac
public static final boolean isMac()
- Common WS query helper method.
-
-
Returns:
-
true for mac platforms -
Since:
- 3.5
isLinux
public static final boolean isLinux()
- Common WS query helper method.
-
-
Returns:
-
true for linux platform -
Since:
- 3.5
isGtk
public static final boolean isGtk()
- Common WS query helper method.
-
-
Returns:
-
true for gtk platforms -
Since:
- 3.5
isMotif
public static final boolean isMotif()
- Common WS query helper method.
-
-
Returns:
-
true for motif platforms -
Since:
- 3.5
isPhoton
public static final boolean isPhoton()
- Common WS query helper method.
-
-
Returns:
-
true for photon platforms -
Since:
- 3.5
isCarbon
public static final boolean isCarbon()
- Common WS query helper method.
-
-
Returns:
-
true for carbon platforms -
Since:
- 3.5
isCocoa
public static final boolean isCocoa()
- Common WS query helper method.
-
-
Returns:
-
true for the cocoa platform. -
Since:
- 3.5
isWpf
public static final boolean isWpf()
- Common WS query helper method.
-
-
Returns:
-
true for WPF -
Since:
- 3.5
isWin32
public static final boolean isWin32()
- Common WS query helper method.
-
-
Returns:
-
true for win32 -
Since:
- 3.5
getWS
public static final
String getWS()
- Common WS query helper method.
-
-
Returns:
- the SWT windowing platform string.
-
Since:
- 3.5
-
See Also:
-
SWT.getPlatform()
Guidelines for using Eclipse APIs.
Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.