有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将If条件转换为HashSet对象

有谁能帮我写下面的代码在“如果条件”设置对象

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) 个答案

  1. # 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) {
      ...
    }