Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将If条件转换为HashSet对象_Java - Fatal编程技术网

Java 将If条件转换为HashSet对象

Java 将If条件转换为HashSet对象,java,Java,任何人都可以帮助我如何写下面的代码在“如果条件”设置对象 if (!(Aaa.HELLO.equals(city.getcityMethod()) || Aaa.BANGALORE.equals(city.getcityMethod())) || !((Bbb.MYSORE.equals(city.getcityTypeInformation().getCitypurspose()))

任何人都可以帮助我如何写下面的代码在“如果条件”设置对象

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);
if( CONVERTING) { // some logic}

那么,将所需的数据放入适当类型的相关集合中,然后检查这些集合是否包含传递的数据:

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) {
  ...
}
Set methods=newhashset();
add(Aaa.HELLO);
方法:添加(Aaa班加罗尔);
Set purposes=新HashSet();
目的。添加(Bbb.mystore);
目的。添加(城市目的。重试);
...
布尔转换=methods.contains(city.getcityMethod())||
包含(cirty.getcityTypeInformation().getcityPurpose());
如果(转换){
...
}

我不明白这个问题。你想重构出条件吗?我的意思是,你在不同的条件下检查一堆不同的东西——具体的问题是什么?您可以获取city purspose(sp?)并查看它是否包含在您正在检查的值数组中——这就是您正在寻找的更改类型吗?您是否要求在(重试、社交、公司)中使用Java等效的
getCitypurspose()
(假设
getCitypurspose()
getCityPurpose()
的输入错误)?