将Groovy数组与枚举值进行比较

时间:2016-07-22 06:46:08

标签: arrays groovy enums

我在groovy中有以下数组:

test = [Andrew-PAR, Jackson-CDG, Jilly-MAD, Mike-CDG, Tim-AGP]

并且也遵循枚举

NAME_PLACE("Andrew-PAR, Jackson-CDG, Brian-NY")

获取Andrew-PAR, Jackson-CDG, Brian-NY

等枚举值

我需要的是什么 *必须找出枚举中不在数组中的值' test'  即输出为'Brian-NY'

我尝试<enum returned values> - test来查找输出 - 但它显示了枚举中的整个值,如Andrew-PAR, Jackson-CDG, Brian-NY

枚举代码:

public enum StudentDetails {
    NAME_PLACE("Andrew-PAR, Jackson-CDG, Brian-NY"),
    NAME_COURSE("TEST1, TEST2"),

    private final String studentdetails

    StudentDetails (String studentdetails) {
        this.studentdetails = studentdetails
    }

    public String getstudent() {
        return studentdetails
    }

}

获取枚举值的代码:

def student = StudentDetails.values().find {
            val.equalsIgnoreCase(it.name())
        } ?.getstudent()

找到差异:

def diff = student - test

1 个答案:

答案 0 :(得分:2)

试试这个:

public enum StudentDetails {
  NAME_PLACE("Andrew-PAR, Jackson-CDG, Brian-NY"),
  NAME_COURSE("TEST1, TEST2"),

  private final String studentdetails

  StudentDetails (String studentdetails) {
     this.studentdetails = studentdetails
  }

   public String getstudent() {
      return studentdetails
   }

  public String value(){
     return studentdetails

  }

}


def test = ["Andrew-PAR", "Jackson-CDG", "Jilly-MAD", "Mike-CDG", "Tim-AGP"]


println StudentDetails.NAME_PLACE.value().split(",")*.trim()-test