Problem Statement:
First Case: Where inclusion and exclusion both are not empty so that means inclusion overrides anything in exclusion so for that algorithm is like this:
If key is either equal to 155 or 156 and if temp is there in inclusion then go into that if loop and do whatever you want. But if temp is not there in inclusion then don't do anything.
Second Case: Where inclusion is null and exclusion is not null so that means now you need to exclude everything present in exclusion string, so the algorithm is like this:
If key is either equal to 155 or 156 and if temp is not there in exclusion then do whatever you want to do in that else loop otherwise don't do anything.
Third Case: If key is not equal to 155 or 156 then do whatever you want to do in that loop.
Is there any way we can improve this code in terms of performance, readability, accuracy? as when I see this it contains lot of if/else statements to make the above problem works
P.S: Things that I am doing in each if/else loop is same everytime.
Cases1: Where input parameters can be-
String inclusion = null; // It can be null also
String exclusion = "100;77";
String temp = "0"; // It can change anytime
Cases2: Where input parameter can be-
String inclusion = "0"; // It can be null also
String exclusion = null;
String temp = "0"; // It can change anytime
Below is the code in which above input parameters can be used:
for(TesxAttrKey key: pdsxWriteRequest.getAttrKeys()){
if((key.equals("156") || key.equals("155"))) {
if(inclusion != null && !inclusion.trim().isEmpty()) {
if(inclusion.matches("(^|.*;)" + temp + "(;.*|$)")) {
//Check the DsxAttrValue has a Synthesizer
if(metadata!=null){
Synthesizer synthesizer = metadata.getSynthesizer();
if(synthesizer!=null){
//Synthesize the attribute
DsxAttrValue synthesizedVal =
synthesizer.synthesize(key, record);
val = synthesizedVal;
}
}
if(val!=null){
writeRecord.getAttrs().put(key, val);
}
}
} else {
if(!exclusion.matches("(^|.*;)" + temp + "(;.*|$)")) {
//Check the DsxAttrValue has a Synthesizer
if(metadata!=null){
Synthesizer synthesizer = metadata.getSynthesizer();
if(synthesizer!=null){
//Synthesize the attribute
DsxAttrValue synthesizedVal =
synthesizer.synthesize(key, record);
//if(synthesizedVal!=null){
val = synthesizedVal;
//}
}
}
if(val!=null){
writeRecord.getAttrs().put(key, val);
}
}
}
} else {
//Check the DsxAttrValue has a Synthesizer
if(metadata!=null){
Synthesizer synthesizer = metadata.getSynthesizer();
if(synthesizer!=null){
//Synthesize the attribute
DsxAttrValue synthesizedVal = synthesizer.synthesize(key, record);
//if(synthesizedVal!=null){
val = synthesizedVal;
//}
}
}
if(val!=null){
writeRecord.getAttrs().put(key, val);
}
}
Is there any way we can improve this code in terms of performance, as I have lot of if/else loops to solve the above problem?