It looks horrible, but I don't see how can I factorize that ?
I thought of creating small boolean methods but I think it won't change too much, there will always be as many ifs ?
private String getFolderValue(TableRow row) {
String cote = row.getCellValue("B");
String typologie = row.getCellValue("G");
String description = row.getCellValue("Q");
if (cote.startsWith("DE")) {
return "Dessins";
}
if (cote.startsWith("PH")){
return "Photographies";
}
if(cote.startsWith("CA")) {
return "Catalogues";
}
if(cote.startsWith("PU") && typologie.contains("affiche")){
return "Publicité###Affiches";
}
if(cote.startsWith("PU") && typologie.contains("flyer")){
return "Publicité###Flyers";
}
if(cote.startsWith("PU") && description.contains("presse")){
return "Publicité###Presse";
}
if(cote.startsWith("PU") && (description.contains("Facture") || description.contains("devis"))){
return "Documents###Vente";
}
if(typologie.contains("Emballage")){
return "Visual Merchandising###Flyers";
}
if(typologie.contains("PLV")){
return "Visual Merchandising###PLV";
}
if(description.contains("Correspondances")){
return "Documents###Correspondances";
}
return null;
}
Ok, first of all let's notice that one of your conditions is repeated a lot. Let's try with a nested "if" and let's use StreamAPI.
I wouldn't get too much into refactoring here, as this is a simple strategy pattern and in some cases the more "generic" and fancy you go, the worse it is in the end, as it has to be simple to read.
EDIT: Let's divide into functions. You need to test it as I was in a hurry, but you should get the gist:
If you're using Java8 replace final var with proper type. If you prefer to do it lazily you need to pass references to Functional Interfaces there, but I think even "eager" evaluation looks not that bad ;)