A better method to eliminate having to create many lists to pare down to the required items.
Posted on 2013-06-26
I am a beginner.
I am being passed a list of values into a method.
Out of the List of value I have to perform evaluarion on the items in the
list with these types 'CISCO', 'IP', 'SRV'. The List will contain other types but these are the ones that require evaluation.
If type CISCO has a defict in cost
and there is a surplus for type IP with the same serial as CISCO , set CISCO excess to IP surplus. if type IP has a deficit in cost and type SRV with the same serial as IP has surplus set IP excess to SRV surplus
The items in the list are: name type serial cost laborcost excess
The only way that I know how to do this is to create 6 lists . Is there a better way to do this?
What I'm current doing is
looping through the passed list
if type = 'CISCO' and cost < laborCost
ADD TO deficitCISCOList
if type = 'IP' and cost < laborCost
ADD TO deficitIPList
Create the surplus list
if type = 'IP' and cost > laborCost
add to excessIPList
if type = 'SRV' and cost > laborCost
add to excessSRVList
loop through excessIPList
if IPCost serial = CISCO serial
update deficitCISCOList excess with excessIPList laborCost
add to adjustCISCOList
loop through excessSRVList
if IPCost serial = SRV serial
update deficitIPList excess with excessSRVList
add to adjustIPList
After that, I loop through the adjustCISCOList and the list passed to the method until I find the matching type and serial and update the passed list excess.