Class Information
Package: com.onepg.util
Class Name: ValUtil
Description
Enumeration List
CharSet
public enum CharSet
Constants
UTF8SJISMS932
LineSep
public enum LineSep
Constants
LFCRCRLF
CsvType
public enum CsvType
- Defines how to add double quotes to each CSV item and how to handle line break codes.
- When CSV type allows line breaks and values contain line break codes, unifies line break codes (CRLF/CR) to LF.
- When CSV type does not allow line breaks (other than line break types) and values contain line break codes, converts line break codes (CRLF/CR/LF) to half-width spaces.
Constants
NO_DQDQ_ALLDQ_STD
Constants and Variables
BLANK
public String BLANK
ON
public String ON
OFF
public String OFF
LF
public String LF
CR
public String CR
CRLF
public String CRLF
TAB
public String TAB
UTF8
public String UTF8
SJIS
public String SJIS
MS932
public String MS932
JSON_NULL
public String JSON_NULL
null character.
Method List
isNull
public boolean isNull(Object obj)
null.- Checks if
Objectisnull.
Parameters
| Name | Type | Description |
|---|---|---|
obj |
Object |
target to check |
Return Value
boolean - true if null
isBlank
public boolean isBlank(String value)
- Treats as blank if composed only of half-width spaces, zero-byte string, or
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
Return Value
boolean - true if blank
isEmpty
public boolean isEmpty(Object[] values)
- Checks if array has zero length or is
null.
Parameters
| Name | Type | Description |
|---|---|---|
values |
Object[] |
target to check |
Return Value
boolean - true if empty
isEmpty
public boolean isEmpty(List<?> list)
- Checks if list has zero length or is
null.
Parameters
| Name | Type | Description |
|---|---|---|
list |
List<?> |
target to check |
Return Value
boolean - true if empty
isEmpty
public boolean isEmpty(Map<?, ?> map)
- Checks if map has zero length or is
null.
Parameters
| Name | Type | Description |
|---|---|---|
map |
Map<?, ?> |
target to check |
Return Value
boolean - true if empty
isValidIoKey
public boolean isValidIoKey(String key)
- Checks if characters can be used as keys for input/output map.
- Allowed characters are as follows:
- Lowercase letters
- Digits
- Underscore
- Hyphen
- Dot
Parameters
| Name | Type | Description |
|---|---|---|
key |
String |
target key to check |
Return Value
boolean - false if contains invalid characters
validateIoKey
public void validateIoKey(String key)
- Checks if characters can be used as keys for input/output map.
- Allowed characters are as follows:
- Lowercase letters
- Digits
- Underscore
- Hyphen
- Dot
- Throws
RuntimeExceptionif contains invalid characters.
Parameters
| Name | Type | Description |
|---|---|---|
key |
String |
target key to check |
nvl
public String nvl(String value)
null with blank.- Returns blank if string is
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
Return Value
String - blank if null
nvl
public String nvl(String value, String nullDefault)
null.- Returns replacement string if string is
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
nullDefault |
String |
replacement string |
Return Value
String - replacement string if null
nvl
public BigDecimal nvl(BigDecimal value)
null with zero.- Returns zero if number is
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
BigDecimal |
target to check |
Return Value
BigDecimal - zero if null
bvl
public String bvl(String value, String blankDefault)
- Returns replacement string if string is blank.
- Uses
#isBlank(String)for blank check.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
blankDefault |
String |
replacement string |
Return Value
String - replacement string if blank
join
public String join(String joint, String... values)
- Returns blank if array is empty.
nullis joined as blank.
Parameters
| Name | Type | Description |
|---|---|---|
joint |
String |
joining character |
values |
String... |
targets to join |
Return Value
String - the joined string
join
public String join(String joint, List<String> list)
- Returns blank if list is empty.
nullis joined as blank.
Parameters
| Name | Type | Description |
|---|---|---|
joint |
String |
joining character |
list |
List<String> |
targets to join |
Return Value
String - the joined string
join
public String join(String joint, Set<String> list)
- Returns blank if set is empty.
nullis joined as blank.
Parameters
| Name | Type | Description |
|---|---|---|
joint |
String |
joining character |
list |
Set<String> |
targets to join |
Return Value
String - the joined string
split
public String[] split(String value, String sep)
- Returns a zero-length array if the string is
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string to split |
sep |
String |
separator character |
Return Value
String[] - the split string array
splitReg
public String[] splitReg(String value, String sep)
- Returns a zero-length array if the string is
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string to split |
sep |
String |
separator character (regular expression) |
Return Value
String[] - the split string array
splitReg
public String[] splitReg(String value, String sep, int limitLength)
- Returns a zero-length array if the string is
null.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string to split |
sep |
String |
separator character (regular expression) |
limitLength |
int |
maximum length |
Return Value
String[] - the split string array
equals
public boolean equals(String str1, String str2)
- Treats
nullas a zero-byte blank string for comparison.
Parameters
| Name | Type | Description |
|---|---|---|
str1 |
String |
first target to compare |
str2 |
String |
second target to compare |
Return Value
boolean - true if equal
equals
public boolean equals(BigDecimal dec1, BigDecimal dec2)
- Treats
nullas zero for comparison.
Parameters
| Name | Type | Description |
|---|---|---|
dec1 |
BigDecimal |
first target to compare |
dec2 |
BigDecimal |
second target to compare |
Return Value
boolean - true if equal
substring
public String substring(String value, Integer beginIndex)
- Extracts from the start index to the end of the string.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string |
beginIndex |
Integer |
start index |
Return Value
String - the extracted string
substring
public String substring(String value, Integer beginIndex, Integer endIndex)
- Safely extracts a specified range of the string.
- Handles out-of-range specifications and invalid values appropriately.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string |
beginIndex |
Integer |
start index (optional); defaults to 0 if null is passed (omitted) |
endIndex |
Integer |
end index (optional); defaults to the string length if null is passed (omitted) |
Return Value
String - the extracted string
isAlphabetNumber
public boolean isAlphabetNumber(String value)
- Checks if the string is valid as alphanumeric characters.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
Return Value
boolean - true if valid
isNumber
public boolean isNumber(String value)
- Checks if the string is valid as a numeric value.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
Return Value
boolean - true if valid
isNumber
public boolean isNumber(String value, boolean minusNg, boolean decNg)
- Checks if the string is valid as a numeric value.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
minusNg |
boolean |
true to treat negative values as invalid |
decNg |
boolean |
true to treat decimals as invalid |
Return Value
boolean - true if valid
checkLength
public boolean checkLength(String value, int len)
- Assumes
#isBlank(String)istrue; returnsfalseif the target is blank.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
len |
int |
valid length |
Return Value
boolean - true if valid
checkLengthNumber
public boolean checkLengthNumber(String value, int intPartLen, int decPartLen)
- Verifies that the integer part and decimal part lengths are within the specified range.
- Arguments follow the same DB field definition format: specify the total length of integer and decimal parts, and the decimal part length separately.
- Assumes
#isNumber(String)istrue; returnsfalseif the target is blank.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check |
intPartLen |
int |
valid length of integer part plus decimal part combined |
decPartLen |
int |
valid length of decimal part |
Return Value
boolean - true if valid
isDate
public boolean isDate(String value)
- Checks if the string is valid as a date.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target to check (YYYYMMDD) |
Return Value
boolean - true if valid
isTrue
public boolean isTrue(String val)
- Checks if the string is considered as boolean true.
- Evaluates as follows:
- "1", "true", "yes", "on" (all half-width) are
true. nullor blank, as well as any other values, arefalse.- Case-insensitive.
- Leading and trailing half-width spaces are ignored.
- "1", "true", "yes", "on" (all half-width) are
Parameters
| Name | Type | Description |
|---|---|---|
val |
String |
target to check |
Return Value
boolean - true if considered as boolean true
dateToLocalDate
public LocalDate dateToLocalDate(java.util.Date date)
Parameters
| Name | Type | Description |
|---|---|---|
date |
java.util.Date |
Date type (including java.sql.Date) |
Return Value
LocalDate - LocalDate type
trimDq
public String trimDq(String value)
- Removes double quotes from the start and end of the string.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string |
Return Value
String - the string after removal
See Also
trimBothEnds
public String trimBothEnds(String value, char prefix, char suffix)
- Trims only when both end characters are found.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string |
prefix |
char |
character at the start |
suffix |
char |
character at the end |
Return Value
String - the string with both ends trimmed
trimBothEnds
public String trimBothEnds(String value, String prefix, String suffix)
- Trims only when both end characters are found.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string |
prefix |
String |
character at the start |
suffix |
String |
character at the end |
Return Value
String - the string with both ends trimmed
trimZenkakuSpace
public String trimZenkakuSpace(String value)
- Removes full-width spaces from the start and end of the string.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
target string |
Return Value
String - the string after removal
trimLeftZero
public String trimLeftZero(String value)
- Removes
"0"from the left of the string.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
string |
Return Value
String - the processed string
paddingLeftZero
public String paddingLeftZero(String value, int digit)
- Pads
"0"to the left of the string. - Pads with
0if the argument isnull.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
string |
digit |
int |
number of characters after padding |
Return Value
String - the processed string
paddingLeftZero
public String paddingLeftZero(int value, int digit)
- Converts a number to a string and pads
"0"to the left.
Parameters
| Name | Type | Description |
|---|---|---|
value |
int |
number |
digit |
int |
number of characters after padding |
Return Value
String - the processed string
deleteLastChar
public void deleteLastChar(StringBuilder sb)
Parameters
| Name | Type | Description |
|---|---|---|
sb |
StringBuilder |
StringBuilder |
deleteLastChar
public void deleteLastChar(StringBuilder sb, int length)
Parameters
| Name | Type | Description |
|---|---|---|
sb |
StringBuilder |
StringBuilder |
length |
int |
length of characters to delete from the end |
urlEncode
public String urlEncode(String url)
- To match JavaScript's encodeURIComponent, converts single-byte blank from "+" to "%20".
- Converts wildcard "*" to "%2A".
Parameters
| Name | Type | Description |
|---|---|---|
url |
String |
target string to convert |
Return Value
String - the converted string
urlDecode
public String urlDecode(String url)
Parameters
| Name | Type | Description |
|---|---|---|
url |
String |
target string to convert |
Return Value
String - the converted string
jsonEscape
public String jsonEscape(String value)
- Escapes characters that require escaping in JSON.
- Also escapes
nullas a control character.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
string |
Return Value
String - the converted string
jsonUnEscape
public String jsonUnEscape(String value)
- Removes escaping of characters that require escaping in JSON.
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
string |
Return Value
String - the string after removal
getSequenceCode
public String getSequenceCode()
- Returns a timestamp including nanoseconds converted to base-36.
- Sleeps for 1 nanosecond before returning to ensure uniqueness within the system.
- When used across multiple systems, additional consideration such as appending a hostname or system name is required to ensure unique values.
Return Value
String - the sequence code value