Flex Hash Map technique

srujanmiryala used Ask the Experts™
Dear All,

I have got the code for implementing matrix style for displaying the data(you can see it in the output).

In the inputFlight(Array) the order of the data coming from the XML(which is filtered by finalPricePerPerson) is perfect.

but when it comes to finalFlight(HashMap) for some iterations the order is coming perfect and later the order in the  finalFlight(HashMap) is changing. How to resolve this problem. I need the data in the order of price,
In the final output the order is coming uneven. I need it in the order based on price.

Please someone help me out.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

May I ask first why are you using some third party component HashMap class?

Simple just change your result type in your class from String to Object

internal class _Super_TestClassPort extends com.adobe.fiber.services.wrapper.WebServiceWrapper

//operation.resultElementType = String;
 operation.resultElementType = Object;

You have to get your XML as Object without extra encoding on the client side.


You are right.Thats not a problem actual requirement is that i need to capture all the airline names and the best fare relating to the stops like
if airline name is airindia , i need to capture the zerostop  fare,one stop fare and twostop fare (best fares) and i need to display them as you can see in the matrix style

0(zero stop fare)
808(one stop fare)
817 (two stop fare)

i have tried to achive this with the array and arraycollections with some hardcode logic and unable to do it.
At last i find this thirdparty hashmap wich can achive this kind of functonality.

but i found that in inputFlight the data is comming in the order but if you can check this code

for each(var item1:Flight in inputFlight){
                      var existFlight:Flight = finalFlight.getValue(item1.getAirline());
                      if(existFlight == null){
                            trace("IF Put: "+finalFlight.getKeys());
                            trace("Existing Fligth: "+existFlight.airline);
                            if (item1.getZerostopFare() != 0){
                                  if (existFlight.getZerostopFare() == 0){
                                  }else if(existFlight.getZerostopFare() > item1.getZerostopFare()){
                            if (item1.getOnestopFare() != 0){
                                  if (existFlight.getOnestopFare() == 0){
                                  }else if(existFlight.getOnestopFare() > item1.getOnestopFare()){
                            if (item1.getTwostopFare() != 0){
                                  if (existFlight.getTwostopFare() == 0){
                                  }else if(existFlight.getTwostopFare() > item1.getTwostopFare()){
                            trace("ELSE Put: "+finalFlight.getKeys());

the data moving into the loop is correct but when the data is pushing into finalflight it is not in the order how the data is pushed.

Top Expert 2011

I can see you are using Array (not ArrayCollection)
An Array class can represent on Java side as List or HashMap.
If you decalred java.utils.List you should get the same order, but if Hashtable
or Map your order can be changed
Top Expert 2011
I am not sure you need so complicated logic.

You can user native AS functions without Hashmap

var flights:Array = [];
flights.push( { name:"airindia", twoStopFare:0, oneStopFare:808, zeroStopFare:817 } );
flights.push( { name:"american", twoStopFare:400, oneStopFare:0, zeroStopFare:700} );
flights.push( { name:"united", twoStopFare:0, oneStopFare:750, zeroStopFare:0} );

trace("\nBest deal for two stop fare:");
trace("\nBest deal for one stop fare:");
trace("\nBest deal for zero stop fare:");

function printTwoStopFare(element:*, index:int, arr:Array):void {
      if(element.twoStopFare != 0)
            trace(element.name + " = $" +  element.twoStopFare);
function printOneStopFare(element:*, index:int, arr:Array):void {
      if(element.oneStopFare != 0)
            trace(element.name + " = $" +  element.oneStopFare);
function printZeroStopFare(element:*, index:int, arr:Array):void {
      if(element.zeroStopFare != 0)
            trace(element.name + " = $" +  element.zeroStopFare);

Result is:

Best deal for two stop fare:
american = $400

Best deal for one stop fare:
united = $750
airindia = $808

Best deal for zero stop fare:
american = $700
airindia = $817


Good solution but it cannot help it with my requirements, i have implemented at java side now which is working fine.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial