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.

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)
リスト連結.
  • リストが空の場合はブランクを返す。
  • 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. "1", "true", "yes", "on"(すべて半角)は true
    2. null またはブランクは false を含み、上記以外は false
    3. 大文字小文字を区別しない。
    4. 左右の半角スペースは無視する。

Parameters

Name Type Description
val String チェック対象

Return Value

boolean - 真偽値「真」とみなす場合は true

dateToLocalDate

public LocalDate dateToLocalDate(java.util.Date date)
Date型 to LocalDate型変換.

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 - 除去後文字列

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)
最終1文字削除.

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)
URLエンコード変換.
  • JavaScript の encodeURIComponent と合わせるため1バイトブランクを "+" から "%20" に変換しなおす。
  • ワイルドカードの "*" を "%2A" に変換する。

Parameters

Name Type Description
url String 変換文字列

Return Value

String - 変換後文字列

urlDecode

public String urlDecode(String url)
URLデコード変換.

Parameters

Name Type Description
url String 変換文字列

Return Value

String - 変換後文字列

jsonEscape

public String jsonEscape(String value)
JSONエスケープ変換.
  • JSONでエスケープが必要な文字をエスケープする。
  • null も制御文字としてエスケープする。

Parameters

Name Type Description
value String 文字列

Return Value

String - 変換後文字列

jsonUnEscape

public String jsonUnEscape(String value)
JSONエスケープ変換除去.
  • JSONでエスケープが必要な文字のエスケープを除去する。

Parameters

Name Type Description
value String 文字列

Return Value

String - 除去後文字列

getSequenceCode

public String getSequenceCode()
シーケンスコード値取得.
  • ナノ秒まで含むタイムスタンプを36進数に変換した値を返す。
  • システム内で常にユニークな値を返すため1ナノ秒スリープしてから返す。
  • 複数のシステムで使用する場合、ユニークな値を返すためにはホスト名やシステム名を付加するなどの考慮が必要となる。

Return Value

String - シーケンスコード値