|
Servoy 5.x Public API | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.servoy.j2db.util.Utils
public class Utils
Utility methods
Normal Use: static methods
| Field Summary | |
|---|---|
static double |
DEFAULT_EQUALS_PRECISION
|
static int |
PLATFORM_LINUX
|
static int |
PLATFORM_MAC
|
static int |
PLATFORM_OTHER
|
static int |
PLATFORM_WINDOWS
|
static float |
PPI
|
| Method Summary | ||
|---|---|---|
static void |
applyMaxTime(Calendar cal)
Set Calendar time part to 23:59:59:999 |
|
static void |
applyMinTime(Calendar cal)
Set Calendar time part to 00:00:00:000 |
|
static
|
arrayAdd(T[] array,
T element,
boolean append)
Add an element to an array. |
|
static
|
arrayInsert(T[] src,
Object[] toAdd,
int position,
int n)
Insert an array into another array at a certain position. |
|
static
|
arrayJoin(T[] array1,
Object[] array2)
Join 2 arrays into 1. |
|
static
|
arrayMerge(T[] upperAarray,
T[] lowerAarray)
Merge two arrays in 1, the upperArray will be overlaid onto the lowerArray. |
|
static
|
arraySub(T[] array,
int beginIndex,
int endIndex)
Get a sub-array. |
|
static
|
asArray(Iterator<? extends T> it,
Class<T> clazz)
|
|
static
|
asList(Iterator<? extends T> it)
|
|
static String |
calculateMD5Hash(String input)
Deprecated. |
|
static String |
calculateMD5HashBase16(String input)
|
|
static String |
calculateMD5HashBase64(String password)
|
|
static String |
changeClassNameToFileName(String name)
Change the passed class name to its corresponding file name. |
|
static String |
changeFileNameToClassName(String name)
Change the passed file name to its corresponding class name. |
|
static Connection |
closeConnection(Connection connection)
|
|
static InputStream |
closeInputStream(InputStream is)
|
|
static OutputStream |
closeOutputStream(OutputStream os)
|
|
static Reader |
closeReader(Reader r)
|
|
static ResultSet |
closeResultSet(ResultSet resultSet)
|
|
static PreparedStatement |
closeStatement(PreparedStatement statement)
|
|
static Statement |
closeStatement(Statement statement)
|
|
static Writer |
closeWriter(Writer w)
|
|
static int |
compare(double d1,
double d2)
|
|
static double |
convertPageFormatUnit(int oldUnit,
int newUnit,
double value)
|
|
static String |
convertToString(Object o)
Convert to string representation, remove trailing '.0' for numbers. |
|
static int |
countNumbers(String s)
count the numbers in a string |
|
static PageFormat |
createPageFormat(double width,
double height,
double lm,
double rm,
double tm,
double bm,
int orientation,
int units)
Create a PageFormat object from the dimensions and margins. |
|
static byte[] |
decodeBASE64(String data)
|
|
static String |
encodeBASE64(byte[] data)
|
|
static boolean |
equalObjects(Object oldObj,
Object obj)
|
|
static boolean |
equalObjects(Object oldObj,
Object obj,
boolean ignoreCase)
|
|
static boolean |
equalObjects(Object oldObj,
Object obj,
double equalsPrecision)
|
|
static boolean |
equalObjects(Object oldObj,
Object obj,
double equalsPrecision,
boolean ignoreCase)
|
|
static CharSequence |
escapeMarkup(String s)
Deprecated. |
|
static CharSequence |
escapeMarkup(String s,
boolean escapeSpaces)
Deprecated. |
|
static CharSequence |
escapeMarkup(String s,
boolean escapeSpaces,
boolean convertToHtmlUnicodeEscapes)
Deprecated. |
|
static
|
filterArrayClass(Object[] array,
Class<T> clazz)
Filter an array for the items that are assignable from the given class. |
|
static String |
findLastNumber(String s)
hardcore try to find the last number in a string |
|
static String |
findNumber(String s)
hardcore try to find a number in a string |
|
static String |
formatNumber(Locale locale,
double param,
int digits)
Format a given number (Visitor (locale) specific) |
|
static String |
formatNumber(Locale locale,
double param,
String digits)
Format a given number (Visitor (locale) specific) |
|
static String |
formatNumber(Locale locale,
Object param,
String digits)
Format a given number (Visitor (locale) specific) |
|
static String |
formatNumber(Locale locale,
String param,
String digits)
Format a given number (Visitor (locale) specific) |
|
static String |
formatTime(int msec,
String format)
Format a given number of miliseconds in a formatted time Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone) |
|
static String |
formatTime(long msec,
String format)
Format a given number of miliseconds in a formatted time Note:if the time (in milliseconds) is smaller than ~month, it is calulated without a timezone) |
|
static String |
generateNormalizedName(String plainSQLName)
|
|
static boolean |
getAsBoolean(Object o)
Try to parse the given object as a boolean |
|
static boolean |
getAsBoolean(String s)
Try to parse the given string as a boolean |
|
static double |
getAsDouble(Object o)
Try to parse the given object as a double |
|
static double |
getAsDouble(Object o,
boolean throwOnFail)
Try to parse the given object as a double |
|
static double |
getAsDouble(String s)
Try to parse the given string as a double |
|
static double |
getAsDouble(String s,
boolean throwOnFail)
Try to parse the given string as a double |
|
static float |
getAsFloat(Object o)
Try to parse the given object as a float |
|
static float |
getAsFloat(Object o,
boolean throwOnException)
Try to parse the given object as a float |
|
static float |
getAsFloat(String s)
Try to parse the given string as a float |
|
static float |
getAsFloat(String s,
boolean throwOnException)
Try to parse the given string as a float |
|
static int |
getAsInteger(Object o)
Try to parse the given object as an integer |
|
static int |
getAsInteger(Object o,
boolean throwOnException)
Try to parse the given object as an integer |
|
static int |
getAsInteger(String s)
Try to parse the given string as an integer |
|
static int |
getAsInteger(String s,
boolean throwOnException)
Try to parse the given string as an integer |
|
static long |
getAsLong(Object o)
Try to parse the given object as a long |
|
static long |
getAsLong(Object o,
boolean throwOnException)
Try to parse the given object as a long |
|
static long |
getAsLong(String s)
Try to parse the given string as a long |
|
static long |
getAsLong(String s,
boolean throwOnException)
Try to parse the given string as a long |
|
static com.servoy.j2db.util.UUID |
getAsUUID(Object o,
boolean throwOnException)
Try to parse the given object as a UUID |
|
static Rectangle |
getBounds(Iterator<?> elements)
Get the rectangle that surrounds all elements |
|
static CharSequence |
getDotQualitfied(Object... tokens)
|
|
static byte[] |
getFileContent(File f)
|
|
static int |
getPlatform()
|
|
static int |
getPlatform(String osname)
|
|
static String |
getTXTFileContent(File f)
|
|
static String |
getTXTFileContent(File f,
Charset charset)
|
|
static String |
getTXTFileContent(InputStream f,
Charset charset)
|
|
static byte[] |
getURLContent(String url)
|
|
static InputStream |
getUTF8EncodedStream(String out)
|
|
static void |
invokeLater(com.servoy.j2db.IEventDelegator delegator,
List<Runnable> runnables)
|
|
static boolean |
isAppleMacOS()
|
|
static String |
longToHexString(long n,
int digits)
|
|
static Object |
mapToNullIfUnmanageble(Object value)
|
|
static Timestamp |
parseDate(String datetime,
String format)
Create a Date (time) from a String, returns null on failure Example: Timestamp t = Utils.parseDate("23-06-1975 6:08 AM", "dd-MM-yyyy hh:mm a"); |
|
static Object |
parseJSExpression(String s)
Parse a javascript string into a java string, example parseJSString('Hello world') returns Hello World |
|
static Object[] |
parseJSExpressions(List<Object> exprs)
|
|
static int |
readerWriterCopy(Reader is,
Writer os)
|
|
static byte[] |
readFile(File f,
long size)
|
|
static void |
releaseConnection(Connection connection)
|
|
static void |
rollback(Connection connection)
|
|
static BigDecimal |
roundNumber(Object number,
int precision,
boolean throwOnFail)
|
|
static int |
streamCopy(InputStream is,
OutputStream os)
|
|
static int |
streamCopy(InputStream is,
OutputStream os,
ActionListener l,
int actionSize)
|
|
static boolean |
stringContainsIgnoreCase(CharSequence source,
String contains)
|
|
static int |
stringIndexOf(String string,
int ch,
int escape)
|
|
static int |
stringIndexOf(String string,
int ch,
int escape,
int beginIndex)
|
|
static String |
stringInitCap(Object text)
|
|
static boolean |
stringIsEmpty(CharSequence str)
Checks whether the string is considered empty. |
|
static String |
stringJoin(Iterator iterator,
char separator)
Joins the elements of the provided Iterator into a single String containing the provided elements. |
|
static String |
stringJoin(Object[] array,
char separator)
|
|
static CharSequence |
stringLimitLenght(CharSequence str,
int length)
|
|
static String |
stringRemoveTags(String str)
Removes all substrings between '<' and corresponding '>'. |
|
static String |
stringReplace(String org,
String source,
String destination)
Method for replacing part of a string with a string |
|
static String |
stringReplace(String org,
String source,
String destination,
int replaceOccurence)
|
|
static String |
stringReplace(String org,
String source,
String destination,
int replaceOccurence,
boolean mustExact,
boolean caseInsensitiveSearch)
|
|
static String |
stringReplaceCaseInsensitiveSearch(String org,
String source,
String destination)
|
|
static String |
stringReplaceExact(String org,
String source,
String destination)
|
|
static String |
stringReplaceRecursive(String org,
String source,
String destination)
|
|
static boolean |
stringSafeEquals(String left,
String right)
Compares two strings no matter if they are null |
|
static String[] |
stringSplit(String string,
int separator,
int escape)
|
|
static String[] |
stringSplit(String s,
String split)
|
|
static String |
toEnglishLocaleLowerCase(String text)
|
|
static CharSequence |
toMultilineMarkup(CharSequence s)
Converts a String to multiline HTML markup by replacing newlines with line break entities (<br/>) and multiple occurrences of newline with paragraph break entities (<p>). |
|
static String |
unescape(String string,
int escape)
|
|
static boolean |
writeTXTFile(File file,
String content)
|
|
static boolean |
writeTXTFile(File f,
String content,
Charset charset)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final double DEFAULT_EQUALS_PRECISION
public static final int PLATFORM_LINUX
public static final int PLATFORM_MAC
public static final int PLATFORM_OTHER
public static final int PLATFORM_WINDOWS
public static final float PPI
| Method Detail |
|---|
public static void applyMaxTime(Calendar cal)
cal - public static void applyMinTime(Calendar cal)
cal -
public static <T> T[] arrayAdd(T[] array,
T element,
boolean append)
array - element - append -
public static <T> T[] arrayInsert(T[] src,
Object[] toAdd,
int position,
int n)
src - toAdd - position - n -
public static <T> T[] arrayJoin(T[] array1,
Object[] array2)
array1 - array2 -
public static <T> T[] arrayMerge(T[] upperAarray,
T[] lowerAarray)
For example:
upper = [x, y] lower = [a,b,c] => overlaid = [x, y, c]
upper = [a, b c] lower = [x, y] => overlaid = [a, b, c]
upperAarray - lowerAarray -
public static <T> T[] arraySub(T[] array,
int beginIndex,
int endIndex)
array - beginIndex - endIndex -
public static <T> T[] asArray(Iterator<? extends T> it,
Class<T> clazz)
public static <T> List<T> asList(Iterator<? extends T> it)
@Deprecated public static String calculateMD5Hash(String input)
public static String calculateMD5HashBase16(String input)
public static String calculateMD5HashBase64(String password)
public static String changeClassNameToFileName(String name)
name - Class name to be changed.
IllegalArgumentException - If a null name passed.public static String changeFileNameToClassName(String name)
name - Class name to be changed. If this does not represent a Java class then null is returned.
IllegalArgumentException - If a null name passed.public static Connection closeConnection(Connection connection)
public static InputStream closeInputStream(InputStream is)
public static OutputStream closeOutputStream(OutputStream os)
public static Reader closeReader(Reader r)
public static ResultSet closeResultSet(ResultSet resultSet)
public static PreparedStatement closeStatement(PreparedStatement statement)
public static Statement closeStatement(Statement statement)
public static Writer closeWriter(Writer w)
public static int compare(double d1,
double d2)
public static double convertPageFormatUnit(int oldUnit,
int newUnit,
double value)
public static String convertToString(Object o)
public static int countNumbers(String s)
s - the string with the numbers
public static PageFormat createPageFormat(double width,
double height,
double lm,
double rm,
double tm,
double bm,
int orientation,
int units)
width - the actual paper width - ignoring orientation. It is the width of the paper as seen by the printer.height - the actual paper height - ignoring orientation. It is the height of the paper as seen by the printer.lm - left margin of the page, not paper. So this is the left margin affected by orientation, as used in application.rm - right margin of the page, not paper. So this is the right margin affected by orientation, as used in application.tm - top margin of the page, not paper. So this is the top margin affected by orientation, as used in application.bm - bottom margin of the page, not paper. So this is the bottom margin affected by orientation, as used in application.orientation - the orientation of the page. Establishes a relation between page and paper coordinates.units - INCHES or MM.
public static byte[] decodeBASE64(String data)
public static String encodeBASE64(byte[] data)
public static final boolean equalObjects(Object oldObj,
Object obj)
public static final boolean equalObjects(Object oldObj,
Object obj,
boolean ignoreCase)
public static final boolean equalObjects(Object oldObj,
Object obj,
double equalsPrecision)
public static final boolean equalObjects(Object oldObj,
Object obj,
double equalsPrecision,
boolean ignoreCase)
@Deprecated public static CharSequence escapeMarkup(String s)
s - The string to be escaped
escapeMarkup(String, boolean)
@Deprecated
public static CharSequence escapeMarkup(String s,
boolean escapeSpaces)
s - The string to escapeescapeSpaces - True to replace ' ' with nonbreaking space
@Deprecated
public static CharSequence escapeMarkup(String s,
boolean escapeSpaces,
boolean convertToHtmlUnicodeEscapes)
s - The string to escapeescapeSpaces - True to replace ' ' with nonbreaking spaceconvertToHtmlUnicodeEscapes - True to convert non-7 bit characters to unicode HTML (...)
public static <T> T[] filterArrayClass(Object[] array,
Class<T> clazz)
array - clazz -
public static String findLastNumber(String s)
s - the string with the number
public static String findNumber(String s)
s - the string with the number
public static String formatNumber(Locale locale,
double param,
int digits)
param - the input numberdigits - number of digits
public static String formatNumber(Locale locale,
double param,
String digits)
param - the input numberdigits - number of digits
public static String formatNumber(Locale locale,
Object param,
String digits)
param - the input numberdigits - number of digits
public static String formatNumber(Locale locale,
String param,
String digits)
param - the input numberdigits - number of digits
public static String formatTime(int msec,
String format)
msec - the miliseconds (current time can be get by 'new java.util.Date().getTime()')format - the display format (format used from java.text.SimpleDateFormat!)
SimpleDateFormat
public static String formatTime(long msec,
String format)
msec - the miliseconds (current time can be get by 'new java.util.Date().getTime()')format - the display format
SimpleDateFormatpublic static String generateNormalizedName(String plainSQLName)
public static boolean getAsBoolean(Object o)
o - the object (Boolean, Number, String, ...) to parse
public static boolean getAsBoolean(String s)
s - the string to parse
public static double getAsDouble(Object o)
o - the object (Number, String, ...) to parse
public static double getAsDouble(Object o,
boolean throwOnFail)
o - the object (Number, String, ...) to parsethrowOnFail - whether or not to throw a RuntimeException on failure
public static double getAsDouble(String s)
s - the string to parse
public static double getAsDouble(String s,
boolean throwOnFail)
s - the string to parsethrowOnFail - whether or not to throw a RuntimeException on failure
public static float getAsFloat(Object o)
o - the object (Number, String, ...) to parse
public static float getAsFloat(Object o,
boolean throwOnException)
o - the object (Number, String, ...) to parsethrowOnException - whether or not to throw a RuntimeException on failure
public static float getAsFloat(String s)
s - the string to parse
public static float getAsFloat(String s,
boolean throwOnException)
s - the string to parsethrowOnException - whether or not to throw a RuntimeException on failure
public static int getAsInteger(Object o)
o - the object (Number, String, ...) to parse
public static int getAsInteger(Object o,
boolean throwOnException)
o - the object (Number, String, ...) to parsethrowOnException - whether to throw an exception if parsing failed
public static int getAsInteger(String s)
s - the string to parse
public static int getAsInteger(String s,
boolean throwOnException)
s - the string to parsethrowOnException - whether or not to throw a RuntimeException on failure
RuntimeException - in case of trouble when throwOnException is truepublic static long getAsLong(Object o)
o - the object (String, Number, ...) to parse
public static long getAsLong(Object o,
boolean throwOnException)
o - the Object (Number, String, ...) to parsethrowOnException - whether or not to throw a RuntimeException on failure
public static long getAsLong(String s)
s - the string to parse
public static long getAsLong(String s,
boolean throwOnException)
s - the string to parsethrowOnException - whether or not to throw a RuntimeException on failure
public static com.servoy.j2db.util.UUID getAsUUID(Object o,
boolean throwOnException)
o - the object to trythrowOnException - whether or not to throw a RuntimeException on failure
public static Rectangle getBounds(Iterator<?> elements)
elements -
public static CharSequence getDotQualitfied(Object... tokens)
public static byte[] getFileContent(File f)
public static int getPlatform()
public static int getPlatform(String osname)
public static String getTXTFileContent(File f)
public static String getTXTFileContent(File f,
Charset charset)
public static String getTXTFileContent(InputStream f,
Charset charset)
public static byte[] getURLContent(String url)
public static InputStream getUTF8EncodedStream(String out)
public static void invokeLater(com.servoy.j2db.IEventDelegator delegator,
List<Runnable> runnables)
public static boolean isAppleMacOS()
public static String longToHexString(long n,
int digits)
public static Object mapToNullIfUnmanageble(Object value)
public static Timestamp parseDate(String datetime,
String format)
datetime - the date as formatted stringformat - the format to be used
SimpleDateFormatpublic static Object parseJSExpression(String s)
s -
public static Object[] parseJSExpressions(List<Object> exprs)
public static int readerWriterCopy(Reader is,
Writer os)
throws IOException
IOException
public static byte[] readFile(File f,
long size)
public static void releaseConnection(Connection connection)
public static void rollback(Connection connection)
public static BigDecimal roundNumber(Object number,
int precision,
boolean throwOnFail)
public static int streamCopy(InputStream is,
OutputStream os)
throws IOException
IOException
public static int streamCopy(InputStream is,
OutputStream os,
ActionListener l,
int actionSize)
throws IOException
IOException
public static boolean stringContainsIgnoreCase(CharSequence source,
String contains)
public static int stringIndexOf(String string,
int ch,
int escape)
public static int stringIndexOf(String string,
int ch,
int escape,
int beginIndex)
public static String stringInitCap(Object text)
public static boolean stringIsEmpty(CharSequence str)
string is considered empty. Empty means that the string may contain whitespace, but no visible characters.
"\n\t " is considered empty, while " a" is not.
str - the string
public static String stringJoin(Iterator iterator,
char separator)
Joins the elements of the provided Iterator into a single String containing the provided elements.
No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.
iterator - the Iterator of values to join together, may be nullseparator - the separator character to use
null if null iterator input
public static String stringJoin(Object[] array,
char separator)
public static CharSequence stringLimitLenght(CharSequence str,
int length)
public static String stringRemoveTags(String str)
str - the initial string.
public static String stringReplace(String org,
String source,
String destination)
org - the orginal stringsource - the string to searchdestination - the string to replace
public static String stringReplace(String org,
String source,
String destination,
int replaceOccurence)
public static String stringReplace(String org,
String source,
String destination,
int replaceOccurence,
boolean mustExact,
boolean caseInsensitiveSearch)
public static String stringReplaceCaseInsensitiveSearch(String org,
String source,
String destination)
public static String stringReplaceExact(String org,
String source,
String destination)
public static String stringReplaceRecursive(String org,
String source,
String destination)
public static boolean stringSafeEquals(String left,
String right)
left - stringright - string
public static String[] stringSplit(String string,
int separator,
int escape)
public static String[] stringSplit(String s,
String split)
public static String toEnglishLocaleLowerCase(String text)
public static CharSequence toMultilineMarkup(CharSequence s)
s - String to transform
public static String unescape(String string,
int escape)
public static boolean writeTXTFile(File file,
String content)
public static boolean writeTXTFile(File f,
String content,
Charset charset)
|
Copyright © 2010 Servoy B.V. | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||