ValUtil

Framework Components [com.onepg.util]

← Back to Class List

Class Information

Package: com.onepg.util

Class Name: ValUtil

Description

Value utility class.

Enumeration List

CharSet

public enum CharSet
Character set specification.

Constants

  • UTF8
  • SJIS
  • MS932

LineSep

public enum LineSep
Line break code.

Constants

  • LF
  • CR
  • CRLF

CsvType

public enum CsvType
CSV type enumeration.
  • 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_DQ
  • DQ_ALL
  • DQ_STD

Constants and Variables

BLANK

public String BLANK
Blank value (zero-byte string).

ON

public String ON
Code: ON value.

OFF

public String OFF
Code: OFF value.

LF

public String LF
Line break code - LF.

CR

public String CR
Line break code - CR.

CRLF

public String CRLF
Line break code - CRLF.

TAB

public String TAB
Tab character - TAB.

UTF8

public String UTF8
Character set specification - UTF-8.

SJIS

public String SJIS
Character set specification - Shift_JIS.

MS932

public String MS932
Character set specification - MS932.

JSON_NULL

public String JSON_NULL
JSON null character.

Method List

isNull

public boolean isNull(Object obj)
Checks if null.
  • Checks if Object is null.

Parameters

Name Type Description
obj Object target to check

Return Value

boolean - true if null

isBlank

public boolean isBlank(String value)
Checks if blank.
  • 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 empty.
  • 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 empty.
  • 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 empty.
  • 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 input/output map key format.
  • 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 input/output map key format.
  • Checks if characters can be used as keys for input/output map.
  • Allowed characters are as follows:
    • Lowercase letters
    • Digits
    • Underscore
    • Hyphen
    • Dot
  • Throws RuntimeException if contains invalid characters.

Parameters

Name Type Description
key String target key to check

nvl

public String nvl(String value)
Replaces 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)
Replaces 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)
Replaces 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)
Replaces blank.
  • 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)
Joins array.
  • Returns blank if array is empty.
  • null is 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)
Joins list.
  • Returns blank if list is empty.
  • null is 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)
Joins set.
  • Returns blank if set is empty.
  • null is 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)
Splits into array.
  • 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)
Splits into array using regular expression.
  • 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)
Splits into array using regular expression.
  • 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)
Compares strings.
  • Treats null as 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)
Compares numbers.
  • Treats null as 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)
Safely extracts a substring (start index only).
  • 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 substring.
  • 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 alphanumeric.
  • 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 numeric.
  • 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 numeric.
  • 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)
Checks length.
  • Assumes #isBlank(String) is true; returns false if 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)
Checks numeric length (precision).
  • 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) is true; returns false if 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 valid date.
  • 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 boolean true.
  • Checks if the string is considered as boolean true.
  • Evaluates as follows:
    1. "1", "true", "yes", "on" (all half-width) are true.
    2. null or blank, as well as any other values, are false.
    3. Case-insensitive.
    4. Leading and trailing half-width spaces are ignored.

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)
Converts from Date type to LocalDate type.

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.
  • 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

trimBothEnds

public String trimBothEnds(String value, char prefix, char suffix)
Trims both ends of string.
  • 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 both ends of string.
  • 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)
Trims full-width spaces from both ends of string.
  • 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 leading zeros.
  • 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 with leading zeros.
  • Pads "0" to the left of the string.
  • Pads with 0 if the argument is null.

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)
Pads with leading zeros.
  • 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)
Deletes the last character.

Parameters

Name Type Description
sb StringBuilder StringBuilder

deleteLastChar

public void deleteLastChar(StringBuilder sb, int length)
Deletes the last characters.

Parameters

Name Type Description
sb StringBuilder StringBuilder
length int length of characters to delete from the end

urlEncode

public String urlEncode(String url)
Converts URL encoding.
  • 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)
Converts URL decoding.

Parameters

Name Type Description
url String target string to convert

Return Value

String - the converted string

jsonEscape

public String jsonEscape(String value)
Converts JSON escape.
  • Escapes characters that require escaping in JSON.
  • Also escapes null as a control character.

Parameters

Name Type Description
value String string

Return Value

String - the converted string

jsonUnEscape

public String jsonUnEscape(String value)
Removes JSON escape conversion.
  • 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()
Retrieves the sequence code value.
  • 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