getInt 추가
This commit is contained in:
parent
40932759a9
commit
aeb96802f9
@ -19,6 +19,7 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapDto extends ListOrderedMap {
|
||||
@ -57,4 +58,22 @@ public class MapDto extends ListOrderedMap {
|
||||
return ObjectUtils.isEmpty(get(key)) ? null : new BigDecimal(getString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* 주어진 키에 해당하는 값을 Integer 타입으로 반환합니다.
|
||||
* 값이 BigInteger인 경우 자동으로 int로 변환합니다.
|
||||
*
|
||||
* @param key Map에서 값을 검색할 키
|
||||
* @return 해당 키에 대한 값(Integer 타입), 값이 없으면 null
|
||||
*/
|
||||
public Integer getInt(String key) {
|
||||
Object value = get(key);
|
||||
if (value instanceof BigInteger) {
|
||||
return ((BigInteger) value).intValue();
|
||||
} else if (value instanceof Integer) {
|
||||
return (Integer) value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user