org.eclipse.jface.resource
Class StringConverter
java.lang.Object
org.eclipse.jface.resource.StringConverter
-
public class StringConverter
- extends
Object
Helper class for converting various data types to and from
strings. Supported types include:
-
boolean
-
int
-
long
-
float
-
double
-
org.eclipse.swt.graphics.Point
-
org.eclipse.swt.graphics.Rectangle
-
org.eclipse.swt.graphics.RGB
-
org.eclipse.swt.graphics.FontData
All methods declared on this class are static. This
class cannot be instantiated.
-
Restriction:
- This class is not intended to be subclassed by clients.
-
Restriction:
- This class is not intended to be instantiated by clients.
Method Summary
|
static
String[]
|
asArray
(
String value)
Breaks out space-separated words into an array of words. |
static
String[]
|
asArray
(
String value,
String[] dflt)
/**
Breaks out space-separated words into an array of words. |
static boolean
|
asBoolean
(
String value)
Converts the given value into a boolean. |
static boolean
|
asBoolean
(
String value,
boolean dflt)
Converts the given value into a boolean. |
static
String
|
asDisplayableString
(
FontData value)
Deprecated. use asString(FontData)
|
static double
|
asDouble
(
String value)
Converts the given value into a double. |
static double
|
asDouble
(
String value,
double dflt)
Converts the given value into a double. |
static float
|
asFloat
(
String value)
Converts the given value into a float. |
static float
|
asFloat
(
String value,
float dflt)
Converts the given value into a float. |
static
FontData
|
asFontData
(
String value)
Converts the given value into an SWT font data object. |
static
FontData
|
asFontData
(
String value,
FontData dflt)
Converts the given value into an SWT font data object. |
static
FontData[]
|
asFontDataArray
(
String value)
Convert the given value into an array of SWT font data objects. |
static int
|
asInt
(
String value)
Converts the given value into an int. |
static int
|
asInt
(
String value,
int dflt)
Converts the given value into an int. |
static long
|
asLong
(
String value)
Converts the given value into a long. |
static long
|
asLong
(
String value,
long dflt)
Converts the given value into a long. |
static
Point
|
asPoint
(
String value)
Converts the given value into an SWT point. |
static
Point
|
asPoint
(
String value,
Point dflt)
Converts the given value into an SWT point. |
static
Rectangle
|
asRectangle
(
String value)
Converts the given value into an SWT rectangle. |
static
Rectangle
|
asRectangle
(
String value,
Rectangle dflt)
Converts the given value into an SWT rectangle. |
static
RGB
|
asRGB
(
String value)
Converts the given value into an SWT RGB color value. |
static
RGB
|
asRGB
(
String value,
RGB dflt)
Converts the given value into an SWT RGB color value. |
static
String
|
asString
(boolean value)
Converts the given boolean value to a string. |
static
String
|
asString
(
Boolean value)
Converts the given boolean object to a string. |
static
String
|
asString
(double value)
Converts the given double value to a string. |
static
String
|
asString
(
Double value)
Converts the given double object to a string. |
static
String
|
asString
(float value)
Converts the given float value to a string. |
static
String
|
asString
(
Float value)
Converts the given float object to a string. |
static
String
|
asString
(
FontData value)
Converts a font data object to a string. |
static
String
|
asString
(
FontData[] value)
Converts a font data array to a string. |
static
String
|
asString
(int value)
Converts the given int value to a string. |
static
String
|
asString
(
Integer value)
Converts the given integer object to a string. |
static
String
|
asString
(long value)
Converts the given long value to a string. |
static
String
|
asString
(
Long value)
Converts the given long object to a string. |
static
String
|
asString
(
Point value)
Converts the given SWT point object to a string. |
static
String
|
asString
(
Rectangle value)
Converts the given SWT rectangle object to a string. |
static
String
|
asString
(
RGB value)
Converts the given SWT RGB color value object to a string. |
static
String
|
removeWhiteSpaces
(
String s)
Returns the given string with all whitespace characters removed. |
Methods inherited from class java.lang.
Object
|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
|
asArray
public static
String[] asArray(
String value)
throws
DataFormatException
- Breaks out space-separated words into an array of words.
For example:
"no comment"
into an array
a[0]="no"
and a[1]= "comment"
.
-
-
Parameters:
-
value
- the string to be converted
-
Returns:
- the list of words
-
Throws:
-
DataFormatException
- thrown if request string could not seperated
asArray
public static
String[] asArray(
String value,
String[] dflt)
- /**
Breaks out space-separated words into an array of words.
For example:
"no comment"
into an array
a[0]="no"
and a[1]= "comment"
.
Returns the given default value if the value cannot be parsed.
-
-
Parameters:
-
value
- the string to be converted -
dflt
- the default value
-
Returns:
- the list of words, or the default value
asBoolean
public static boolean asBoolean(
String value)
throws
DataFormatException
- Converts the given value into a boolean.
This method fails if the value does not represent a boolean.
Valid representations of true
include the strings
"t
", "true
", or equivalent in mixed
or upper case.
Similarly, valid representations of false
include the strings
"f
", "false
", or equivalent in mixed
or upper case.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as a boolean
-
Throws:
-
DataFormatException
- if the given value does not represent
a boolean
asBoolean
public static boolean asBoolean(
String value,
boolean dflt)
- Converts the given value into a boolean.
Returns the given default value if the
value does not represent a boolean.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a boolean, or the default value
asDouble
public static double asDouble(
String value)
throws
DataFormatException
- Converts the given value into a double.
This method fails if the value does not represent a double.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as a double
-
Throws:
-
DataFormatException
- if the given value does not represent
a double
asDouble
public static double asDouble(
String value,
double dflt)
- Converts the given value into a double.
Returns the given default value if the
value does not represent a double.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a double, or the default value
asFloat
public static float asFloat(
String value)
throws
DataFormatException
- Converts the given value into a float.
This method fails if the value does not represent a float.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as a float
-
Throws:
-
DataFormatException
- if the given value does not represent
a float
asFloat
public static float asFloat(
String value,
float dflt)
- Converts the given value into a float.
Returns the given default value if the
value does not represent a float.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a float, or the default value
asFontData
public static
FontData asFontData(
String value)
throws
DataFormatException
- Converts the given value into an SWT font data object.
This method fails if the value does not represent font data.
A valid font data representation is a string of the form
fontname-style-height
where
fontname
is the name of a font,
style
is a font style (one of
"regular"
, "bold"
,
"italic"
, or "bold italic"
)
and
height
is an integer representing the
font height. Example: Times New Roman-bold-36
.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as font data
-
Throws:
-
DataFormatException
- if the given value does not represent
font data
asFontDataArray
public static
FontData[] asFontDataArray(
String value)
- Convert the given value into an array of SWT font data objects.
-
-
Parameters:
-
value
- the font list string
-
Returns:
- the value as a font list
-
Since:
- 3.0
asFontData
public static
FontData asFontData(
String value,
FontData dflt)
- Converts the given value into an SWT font data object.
Returns the given default value if the
value does not represent a font data object.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a font data object, or the default value
asInt
public static int asInt(
String value)
throws
DataFormatException
- Converts the given value into an int.
This method fails if the value does not represent an int.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as an int
-
Throws:
-
DataFormatException
- if the given value does not represent
an int
asInt
public static int asInt(
String value,
int dflt)
- Converts the given value into an int.
Returns the given default value if the
value does not represent an int.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as an int, or the default value
asLong
public static long asLong(
String value)
throws
DataFormatException
- Converts the given value into a long.
This method fails if the value does not represent a long.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as a long
-
Throws:
-
DataFormatException
- if the given value does not represent
a long
asLong
public static long asLong(
String value,
long dflt)
- Converts the given value into a long.
Returns the given default value if the
value does not represent a long.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a long, or the default value
asPoint
public static
Point asPoint(
String value)
throws
DataFormatException
- Converts the given value into an SWT point.
This method fails if the value does not represent a point.
A valid point representation is a string of the form
x,y
where
x
and
y
are valid ints.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as a point
-
Throws:
-
DataFormatException
- if the given value does not represent
a point
asPoint
public static
Point asPoint(
String value,
Point dflt)
- Converts the given value into an SWT point.
Returns the given default value if the
value does not represent a point.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a point, or the default value
asRectangle
public static
Rectangle asRectangle(
String value)
throws
DataFormatException
- Converts the given value into an SWT rectangle.
This method fails if the value does not represent a rectangle.
A valid rectangle representation is a string of the form
x,y,width,height
where
x
,
y
,
width
, and
height
are valid ints.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as a rectangle
-
Throws:
-
DataFormatException
- if the given value does not represent
a rectangle
asRectangle
public static
Rectangle asRectangle(
String value,
Rectangle dflt)
- Converts the given value into an SWT rectangle.
Returns the given default value if the
value does not represent a rectangle.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a rectangle, or the default value
asRGB
public static
RGB asRGB(
String value)
throws
DataFormatException
- Converts the given value into an SWT RGB color value.
This method fails if the value does not represent an RGB
color value.
A valid RGB color value representation is a string of the form
red,green
,blue
where
red
, green
, and
blue
are valid ints.
-
-
Parameters:
-
value
- the value to be converted
-
Returns:
- the value as an RGB color value
-
Throws:
-
DataFormatException
- if the given value does not represent
an RGB color value
asRGB
public static
RGB asRGB(
String value,
RGB dflt)
- Converts the given value into an SWT RGB color value.
Returns the given default value if the
value does not represent an RGB color value.
-
-
Parameters:
-
value
- the value to be converted -
dflt
- the default value
-
Returns:
- the value as a RGB color value, or the default value
asString
public static
String asString(double value)
- Converts the given double value to a string.
Equivalent to
String.valueOf(value)
.
-
-
Parameters:
-
value
- the double value
-
Returns:
- the string representing the given double
asString
public static
String asString(float value)
- Converts the given float value to a string.
Equivalent to
String.valueOf(value)
.
-
-
Parameters:
-
value
- the float value
-
Returns:
- the string representing the given float
asString
public static
String asString(int value)
- Converts the given int value to a string.
Equivalent to
String.valueOf(value)
.
-
-
Parameters:
-
value
- the int value
-
Returns:
- the string representing the given int
asString
public static
String asString(long value)
- Converts the given long value to a string.
Equivalent to
String.valueOf(value)
.
-
-
Parameters:
-
value
- the long value
-
Returns:
- the string representing the given long
asString
public static
String asString(
Boolean value)
- Converts the given boolean object to a string.
Equivalent to
String.valueOf(value.booleanValue())
.
-
-
Parameters:
-
value
- the boolean object
-
Returns:
- the string representing the given boolean value
asString
public static
String asString(
Double value)
- Converts the given double object to a string.
Equivalent to
String.valueOf(value.doubleValue())
.
-
-
Parameters:
-
value
- the double object
-
Returns:
- the string representing the given double value
asString
public static
String asString(
Float value)
- Converts the given float object to a string.
Equivalent to
String.valueOf(value.floatValue())
.
-
-
Parameters:
-
value
- the float object
-
Returns:
- the string representing the given float value
asString
public static
String asString(
Integer value)
- Converts the given integer object to a string.
Equivalent to
String.valueOf(value.intValue())
.
-
-
Parameters:
-
value
- the integer object
-
Returns:
- the string representing the given integer value
asString
public static
String asString(
Long value)
- Converts the given long object to a string.
Equivalent to
String.valueOf(value.longValue())
.
-
-
Parameters:
-
value
- the long object
-
Returns:
- the string representing the given long value
asString
public static
String asString(
FontData[] value)
- Converts a font data array to a string. The string representation is
that of asString(FontData) seperated by ';'
-
-
Parameters:
-
value
- The font data.
-
Returns:
- The string representation of the font data arra.
-
Since:
- 3.0
asString
public static
String asString(
FontData value)
- Converts a font data object to a string. The string representation is
"font name-style-height" (for example "Times New Roman-bold-36").
-
-
Parameters:
-
value
- The font data.
-
Returns:
- The string representation of the font data object.
asString
public static
String asString(
Point value)
- Converts the given SWT point object to a string.
The string representation of a point has the form
x,y
where
x
and
y
are string representations of integers.
-
-
Parameters:
-
value
- the point object
-
Returns:
- the string representing the given point
asString
public static
String asString(
Rectangle value)
- Converts the given SWT rectangle object to a string.
The string representation of a rectangle has the form
x,y,width,height
where
x
,
y
,
width
, and
height
are string representations of integers.
-
-
Parameters:
-
value
- the rectangle object
-
Returns:
- the string representing the given rectangle
asString
public static
String asString(
RGB value)
- Converts the given SWT RGB color value object to a string.
The string representation of an RGB color value has the form
red,green
,blue
where
red
, green
, and
blue
are string representations of integers.
-
-
Parameters:
-
value
- the RGB color value object
-
Returns:
- the string representing the given RGB color value
asString
public static
String asString(boolean value)
- Converts the given boolean value to a string.
Equivalent to
String.valueOf(value)
.
-
-
Parameters:
-
value
- the boolean value
-
Returns:
- the string representing the given boolean
removeWhiteSpaces
public static
String removeWhiteSpaces(
String s)
- Returns the given string with all whitespace characters removed.
All characters that have codes less than or equal to '\u0020'
(the space character) are considered to be a white space.
-
-
Parameters:
-
s
- the source string
-
Returns:
- the string with all whitespace characters removed
asDisplayableString
public static
String asDisplayableString(
FontData value)
-
Deprecated. use asString(FontData)
- Converts a font data object to a string representation for display.
The string representation is
"font name-style-height" (for example "Times New Roman-bold-36").
-
-
Parameters:
-
value
- The font data.
-
Returns:
- The string representation of the font data object.
Guidelines for using Eclipse APIs.
Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.