getInt 추가

This commit is contained in:
yoon 2025-02-17 10:32:40 +09:00
parent 40932759a9
commit aeb96802f9

View File

@ -19,6 +19,7 @@ import org.springframework.util.ObjectUtils;
import java.io.Serial; import java.io.Serial;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Map; import java.util.Map;
public class MapDto extends ListOrderedMap { public class MapDto extends ListOrderedMap {
@ -57,4 +58,22 @@ public class MapDto extends ListOrderedMap {
return ObjectUtils.isEmpty(get(key)) ? null : new BigDecimal(getString(key)); 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;
}
} }