how to iterate duplicate list values and set to map object in java

Hi Experts,

i am getting list of object values from db.
i have to iterate and set to map object
if the duplicate is repeated i need to verify it is already added to the map or not
if it is already added to the map then i need to check the status
if the status is delivered in first object itself. no need to update the status
if the status is inprogress or pending i need to update the status in map

public class Problem{
private String problemName;
private String status;

setters and getters...

}

public class ProblemDto{
private Map<String,Problem> problems;
setters and getters..
}

List<Object> details = dataFromDao.getproblemsData(); //getting the data from database
Map<String,Problem> resultMap= new HashMap<>();
for(Object object :detaisl){
Object[] row = (Object[])object;
final Problem problem = new Problem();
problem.setProblemName((String) row[0]);
problem.setStatus((String) row[1]);
map.put((String)row[0],problem);
}

Open in new window


details list contains duplicated problem names and status
map will not allow duplicates.but i need to update status

let suppose i am getting the values from db like

laptopproblem   pending
telephoneproblem  completed
computerproblem  inprogress
//duplicate values
laptopproblem    delivered

in map i need to check laptopproblem instead of pending i need to replace with delivered.

laptop problem   inprogress

if i got one more duplicate problemname i no need to update, if the status is delivered no need to update  if not i have to update the status

how to do can some one suggest me
LVL 2
srikoteshAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
maybe something like (not tested):

for(Object object :detaisl){
  Object[] row = (Object[])object;
  String key = ((String)row[0];
  Problem problem = map.get(key);

  if(problem != null){
    String currentStatus = problem.getStatus();
    String newStatus =  (String)row[1];
    if(currentStatus.equals("pending") && newStatus.equals("delivered")){
        problem.setStatus(newStatus);
    }
  }else{
    map.put(key, problem)
  }
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srikoteshAuthor Commented:
Excellent
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.