Compiere 3.1

org.compiere.util
Class Util

java.lang.Object
  extended by org.compiere.util.Util

public class Util
extends Object

General Utilities

Version:
$Id: Util.java,v 1.3 2006/07/30 00:52:23 jjanke Exp $
Author:
Jorg Janke, Yves Sandfort

Constructor Summary
Util()
           
 
Method Summary
static String cleanMnemonic(String in)
          Clean mnemonic Ampersand (used to indicate shortcut)
static String cleanWhitespace(String in)
          Clean - Remove all white spaces
static int count(String orig, String find)
          Should return you the number of occurences of "find" in orig
static String crc(String tempStr)
          Generate CRC String for tempStr
static File createBackup(File file)
          Create Backup of file
static void dump(Map<?,?> map)
          Dump a Map (key=value) to out
static int findIndexOf(String str, char search)
          Find index of search character in str.
static int findIndexOf(String str, char search1, char search2)
          Find index of search characters in str.
static int findIndexOf(String str, String search)
          Find index of search character in str.
static String getBackupName()
          Get Backup Name from time
static int getCount(String string, char countChar)
          Get the number of occurances of countChar in string.
static AttributedCharacterIterator getIterator(AttributedString aString, AttributedCharacterIterator.Attribute[] relevantAttributes)
          Return a Iterator with only the relevant attributes.
static String getNextWord(String tempStr)
          To split for indexes we will look for the next Word in tempstr
static String initCap(String in)
          Init Cap Words With Spaces
static boolean is7Bit(String str)
          Is 7 Bit
static boolean is8Bit(String str)
          Is 8 Bit
static boolean isAlphaNumeric(String str)
          Is String Alpha Numeric
static boolean isEmpty(String str)
          Is String Empty
static boolean isEqual(Object o1, Object o2)
          Is Equal.
static boolean isNumeric(String str)
          Is String Numeric
static void main(String[] args)
          Test
static String maskHTML(String content)
          Mask HTML content.
static String maskHTML(String content, boolean maskCR)
          Mask HTML content.
static void printActionInputMap(JComponent comp)
          Print Action and Input Map for component
static String remove(String original, String toBeRemoved, boolean ignoreCase)
          Remove String toBeRemoved from original
static String removeCRLF(String in)
          Remove CR / LF from String
static String removeSpecialChar(String tempStr)
          For some save scenarios and analysis we should remove special characters, i.e.
static StringBuffer replace(StringBuffer original, String search, String replace)
          Replace all occurences of search with replace in original
static StringBuffer replace(StringBuffer original, String search, String replace, boolean ignoreCase, boolean allOccurences)
          Replace all or one occurence of search with replace in original
static String replace(String original, char search, String replace)
          Replace all occurences of search with replace in original
static String replace(String original, String search, String replace)
          Replace all occurences of search with replace in original
static String replace(String original, String search, String replace, boolean ignoreCase, boolean allOccurences)
          Replace all or one occurence of search with replace in original
static StringBuffer replaceOne(StringBuffer original, String search, String replace)
          Replace one occurence of search with replace in original
static String replaceOne(String original, String search, String replace)
          Replace one occurence of search with replace in original
static StringBuffer replaceRegex(StringBuffer original, String regex, String replace, boolean CASE_INSENSITIVE)
          Run RegEx Expression against original String
static String replaceRegex(String original, String regex, String replace, boolean CASE_INSENSITIVE)
          Run RegEx Expression against original String
static int size(String str)
          Size of String in bytes
static String[] split(String searchIn, String splitter)
          This function will split a string based on a split character.
static byte[] toByteArray(String s)
          Convert the hex string to byte array
static String toHex(byte b)
          Return Hex String representation of byte b
static String toHex(char c)
          Return Hex String representation of char c
static String toHexString(byte[] bytes)
          Convert the binary to hex string
static String trimLength(String str, int length)
          Trim to max character length
static String trimSize(String str, int size)
          Trim to max byte size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

replace

public static StringBuffer replace(StringBuffer original,
                                   String search,
                                   String replace)
Replace all occurences of search with replace in original

Parameters:
original - the original String
search - the string to look for
replace - the string we will replace search with
Returns:
StringBuffer with result

replace

public static String replace(String original,
                             String search,
                             String replace)
Replace all occurences of search with replace in original

Parameters:
original - the original String
search - the string to look for
replace - the string we will replace search with
Returns:
String with result, null will get replaced by ""

replace

public static String replace(String original,
                             char search,
                             String replace)
Replace all occurences of search with replace in original

Parameters:
original - the original String
search - the character to look for
replace - the string we will replace search with
Returns:
String with result, null will get replaced by ""

replace

public static StringBuffer replace(StringBuffer original,
                                   String search,
                                   String replace,
                                   boolean ignoreCase,
                                   boolean allOccurences)
Replace all or one occurence of search with replace in original

Parameters:
original - the original StringBuffer
search - String to get replaced
replace - String to replace
ignoreCase - should we ignore cases
allOccurences - should all Occurences get replaced
Returns:
StringBuffer with result

replace

public static String replace(String original,
                             String search,
                             String replace,
                             boolean ignoreCase,
                             boolean allOccurences)
Replace all or one occurence of search with replace in original

Parameters:
original - the original StringBuffer
search - String to get replaced
replace - String to replace
ignoreCase - should we ignore cases
allOccurences - should all Occurences get replaced
Returns:
StringBuffer with result

replaceOne

public static StringBuffer replaceOne(StringBuffer original,
                                      String search,
                                      String replace)
Replace one occurence of search with replace in original

Parameters:
original - StringBuffer
search - String to look for
replace - String to replace search with
Returns:
new StringBuffer with result

replaceOne

public static String replaceOne(String original,
                                String search,
                                String replace)
Replace one occurence of search with replace in original

Parameters:
original - String to look in
search - String to search for
replace - String to replace search with
Returns:
new String with result

replaceRegex

public static StringBuffer replaceRegex(StringBuffer original,
                                        String regex,
                                        String replace,
                                        boolean CASE_INSENSITIVE)
Run RegEx Expression against original String

Parameters:
original - StringBuffer with original context
regex - Regular Expression to run as query
replace - Replace String
CASE_INSENSITIVE - whether we should take care of case or not
Returns:
StringBuffer with result

replaceRegex

public static String replaceRegex(String original,
                                  String regex,
                                  String replace,
                                  boolean CASE_INSENSITIVE)
Run RegEx Expression against original String

Parameters:
original - StringBuffer with original context
regex - Regular Expression to run as query
replace - Replace String
CASE_INSENSITIVE - whether we should take care of case or not
Returns:
String with result

split

public static String[] split(String searchIn,
                             String splitter)
This function will split a string based on a split character.

Parameters:
searchIn - The string to split
splitter - The separator
Returns:
String array of split values

remove

public static String remove(String original,
                            String toBeRemoved,
                            boolean ignoreCase)
Remove String toBeRemoved from original

Parameters:
original - String to look in
toBeRemoved - String to get removed
ignoreCase - should we take care of case
Returns:
String without toBeRemoved

getNextWord

public static String getNextWord(String tempStr)
To split for indexes we will look for the next Word in tempstr

Parameters:
tempStr - to look into
Returns:
nextWord in String

removeSpecialChar

public static String removeSpecialChar(String tempStr)
For some save scenarios and analysis we should remove special characters, i.e. HTML

Parameters:
tempStr - to remove Special Char
Returns:
new String without special chars

count

public static int count(String orig,
                        String find)
Should return you the number of occurences of "find" in orig

Parameters:
orig - The String to look in
find - The String to look for
Returns:
Number of occurences, 0 if none

crc

public static String crc(String tempStr)
                  throws IOException
Generate CRC String for tempStr

Parameters:
tempStr -
Returns:
CRC Code for tempStr
Throws:
IOException

removeCRLF

public static String removeCRLF(String in)
Remove CR / LF from String

Parameters:
in - input
Returns:
cleaned string

cleanWhitespace

public static String cleanWhitespace(String in)
Clean - Remove all white spaces

Parameters:
in - in
Returns:
cleaned string

maskHTML

public static String maskHTML(String content)
Mask HTML content. i.e. replace characters with &values; CR is not masked

Parameters:
content - content
Returns:
masked content

maskHTML

public static String maskHTML(String content,
                              boolean maskCR)
Mask HTML content. i.e. replace characters with &values;

Parameters:
content - content
maskCR - convert CR into
Returns:
masked content

getCount

public static int getCount(String string,
                           char countChar)
Get the number of occurances of countChar in string.

Parameters:
string - String to be searched
countChar - to be counted character
Returns:
number of occurances

isEmpty

public static boolean isEmpty(String str)
Is String Empty

Parameters:
str - string
Returns:
true if >= 1 char

isAlphaNumeric

public static boolean isAlphaNumeric(String str)
Is String Alpha Numeric

Parameters:
str - string
Returns:
false if other than A..Za..z0..9 - true also if empty

isNumeric

public static boolean isNumeric(String str)
Is String Numeric

Parameters:
str - string
Returns:
false if other than 0..9+-.,() or empty

getBackupName

public static String getBackupName()
Get Backup Name from time

Returns:
yyyy_mm_dd_hh_mm_ss

createBackup

public static File createBackup(File file)
Create Backup of file

Parameters:
file - original
Returns:
backup file or null if no success

findIndexOf

public static int findIndexOf(String str,
                              char search)
Find index of search character in str. This ignores content in () and 'texts'

Parameters:
str - string
search - search character
Returns:
index or -1 if not found

findIndexOf

public static int findIndexOf(String str,
                              char search1,
                              char search2)
Find index of search characters in str. This ignores content in () and 'texts'

Parameters:
str - string
search1 - first search character
search2 - second search character (or)
Returns:
index or -1 if not found

findIndexOf

public static int findIndexOf(String str,
                              String search)
Find index of search character in str. This ignores content in () and 'texts'

Parameters:
str - string
search - search character
Returns:
index or -1 if not found

toHex

public static String toHex(byte b)
Return Hex String representation of byte b

Parameters:
b - byte
Returns:
Hex

toHex

public static String toHex(char c)
Return Hex String representation of char c

Parameters:
c - character
Returns:
Hex

toHexString

public static String toHexString(byte[] bytes)
Convert the binary to hex string

Parameters:
bytes - byte array
Returns:
hex string

toByteArray

public static byte[] toByteArray(String s)
Convert the hex string to byte array

Parameters:
s - hex string
Returns:
byte array

initCap

public static String initCap(String in)
Init Cap Words With Spaces

Parameters:
in - string
Returns:
init cap

getIterator

public static AttributedCharacterIterator getIterator(AttributedString aString,
                                                      AttributedCharacterIterator.Attribute[] relevantAttributes)
Return a Iterator with only the relevant attributes. Fixes implementation in AttributedString, which returns everything

Parameters:
aString - attributed string
relevantAttributes - relevant attributes
Returns:
iterator

dump

public static void dump(Map<?,?> map)
Dump a Map (key=value) to out

Parameters:
map - Map

printActionInputMap

public static void printActionInputMap(JComponent comp)
Print Action and Input Map for component

Parameters:
comp - Component with ActionMap

is8Bit

public static boolean is8Bit(String str)
Is 8 Bit

Parameters:
str - string
Returns:
true if string contains chars <= 255

is7Bit

public static boolean is7Bit(String str)
Is 7 Bit

Parameters:
str - string
Returns:
true if string contains chars <= 127

cleanMnemonic

public static String cleanMnemonic(String in)
Clean mnemonic Ampersand (used to indicate shortcut)

Parameters:
in - input
Returns:
cleaned string

trimLength

public static String trimLength(String str,
                                int length)
Trim to max character length

Parameters:
str - string
length - max (incl) character length
Returns:
string

size

public static int size(String str)
Size of String in bytes

Parameters:
str - string
Returns:
size in bytes

trimSize

public static String trimSize(String str,
                              int size)
Trim to max byte size

Parameters:
str - string
size - max size in bytes
Returns:
string

isEqual

public static boolean isEqual(Object o1,
                              Object o2)
Is Equal. (including null compare, binary array)

Parameters:
o1 - one
o2 - two
Returns:
true if one == two

main

public static void main(String[] args)
Test

Parameters:
args - args

Compiere 3.1

Compiere® is a registered trademark of ComPiere, Inc. ©2004-2008 HumanFlash.com All rights reserved.