首页 > 技术文章 > 如何从map中提取value并转换成long

iwangzheng 2018-04-08 11:44 原文

 

old:

taskReportDataDTO.setUv(Long.valueOf(hbaseData.get(HbaseColumnEnum.uv).toString()));

 

 new:

taskReportDataDTO.setPv(MapUtils.getLong(hbaseData, HbaseColumnEnum.pv.name().toLowerCase(), 0L));

 

 

http://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/MapUtils.html

static <K> Long getLong(Map<? super K,?> map, K key, Long defaultValue)
Looks up the given key in the given map, converting the result into a long, using the default value if the the conversion fails.

推荐阅读