Categories: java, xml, spring, spring-boot, jaxb

setting up value to use it as identifier

1 answer

I am trying to set value for BetterID to filename. Then in next step using it as an identifier. need help with making this logic to make it a little better.

 List<CompareDecisionResponse> compareResponse= new ArrayList<CompareDecisionResponse>();         for (Answer singleAnswer : answer){             String identifier = "";             String name = "";              boolean IdentifierFound = false;              Response fileName = new Response(); //Response is another class.             name = fileName.getFileName();              for(AttrValWrapper wrapper: singleAnswer.getAttrValContainer().getAttrValWrapper()){                 if(wrapper.getAttrKey().equalsIgnoreCase("BetterID")){                     wrapper.setAttrVal(name); // setting up value.                  }                      if (wrapper.getAttrKey().equalsIgnoreCase("BetterID") && !StringUtils.isEmpty(wrapper.getAttrVal())){                         identifier = wrapper.getAttrVal();                         IdentifierFound = true;                     }else if (!IdentifierFound && wrapper.getAttrKey().equalsIgnoreCase("MemoryId")&&!StringUtils.isEmpty(wrapper.getAttrVal())){                         identifier = wrapper.getAttrVal();                     }                 }             } 

Thanks in Advance.

All answers to this question, which has the identifier 61208245

The best answer:

I don't have your complete context but still my few cents:

  1. You don't require second if loop

if (wrapper.getAttrKey().equalsIgnoreCase("BetterID") && !StringUtils...

because your are just checking the same condition (which you did in first if loop) and then retrieving the value. So removed that duplicate piece.

    List<CompareDecisionResponse> compareResponse= new      ArrayList<CompareDecisionResponse>();      for (Answer singleAnswer : answer){     String identifier = "";      String name = "";     boolean identifierFound = false;      Response fileName = new Response(); //Response is another class.     name = fileName.getFileName();      for(AttrValWrapper wrapper: singleAnswer.getAttrValContainer().getAttrValWrapper()){         if(wrapper.getAttrKey().equalsIgnoreCase("BetterID")){             wrapper.setAttrVal(name); // setting up value.             identifier = name;             identifierFound = true;         }         if (!identifierFound && wrapper.getAttrKey().equalsIgnoreCase("MemoryId")&&!StringUtils.isEmpty(wrapper.getAttrVal())){             identifier = wrapper.getAttrVal();         }     } 
  1. fixed variable name from IdentifierFound to identifierFound

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data