4 Replies - 750 Views - Last Post: 05 August 2016 - 04:22 AM Rate Topic: -----

#1 alinabb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 02-August 16

Occurrence of value in a map

Posted 04 August 2016 - 12:06 PM

public Map<String ,Car> combination(Map<String ,Car> carMap){
	
       for(Map.Entry<String, Car> entry : qualMap.entrySet()){ 
				
       Car carTemp = entry.getValue();
				
	for(CarDetails temp : carTemp.getCarDetails()){
	    if(Constants.VOLSWAGEN.equals(temp.getBrand) && Integer.parseInt(temp.getRank) <= 25){
		if (totalRank >= 9){
	             carTemp.setStatus("VALID");
	         }
		else if (totalRank >= 10 && totalPass >= 1){
		     carTemp.setStatus("VALID");
	        }
						
		else{
		     carTemp.setStatus("INVALID");
		}
	}
	carTemp.setStatus("INVALID");
       }
				
}


The size of my map will be either 1 or 2. So I can have these combination:
1. Valid
2. Invalid
3. Valid , Valid
4. Valid , invalid or vice versa
5. Invalid , Invalid


My question is , at the end of the for loop, i need to know if the map contain 2 invalid records , in order to do some processing. What is the best way to do this? (I can override the key if needed)

Is This A Good Question/Topic? 0
  • +

Replies To: Occurrence of value in a map

#2 NormR  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 644
  • View blog
  • Posts: 4,844
  • Joined: 25-December 13

Re: Occurrence of value in a map

Posted 04 August 2016 - 12:18 PM

Quote

i need to know if the map contain 2 invalid records

Can you use a variable to count the number of invalid records?
Was This Post Helpful? 1
  • +
  • -

#3 alinabb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 02-August 16

Re: Occurrence of value in a map

Posted 04 August 2016 - 09:41 PM

View PostNormR, on 04 August 2016 - 12:18 PM, said:

Quote

i need to know if the map contain 2 invalid records

Can you use a variable to count the number of invalid records?


it won't work. since the list carTemp.getCarDetails() will contain only one record with volswagen. So I need to check the rank of the volswagen first.
Was This Post Helpful? 0
  • +
  • -

#4 NormR  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 644
  • View blog
  • Posts: 4,844
  • Joined: 25-December 13

Re: Occurrence of value in a map

Posted 05 August 2016 - 03:18 AM

Quote

need to know if the map contain 2 invalid records

I don't know of any other ways to know if the map has 2 invalid records other than to count them.

Why do you think that won't work?
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3444
  • View blog
  • Posts: 15,607
  • Joined: 20-September 08

Re: Occurrence of value in a map

Posted 05 August 2016 - 04:22 AM

Quote

carTemp.setStatus("INVALID");

Your code is badly indented but it looks to me that the last occurrence of the above overrides anything preceding it
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1