-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Kervin edited this page Dec 17, 2020
·
13 revisions
Welcome to the complex-system wiki!
- Java8 lambda 使用Collectors.toMap方法时的两个问题:
- 1)当key重复时,会抛出异常:java.lang.IllegalStateException: Duplicate key **
- 2)当value为null时,会抛出异常:java.lang.NullPointerException
以下两种解决方式
List<RealtimeTag> tags;
tagValues = tags.stream().filter(tag->StringUtils.isNotBlank(tag.getTag())&&Objects.nonNull(tag.getValue())).collect(Collectors.toMap(RealtimeTag::getTag, RealtimeTag::getValue,(v1,v2)->v2));
List<RealtimeTag> tags;
tagValues = tags.stream().collect(Collector.of(HashMap::new, (m,tag)->m.put(tag.getTag(),tag.getValue()), (v1,v2)->v2, Characteristics.IDENTITY_FINISH));
- shell用法:
- 数组相关
#定义数组
array=("a" "b" "c");
#数组长度
len=${#array[@]}或${#array[*]}
#打印数组
${array[@]}或${array[*]}
#遍历数组
for arr in ${array[@]}
do
echo $arr
done;
- 字符串相关
#字符串截取
replicas="2/1";
max=${replicas%/*}; //2
min=${replicas##*/};//1
- if相关
#布尔判断
ENABLED=false;
if ! ${ENABLED} -a ${#array[@]} -gt 0 ;then
fi
#字符串匹配判断
name="test-web";
if [[ $name == *-web ]];then
fi
#字符串精确判断
name="test-web";
if [ $name == "test-web" ];then
fi
- 数值运算相关
num=1;
let num=$num*60+40-30/2
以上均属自主研发,版权归个人所属