Package 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
-
-
Field Summary
Fields Modifier and Type Field Description static SortedSet<?>EMPTY_SORTED_SETAn unmodifiable, empty, sorted set.static StringWS_CARBONDeprecated.static StringWS_COCOAWindowing system constant.static StringWS_GTKWindowing system constant.static StringWS_MOTIFDeprecated.static StringWS_PHOTONDeprecated.static StringWS_UNKNOWNWindowing system constant.static StringWS_WIN32Windowing system constant.static StringWS_WPFWindowing system constant.static StringZERO_LENGTH_STRINGA common zero-length string.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidassertInstance(Object object, Class<?> c)Verifies that the given object is an instance of the given class.static intcompare(boolean left, boolean right)Compares two boolean values.static intcompare(int left, int right)Compares two integer values.static <T extends Comparable<? super T>>
intcompare(List<T> left, List<T> right)Compares two lists -- account fornull.static <T extends Comparable<? super T>>
intcompare(T[] left, T[] right)Compares two arrays of comparable objects -- accounting fornull.static <T extends Comparable<? super T>>
intcompare(T left, T right)Compares to comparable objects -- defending againstnull.static booleanendsWith(Object[] left, Object[] right, boolean equals)Tests whether the first array ends with the second array.static booleanequals(Object[] leftArray, Object[] rightArray)Deprecated.static booleanequals(Object left, Object right)Deprecated.static MonitorgetClosestMonitor(Display toSearch, Point toFind)Returns the monitor whose client area contains the given point.static StringgetWS()Common WS query helper method.static inthashCode(int i)Deprecated.return directly value, or useInteger.hashCode(int)static inthashCode(Object object)Deprecated.static inthashCode(Object[] objects)Deprecated.static booleanisCarbon()Deprecated.static booleanisCocoa()Common WS query helper method.static booleanisGtk()Common WS query helper method.static booleanisLinux()Common WS query helper method.static booleanisMac()Common WS query helper method.static booleanisMotif()Deprecated.static booleanisPhoton()Deprecated.static booleanisWin32()Common WS query helper method.static booleanisWindows()Common WS query helper method.static booleanisWpf()Common WS query helper method.static StringreplaceAll(String src, String find, String replacement)Foundation replacement forString#replaceAll(String, String), but without support for regular expressions.static booleanstartsWith(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 StringtoString(Object[] array)Converts an array into a string representation that is suitable for debugging.static StringtranslateString(ResourceBundle resourceBundle, String key, String defaultString)Provides a translation of a particular key from the resource bundle.
-
-
-
Field Detail
-
EMPTY_SORTED_SET
public static final SortedSet<?> EMPTY_SORTED_SET
An unmodifiable, empty, sorted set. This value is guaranteed to never change and never benull.
-
ZERO_LENGTH_STRING
public static final String ZERO_LENGTH_STRING
A common zero-length string. It avoids needing writeNON-NLSnext 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
@Deprecated public static final String WS_MOTIF
Deprecated.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
@Deprecated public static final String WS_PHOTON
Deprecated.Windowing system constant.- Since:
- 3.5
- See Also:
- Constant Field Values
-
WS_CARBON
@Deprecated public static final String WS_CARBON
Deprecated.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
-
-
Method Detail
-
assertInstance
public static 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 benull.c- The class which the object should be; must not benull.
-
compare
public static int compare(boolean left, boolean right)Compares two boolean values.falseis considered to be "less than"true.- Parameters:
left- The left value to compareright- The right value to compare- Returns:
-1if the left isfalseand the right istrue.1if the opposite is true. If they are equal, then it returns0.
-
compare
public static int compare(int left, int right)Compares two integer values.- Parameters:
left- The left value to compareright- The right value to compare- Returns:
left - right
-
compare
public static <T extends Comparable<? super T>> int compare(T left, T right)
Compares to comparable objects -- defending againstnull.- Parameters:
left- The left object to compare; may benull.right- The right object to compare; may benull.- Returns:
- The result of the comparison.
nullis considered to be the least possible value.
-
compare
public static <T extends Comparable<? super T>> int compare(T[] left, T[] right)
Compares two arrays of comparable objects -- accounting fornull.- Parameters:
left- The left array to be compared; may benull.right- The right array to be compared; may benull.- Returns:
- The result of the comparison.
nullis considered to be the least possible value. A shorter array is considered less than a longer array.
-
compare
public static <T extends Comparable<? super T>> int compare(List<T> left, List<T> right)
Compares two lists -- account fornull. The lists must contain comparable objects.- Parameters:
left- The left list to compare; may benull. This list must only contain instances ofComparable.right- The right list to compare; may benull. This list must only contain instances ofComparable.- Returns:
- The result of the comparison.
nullis considered to be the least possible value. A shorter list is considered less than a longer list.
-
endsWith
public static 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 benull.right- The array that should be a subsequence (smaller); may benull.equals- Whether the two array are allowed to be equal.- Returns:
trueif the second array is a subsequence of the array list, and they share end elements.
-
equals
@Deprecated public static boolean equals(Object left, Object right)
Deprecated.Checks whether the two objects arenull-- allowing fornull.- Parameters:
left- The left object to compare; may benull.right- The right object to compare; may benull.- Returns:
trueif the two objects are equivalent;falseotherwise.
-
equals
@Deprecated public static boolean equals(Object[] leftArray, Object[] rightArray)
Deprecated.Tests whether two arrays of objects are equal to each other. The arrays must not benull, but their elements may benull.- Parameters:
leftArray- The left array to compare; may benull, and may be empty and may containnullelements.rightArray- The right array to compare; may benull, and may be empty and may containnullelements.- Returns:
trueif the arrays are equal length and the elements at the same position are equal;falseotherwise.
-
hashCode
@Deprecated public static int hashCode(int i)
Deprecated.return directly value, or useInteger.hashCode(int)Provides a hash code based on the given integer value.- Parameters:
i- The integer value- Returns:
i
-
hashCode
@Deprecated public static int hashCode(Object object)
Deprecated.Provides a hash code for the object -- defending againstnull.- Parameters:
object- The object for which a hash code is required.- Returns:
object.hashCodeor0ifobjectifnull.
-
hashCode
@Deprecated public static int hashCode(Object[] objects)
Deprecated.Computes the hash code for an array of objects, but with defense againstnull.- Parameters:
objects- The array of objects for which a hash code is needed; may benull.- Returns:
- The hash code for
objects; or0ifobjectsisnull.
-
startsWith
public 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.- Parameters:
left- The first array to compare (large); may benull.right- The second array to compare (small); may benull.equals- Whether it is allowed for the two arrays to be equivalent.- Returns:
trueif the first arrays starts with the second list;falseotherwise.
-
toString
public static String toString(Object[] array)
Converts an array into a string representation that is suitable for debugging.- Parameters:
array- The array to convert; may benull.- Returns:
- The string representation of the array; never
null.
-
translateString
public static 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 benull.key- The key to look up in the resource bundle; should not benull.defaultString- The value to return if the resource cannot be found; may benull.- Returns:
- The value of the translated resource at
key. If the key cannot be found, then it is simply thedefaultString.
-
replaceAll
public static String replaceAll(String src, String find, String replacement)
Foundation replacement forString#replaceAll(String, String), but without support for regular expressions.- Parameters:
src- the original stringfind- the string to findreplacement- the replacement string- Returns:
- the new string, with all occurrences of
findreplaced byreplacement(not using regular expressions) - Since:
- 3.4
-
isWindows
public static boolean isWindows()
Common WS query helper method.- Returns:
truefor windows platforms- Since:
- 3.5
-
isMac
public static boolean isMac()
Common WS query helper method.- Returns:
truefor mac platforms- Since:
- 3.5
-
isLinux
public static boolean isLinux()
Common WS query helper method.- Returns:
truefor linux platform- Since:
- 3.5
-
isGtk
public static boolean isGtk()
Common WS query helper method.- Returns:
truefor gtk platforms- Since:
- 3.5
-
isMotif
@Deprecated public static boolean isMotif()
Deprecated.Common WS query helper method.- Returns:
truefor motif platforms- Since:
- 3.5
-
isPhoton
@Deprecated public static boolean isPhoton()
Deprecated.Common WS query helper method.- Returns:
truefor photon platforms- Since:
- 3.5
-
isCarbon
@Deprecated public static boolean isCarbon()
Deprecated.Common WS query helper method.- Returns:
truefor carbon platforms- Since:
- 3.5
-
isCocoa
public static boolean isCocoa()
Common WS query helper method.- Returns:
truefor the cocoa platform.- Since:
- 3.5
-
isWpf
public static boolean isWpf()
Common WS query helper method.- Returns:
truefor WPF- Since:
- 3.5
-
isWin32
public static boolean isWin32()
Common WS query helper method.- Returns:
truefor win32- Since:
- 3.5
-
getWS
public static String getWS()
Common WS query helper method.- Returns:
- the SWT windowing platform string.
- Since:
- 3.5
- See Also:
SWT.getPlatform()
-
getClosestMonitor
public static Monitor getClosestMonitor(Display toSearch, Point toFind)
Returns the monitor whose client area contains the given point. If no monitor contains the point, returns the monitor that is closest to the point. If this is ever made public, it should be moved into a separate utility class.- Parameters:
toSearch- point to find (display coordinates)toFind- point to find (display coordinates)- Returns:
- the monitor closest to the given point
- Since:
- 3.15
-
-