lundi 26 novembre 2018

How to minimize If else statement on below? or should i use map or switch?

public String identifyCellular(Long phone1, Long phone2, Long phone3) {

String cellular = null;
if (String.valueOf(phone2).trim().replaceAll("\\D", " ").equals("(07'\\d'{8})|(467'\\d'{8})")) {
  cellular = String.valueOf(phone2).trim().replaceAll("\\D", " ");
} else if (String.valueOf(phone1).trim().replaceAll("\\D", " ")
    .equals("(07'\\d'{8})|(467'\\d'{8})")) {
  cellular = String.valueOf(phone1).trim().replaceAll("\\D", " ");
} else {
  cellular = String.valueOf(phone3).trim().replaceAll("\\D", " ");
}
return cellular;

}

Aucun commentaire:

Enregistrer un commentaire