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
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)
- リストが空の場合はブランクを返す。
nullはブランクとして連結される。
Parameters
| Name | Type | Description |
|---|---|---|
joint |
String |
つなぎ目文字 |
list |
List<String> |
連結対象 |
Return Value
String - 連結した文字列
join
public String join(String joint, Set<String> list)
- リストが空の場合はブランクを返す。
nullはブランクとして連結される。
Parameters
| Name | Type | Description |
|---|---|---|
joint |
String |
つなぎ目文字 |
list |
Set<String> |
連結対象 |
Return Value
String - 連結した文字列
split
public String[] split(String value, String sep)
- 文字が
nullの場合は長さゼロの配列を返す。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
分割対象文字 |
sep |
String |
分割文字 |
Return Value
String[] - 分割した文字列配列
splitReg
public String[] splitReg(String value, String sep)
- 文字が
nullの場合は長さゼロの配列を返す。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
分割対象文字 |
sep |
String |
分割文字(正規表現) |
Return Value
String[] - 分割した文字列配列
splitReg
public String[] splitReg(String value, String sep, int limitLength)
- 文字が
nullの場合は長さゼロの配列を返す。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
分割対象文字 |
sep |
String |
分割文字(正規表現) |
limitLength |
int |
最大長さ |
Return Value
String[] - 分割した文字列配列
equals
public boolean equals(String str1, String str2)
nullはゼロバイトブランク文字として比較する。
Parameters
| Name | Type | Description |
|---|---|---|
str1 |
String |
比較対象その1 |
str2 |
String |
比較対象その2 |
Return Value
boolean - 同値の場合は true
equals
public boolean equals(BigDecimal dec1, BigDecimal dec2)
nullはゼロとして比較する。
Parameters
| Name | Type | Description |
|---|---|---|
dec1 |
BigDecimal |
比較対象その1 |
dec2 |
BigDecimal |
比較対象その2 |
Return Value
boolean - 同値の場合は true
substring
public String substring(String value, Integer beginIndex)
- 開始インデックスから文字列の最後まで切り取る。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
対象文字列 |
beginIndex |
Integer |
開始インデックス |
Return Value
String - 切り取り文字列
substring
public String substring(String value, Integer beginIndex, Integer endIndex)
- 文字列の指定範囲を安全に切り取る。
- 範囲外の指定や不正な値に対して適切に処理する。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
対象文字列 |
beginIndex |
Integer |
開始インデックス(省略可能)null を渡した(省略した)場合は0 |
endIndex |
Integer |
終了インデックス(省略可能)null を渡した(省略した)場合は文字列長 |
Return Value
String - 切り取り文字列
isAlphabetNumber
public boolean isAlphabetNumber(String value)
- 文字列が英数字として有効かチェックする。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
チェック対象 |
Return Value
boolean - 有効な場合は true
isNumber
public boolean isNumber(String value)
- 文字列が数値として有効かチェックする。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
チェック対象 |
Return Value
boolean - 有効な場合は true
isNumber
public boolean isNumber(String value, boolean minusNg, boolean decNg)
- 文字列が数値として有効かチェックする。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
チェック対象 |
minusNg |
boolean |
マイナス値を無効とする場合は true |
decNg |
boolean |
小数を無効とする場合は true |
Return Value
boolean - 有効な場合は true
checkLength
public boolean checkLength(String value, int len)
#isBlank(String)がtrueの前提とし、チェック対象がブランクの場合はfalseを返す。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
チェック対象 |
len |
int |
有効桁数 |
Return Value
boolean - 有効な場合は true
checkLengthNumber
public boolean checkLengthNumber(String value, int intPartLen, int decPartLen)
- 整数部分と小数点以下の桁数が指定された範囲内であることを確認する。
- 引数はDB項目定義と同じで整数部と小数部を足した桁数と小数部だけの桁数で指定する。
#isNumber(String)がtrueの前提とし、チェック対象がブランクの場合はfalseを返す。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
チェック対象 |
intPartLen |
int |
整数部と小数部を足した有効桁数 |
decPartLen |
int |
小数部の有効桁数 |
Return Value
boolean - 有効な場合は true
isDate
public boolean isDate(String value)
- 文字列が日付として有効かチェックする。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
チェック対象(YYYYMMDD) |
Return Value
boolean - 有効な場合は true
isTrue
public boolean isTrue(String val)
- 文字列が真偽値「真」とみなす値かチェックする。
- 下記の評価を行う。
- "1", "true", "yes", "on"(すべて半角)は
true。 nullまたはブランクはfalseを含み、上記以外はfalse。- 大文字小文字を区別しない。
- 左右の半角スペースは無視する。
- "1", "true", "yes", "on"(すべて半角)は
Parameters
| Name | Type | Description |
|---|---|---|
val |
String |
チェック対象 |
Return Value
boolean - 真偽値「真」とみなす場合は true
dateToLocalDate
public LocalDate dateToLocalDate(java.util.Date date)
Parameters
| Name | Type | Description |
|---|---|---|
date |
java.util.Date |
Date型(java.sql.Date 含む) |
Return Value
LocalDate - LocalDate型
trimDq
public String trimDq(String value)
- 文字列の開始と終了のダブルクォーテーションを除去する。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
対象文字列 |
Return Value
String - 除去後文字列
See Also
trimBothEnds
public String trimBothEnds(String value, char prefix, char suffix)
- トリムして両端文字ともに見つかった場合のみ切り捨てる。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
対象文字列 |
prefix |
char |
前の端の文字 |
suffix |
char |
後ろの端の文字 |
Return Value
String - 両端を切り捨てた文字列
trimBothEnds
public String trimBothEnds(String value, String prefix, String suffix)
- トリムして両端文字ともに見つかった場合のみ切り捨てる。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
対象文字列 |
prefix |
String |
前の端の文字 |
suffix |
String |
後ろの端の文字 |
Return Value
String - 両端を切り捨てた文字列
trimZenkakuSpace
public String trimZenkakuSpace(String value)
- 文字列の開始と終了の全角スペースを除去する。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
対象文字列 |
Return Value
String - 除去後文字列
trimLeftZero
public String trimLeftZero(String value)
- 文字列の左の
"0"を除去する。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
文字列 |
Return Value
String - 処理後の文字
paddingLeftZero
public String paddingLeftZero(String value, int digit)
- 文字列の左に
"0"を詰める。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
文字列 |
digit |
int |
詰めた後の文字桁数 |
Return Value
String - 処理後の文字
paddingLeftZero
public String paddingLeftZero(int value, int digit)
- 数値を文字列に変換して左に
"0"を詰める。
Parameters
| Name | Type | Description |
|---|---|---|
value |
int |
数値 |
digit |
int |
詰めた後の文字桁数 |
Return Value
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 |
最終文字長さ |
urlEncode
public String urlEncode(String url)
- JavaScript の encodeURIComponent と合わせるため1バイトブランクを "+" から "%20" に変換しなおす。
- ワイルドカードの "*" を "%2A" に変換する。
Parameters
| Name | Type | Description |
|---|---|---|
url |
String |
変換文字列 |
Return Value
String - 変換後文字列
urlDecode
public String urlDecode(String url)
Parameters
| Name | Type | Description |
|---|---|---|
url |
String |
変換文字列 |
Return Value
String - 変換後文字列
jsonEscape
public String jsonEscape(String value)
- JSONでエスケープが必要な文字をエスケープする。
nullも制御文字としてエスケープする。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
文字列 |
Return Value
String - 変換後文字列
jsonUnEscape
public String jsonUnEscape(String value)
- JSONでエスケープが必要な文字のエスケープを除去する。
Parameters
| Name | Type | Description |
|---|---|---|
value |
String |
文字列 |
Return Value
String - 除去後文字列
getSequenceCode
public String getSequenceCode()
- ナノ秒まで含むタイムスタンプを36進数に変換した値を返す。
- システム内で常にユニークな値を返すため1ナノ秒スリープしてから返す。
- 複数のシステムで使用する場合、ユニークな値を返すためにはホスト名やシステム名を付加するなどの考慮が必要となる。
Return Value
String - シーケンスコード値