My beautiful code----feel bad code smell (a serial code review later)

boolean fisrt=true;
for(int i=1;i<=FLAG;i++){
          if(fisrt&&((int)Math.pow(2, i)&carrier.getFlags())!=0){
              sb.append(flag[i-1]);
              fisrt=false;
          }else if(((int)Math.pow(2, i)&carrier.getFlags())!=0&&!fisrt){
              sb.append("  ,   "+flag[i-1]);
          }
  }

 

 

 

a few days later:

    private  String getFlagString(int flags) {
        StringBuilder sb = new StringBuilder();
        String separator = "  , ";
        for (CarrierFlagType c : CarrierFlagType.values()) {
            if ((CarrierFlagType.getCarrierTypeValue(c) & flags) != 0) {
                sb.append(c + separator);
            }
        }
        if (sb.length() > 0)
            sb.delete(sb.length() - separator.length(), sb.length() - 1);
        return sb.toString();

    }

你可能感兴趣的:(java)