将Condition转换为HashSet对象

时间:2016-02-22 18:51:53

标签: java

任何人都可以帮我如何在“if Condition”中将下面的代码写入Set对象。

if (!(Aaa.HELLO.equals(city.getcityMethod()) || 
Aaa.BANGALORE.equals(city.getcityMethod()))
                        || !((Bbb.MYSORE.equals(city.getcityTypeInformation().getCitypurspose()))
                                || (CityPurpose.RETRIED.equals(city.getCityTypeInformation().getCitypurspose(()))
                                || (CityPurpose.SOCIAL.equals(getcityMethod.getCityTypeInformation().getCitypurspose()))
                                || (CityPurpose.COMPANY.equals(getcityMethod.getCityTypeInformation().getCitypurspose())))) 

有些人喜欢这样:

CONVERTING =unmodifiable::< SET>(HashSet( //here using if condition logic);

这样CONVERTING可以像这样使用:

if( CONVERTING) { // some logic}

1 个答案:

答案 0 :(得分:1)

好吧,把你想要的数据放在适当类型的相关集合中,然后检查这些集合包含传递的数据:

Set<CityMethod> methods=new HashSet<>();
methods.add(Aaa.HELLO);
methods.add(Aaa.BANGALORE);
Set<CityPurpose> purposes=new HashSet<>();
purposes.add(Bbb.MYSORE);
purposes.add(CityPurpose.RETRIED);
...
boolean converting=methods.contains(city.getcityMethod()) ||
                   purposes.contains(cirty.getcityTypeInformation().getcityPurpose());
if (converting) {
  ...
}