public String getCoverBottom(FlowAdditions additions) { if(null==additions){ return "默认"; } List<FlowCoverBottom> li = this.isMatchBottom(additions); if(null == li || li.isEmpty()){ return "默认"; } //根据权重输出兜底方。 int sum = li.stream().mapToInt(FlowCoverBottom::getIntRatio).sum(); int random = RandomUtils.nextInt(0, sum); ConcurrentSkipListMap<Integer,String> skipListMap = new ConcurrentSkipListMap<>(); int ceiling = 0; for(int i=0;i<li.size();i++){ FlowCoverBottom bottom = li.get(i); ceiling = ceiling+bottom.getIntRatio(); skipListMap.put(ceiling,bottom.getCode()); } return skipListMap.higherEntry(random).getValue(); }
标签:int,sum,li,随机数,命中,ConcurrentSkipListMap,additions,null From: https://www.cnblogs.com/guoziyi/p/17117038.html