当前位置:   article > 正文

groovy&&集合 list_groovy list

groovy list

一前一直没使用过groovy语言,但是在新的公司需要用到这个语言;不过还好,groovy是基于java之上的语言;学起来不是很吃力;
会一直更新新这篇文章。。。。。
刚开始的时候看到一个符号“<<”

List<Byte> types = Lists.newArrayList()
            if (type == 3) {
                types << (1 as byte)
                types << (2 as byte)
            } else {
                types << (byte) type
            }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

一开始很不理解,这不是按位运算符吗;啥意思啊我天;然后自己试了试:

class SymbolDemo {
    static void main(String[] args) {
        def i = methdod01(2)
        println(i)
    }
    static def methdod01(Integer a){
        Integer type = 3
        List<Integer> list = Lists.newArrayList();
        list << 1
        list << 2
        list << 3
        if (a == 2){
            list << a
        }else {
            list << 5
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

看到这些代码应该就很明确了。这相当于list.add
在这里插入图片描述需求是这样的一张图片;就是说需要从数据库中查书数据来,然后根据bug status(状态分组);

  List<BugStatusFindVo> bugStatusFindVos = Lists.newArrayList()
  List<Bug> bugs = bugService.findBugList(status, systemId, timeType, startTime, endTime)
        bugs.each {
              Bug bug ->
                 bugStatusFindVos.each {
                     BugStatusFindVo statusFindVo ->
                         if (bug.status == statusFindVo.status){
                            statusFindVo.bugs << bug
                         }
                 }
        }
        bugStatusFindVos.each {
            it.bugNum = it.bugs.size()
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

BugStatusFindVo :实体类是这样的:

class BugStatusFindVo implements Serializable{

    private static final long serialVersionUID = 8401342664443969084L

  Long bugNum

    Byte status

    String statusName

    List<Bug> bugs = Lists.newArrayList()
    }

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/810377?site
推荐阅读
相关标签
  

闽ICP备14008679号