Iterating the Map

Hi there
I am using a HashMap and I put some data in the map and I then get the data from the map with get(). However, I found that the order I get the object is in reverse order of the order that I put the data in the map. I just want to know if I can get the object from the map in the same order as I put the data.
Thanks for your help!
From
Edmund

When you iterate on a HashMap (Hashtable, HashSet...), you're actually getting them in pseudorandom order; that is, in the order of the modulo of object's hashCode value.
Neither Maps nor Sets inheritently preserve the "input" order of their elements. If you need to do that, you'll have to use a List (LinkedList, Vector, ArrayList...)

Similar Messages

  • Is there a way to overload the Map's toString() function?

    Hello everyone. I was wondering if its possible to overload the toString() function of the Map datastructure supplied by java.
    I looked it up and it says:
    public class HashMapextends AbstractMapSo I looked up AbstractMap and it says:
    public abstract class AbstractMapextends Objectimplements MapAnd I found a toString() function in the AbstractMap saying:
    toString
    public String toString() Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object). This implementation creates an empty string buffer, appends a left brace, and iterates over the map's entrySet view, appending the string representation of each map.entry in turn. After appending each entry except the last, the string ", " is appended. Finally a right brace is appended. A string is obtained from the stringbuffer, and returned.
    here: http://java.sun.com/j2se/1.3/docs/a...ml#toString()So I did the following:
    package parse;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.io.*;
    //this class should store all the Messages or "Events" and
    //you can access them based on their EntityID key.
    public class MessageDB extends HashMap
         //database to hold the information
         //     holds the Alerts/messages
         public static Map<Integer, List<String>> AlertMap;
         //Constructor
         MessageDB()
              AlertMap = new HashMap<Integer, List<String>>();
         public String toString()
              return ( )//not sure what to put here...
         //print, outputs the contents of the hashMap
         public static void print()
            //want to print out the Key and all the Messages
              //associated with that key
              Set keys = AlertMap.keySet();          // The set of keys in the map.
              Iterator keyIter = keys.iterator();
              System.out.println("The map contains the following associations:");
              while (keyIter.hasNext()) {
                    Object key = keyIter.next();  // Get the next key.
                    Object value = AlertMap.get(key);  // Get the value for that key.
                    System.out.println( "EntityID: " + key + "\n"
                                  + "Message: " + value + "\n" );
         //overloaded print to print to user screen.
         public static void print(PrintWriter out)
              //want to print out the Key and all the Messages
              //associated with that key
              Set keys = AlertMap.keySet();          // The set of keys in the map.
              Iterator keyIter = keys.iterator();
              out.println("The map contains the following associations:");
              out.flush();
              while (keyIter.hasNext()) {
                    Object key = keyIter.next();  // Get the next key.
                    Object value = AlertMap.get(key);  // Get the value for that key.
                   //out.flush();
                   /* out.println( "   (" + key + "," + value + ")" );
                   out.flush();*/
                   // out.println("------------------\n");
                   out.println("EntityID: " + key + "\n"
                                  + "Message: " + value + "\n");
                   //out.println("------------------\n");
                   out.flush();
         void add(Message msg)
              //getting the position of the List by EntityID if avaiable
              List<String> Alert = AlertMap.get(msg.entityID);
              //checking to see if there is a unique Key already in the Map.
              if (Alert == null)
                   //if there isnt a key in the map, add a new key, and a new List mapping
                   //to the key EntityID;
                     Alert = new ArrayList<String>();
                     AlertMap.put(msg.entityID, Alert);
                     Alert.add(msg.message);
              else
              //adding message to List
                   Alert.add(msg.message);
    }Right now the output is like this:
    The map contains the following associations:
    EntityID: 99999
                      Message: [a test ]
    EntityID: 800
                    Message: [this is a test , again a test ]
    EntityID: 801
                    Message: [again a test ]
    EntityID: 111
                    Message: [a test again yes , a test once again ]You see how its automatically doing [message1, message2,...,message x]
    By me calling this line of code:
    out.println("EntityID: " + key + "\n"
                                  + "Message: " + value + "\n");Because I found out it implicity calls the toString() method when concatinating it to a string.
    What I would like it to display would be:
    EntityID: 800
    Message:
    This is a test
    This is a test again
    any ideas would be great!
    Or is there a way to just iterate over the messages, rather than doing it my way?
    Message was edited by:
    lokie

    Hi,
    When you do a String concatenation in java, calls are implicitly done to #toString().
    Means, you are doing this:
    while (keyIter.hasNext()) {
                    Object key = keyIter.next();  /
                    Object value = AlertMap.get(key); 
                    System.out.println( "EntityID: " + key.toString()+ "\n"
                                  + "Message: " + value.toString() + "\n" );
    }The "[ [/b]... [b], ... , ... ]" you can see in your output is created by the implicit call to List#toString() method.
    You can Override it in an anonymous class by doing:
    if (Alert == null)
                   //if there isnt a key in the map, add a new key, and a new List mapping
                   //to the key EntityID;
                     Alert = new ArrayList<String>(){
                              @Override
                               public String toString(){
                                StringBuilder sb = new StringBuilder();
                       for(String s: this){
                        sb.append(s);
                        sb.append("\n");
                               return sb.toString();
                             };PS:
    toString() is usually used for debbuging only...

  • Error while deploying the mapping in owb 10gR2

    Hi friends,
    when i tried to deploy the mapping firstly i got the  below error like
    Name
    Action
    Status
    Log
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 11, column 3: PL/SQL: SQL Statement ignored         
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 18, column 59: PL/SQL: ORA-00942: table or view does not exist         
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 33, column 3: PL/SQL: SQL Statement ignored         
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 40, column 59: PL/SQL: ORA-00942: table or view does not exist         
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 216, column 7: PL/SQL: SQL Statement ignored         
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 237, column 59: PL/SQL: ORA-00942: table or view does not exist         
    From the above error, it states like table doesn't exist. Hence after checking that the source table connections that i used in the mapping seems to be wrong.
    so what i did is, in the control center i right clicked the source module where i have used source table and changed the connection but soon after i pressed the ok button as a part of registering i got the below error like
    >> RTC-5318 Invalid Location Type pair for Name oracle db and version 11.1
    I ignored the above error and continued to deploy the mapping, but as a result of mapping i got the below error like
    Name
    Action
    Status
    Log
    None
    INFORMATIONAL
    ORA-04052: error occurred when looking up remote object [email protected]@PEOPLE_SOURCE_LOCATION ORA-00604: error occurred at recursive SQL level 1 ORA-02019: connection description for remote database not found         
    COPY_OF_ORG_FINAL_MAPPING
    Create
    Warning
    ORA-06550: line 0, column 0: ORA-04052: error occurred when looking up remote object [email protected]@PEOPLE_SOURCE_LOCATION ORA-00604: error occurred at recursive SQL level 1 ORA-02019: connection description for remote database not found         
    Not sure, where im missing.
    Kindly help me friends,
    Thanks
    Brgds,
    Mini

    Hi Vidyanand,
    Did you create the runtime access user using the runtime assistant? Did you select the correct runtime repository (if you have more) to associate your runtime access user with?
    Note that there are 4 database roles being created when you create a runtime repository owner:
    - OWB_A_<runtime repository owner>
    - OWB_D_<runtime repository owner>
    - OWB_R_<runtime repository owner>
    - OWB_U_<runtime repository owner>
    If you would grant those roles to a user, then that user becomes an access user for the user with username <runtime repository owner>.
    Note that you can also use the runtime repository credentials to connect to the runtime repository for deployment purposes, but you may not want that because of security concerns.
    Thanks,
    Mark.

  • Error while Executing the mapping

    While I am executing the mapping this error is thrown by the server. It is big mapping and references many parent tables.
    ORA-12801: error signaled in parallel query server P001 ORA-01114: IO error writing block to file 201 (block # 523269) ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file OSD-04026: Invalid parameter passed. (OS 523275) ORA-01114: IO error writing block to file 201 (block # 523269) ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file OSD-04026: Invalid parameter passed. (OS 523275)
    Can you please provide the solution for this.
    Thanks in advance.

    This seems to be a DB server error, not an OWB issue. You should contact Oracle support.
    Regards:
    Igor

  • There should be a plus and minus for zoom on the maps for iphone

    when driving having to use two hands and navigate is troublesome to say the least.  I know its cleaner and simper when not crowding the screen or maybe a prgramming issue just seems like it would be easier to use with one hand when driving sometimes if i had the buttons for zooming more safer too.  Or maybe not.   Because its making you stop or you have to take your other hand off the wheel i can do it with one hand but maybe not everyone can zoom with one hand while driving.  Just a suggestion on something apple might want to put into next maps maybe or maybe you wont even need it since now theres turn by turn.  It still neccesary for using it on a bicycle or slower moving forms of tranportation where you might need it.  Just a suggestion i thought would be helpful and maybe even safer. 

    yeah but how many people do you think in actuality use it the way you are saying.  not me when i drive im always looking for a road to see if i passed it or not and thats because i had to reroute my traffic or im lost and i turn on the map and or i passed something because the map is sometimes off etc...  It could be anyting not just the need to not touch your phone. 

  • I am facing a strange problem on new iphone 5 that I bought last week. The maps app and the places in photo gallery shows the pin and my location, however there is no information of locations. Tried to close the apps, phone restart, reset etc. Please help

    I am facing a strange problem on new iphone 5 that I bought last week. The maps app and the places in photo gallery shows the pin and my location, however there is no information of locations. Tried to close the apps, phone restart, reset etc. I am accessing it via strong wireless connection and it works fine on other devices. Please help.

    zapgrap wrote:
    there is no information of locations.
    Then no information exists.  Use the Report a Problem button within the app to report it.

  • BPM Idoc collection without calling the mapping in BPM

    Hi Expert,
    I have an IDOC to file scenario in which source side I have to collect multiple IDOC and map it to a single file .I am achieving it through BPM . at present I am using one multimapping and calling this mapping in the BPM under transformation step its working  fine  but due to some constraint  , Now I want to achieve it using BPM but without calling the Mapping in the BPM i.e I don't want to use Transformation step in the BPM. Is it possible ????
    Regards,
    Saurabh

    Hi Saurabh,
    If that is the case it is preferable to collect the IDocs in ECC and then send them to XI at one go.
    Cheers !
    Lokesh

  • Is there any way to retreive the FileName in the mapping

    Is there any way to retreive the FileName and so that I can use that in my mapping. This is FILE2RFC scenario with NO BPM.
       I am using the adapter specific message attributes in the file sender CC.
    Thanks,
    Ravi
    null

    Yes you can retreive it.  Create an simple user defined function in the mapping and use the following code.
    Imports: com.sap.aii.mapping.api.*;
    Parameter: String filename
    Paramter: String filename;
    filename = fileName + ".DAT";
    DynamicConfiguration conf = (DynamicConfiguration) container
    .getTransformationParameters()
    .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "FileName");
    conf.put(key, filename);
    return filename;
    Or
    Just do whatever mentioned in this weblog:
    /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14
    ---Satish

  • Can not find the MAP in 0CO_PC_ACT_05

    dear experts,
    when i extract data from 0CO_PC_ACT_05, find some material have no the movemetn average price in some specific periods. why the period is not in series? how can i get the right MAP?
    another question, in r/3 side, in MBEW, our currenct period is 2007-006, but when i extract data via rsa3, i find the MAP about period 2009-002, why ? it's very strange!
    many thanks.
    brgds/steve
    Edited by: Steve Duan on Feb 23, 2009 7:46 AM
    Edited by: Steve Duan on Feb 23, 2009 8:52 AM

    ??

  • Maintaining the mapping information and writing update routine to populate

    Hi,
    Its my requriment to get the transactional data from r/3, here in the transaction data i will get the data in following format
    (for example)
    Material no.   Sales value    quantity ..
    M001              100           2
    M002              200           4
    M003              150           3
    now my requirement is to take the quantity per material number and multiply it with a factor called as SBU factor
    .. my problem is that this SBU factor is not maintained in r/3 means the mapping information of material no. with its relative SBU factor is not maintained. So i thought of two option as this mapping is fixed means it will not changed so we can maintain in bw system through 1) one time upload of flat file or
    2) maintaning a table in BW with mapping
    so users agreed to give the mapping information as follows
    Material no.    SBU factor
    M001              5
    M002              10
    M003              7
    now while uplading the transational data i need to take the SBU factor per material that is maintained through flat file or table and multiply it with quantity and store it quantity.
    for example(the result i need in cube)
    material no.   sales value    quantity(quantity * SBU)
    M001             100           2*5=10
    M002             200           4*10=40
    M003             150           3*7=21
    so i can do this at two level at transfer rules or update rules.
    I need following clarification
    1) shall i load the mapping information through flat file or maintain it in table?
    2) If i will do the transformation at update rules so wht routine (start or update) should i write to get the SBU factor per material and do transformations
    If possible send the sample routine.
    Pls reply ASAP.
    Thanks
    Saleem.

    Hi Saleem,
    Nimesh is right..Do the multiplication in the Update rules.
    If the data for this SBU factor is less and is always fixed, you can go for one time upload, else set up a RFC Call to load this data to BW from R/3 if no datasource for the same exist.
    Else you can also maintain a table in BW, in which one time upload could be done by writing an ABAP, or manually. And then you can provide authorizsation to add more values to it, so that the table can be maintained.
    And then in Update rules, use the table for look up and get the SBU Factor per material.
    Some thing like
    Select * from the <ODS table or Table name> into <internal table>
    Loop at Data_Package.
    Read table <internal table> for all values in Data_Package where internal table-Material = Data_package-MAterial.
    If sy-subrc = 0.
    Sales Value = Sales Value * internal table-SBU Factor.
    ENDIF.
    MODIFY DATA_PACKAGE.
    ENDLOOP.
    You might need to make more changes to this code as required.
    Assign points if useful
    Regards
    Rohit

  • Issue in Color Theme on the map with ADF geographic components

    I am facing an issue in bringing up a map using color theme .I can able to bring up a map with color themes using geographic components feature in ADF.
    The problem here is 'Edit Color Map Theme' dialog which lists Map Theme in five categories like continents,counties,countries,states_abbrev,states_names.
    we had implemented map using Color Theme based on the states_abbrev and found it was working properly.
    But after some days we found that the settings we made to work for the map no longer works and resulted in no color theme on the map being displayed on the page.
    It was found that the states_names works properly instead of states_abbrev by that time.
    But again after some days it didnt work with state_names and we revert back our code to follow state_abbrev so as to get the desired result.
    Does somebody know where is the problem and how to approach this issue?

    Quick Install is gone.
    Database repair doesn't work.
    Color coded categories is gone, and as you've discovered Theme colors are gone.
    Print to Excel is gone.
    Many desktop clients that worked with 4.2 do not work.
    It won't work with legacy devces.
    and others.... There are lots of complaints about 6.2 scattered around the forums.  Personally, the HotSync manager keeps forgetting the connections I've set, and goes to default views.
    You aren't missing much of anything, IMHO.
    WyreNut
    Post relates to: Centro (AT&T)
    Message Edited by WyreNut on 02-20-2009 12:18 PM
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • How to multiple layers in the MAP web item?

    Hi experts,
    I'm working on a demo with BWGIS. I encounter several problems with the MAP web item.
    My demo:
    QA results visualized on global (region object - e.g. Europe, Asia), country (country object) and plant level. Use geo-drilldown to navigate into the lower layers functionality to get from the global view to the countries within one region and plants within one country.
    My settings:
    Region is a static geo-characteristic. For region I used the cont200.shp file. Also country is a static geo-characteristic, here I used cntry200.shp. For test I used ARCGIS to draw (points) some example plants in the country shape file. I uploaded this shape file to the plant object (also static).
    My success:
    I'm able to display the QA results in a separate global or country view within the 3.x Web template.
    My problems:
    A) The map web item in 7.0 does not display any data: it looks like no link can be made between the query result and graphic although we installed the latest IGS.
    B) I'm not able to drilldown from a global view to the countries within one region (doubleclick on one region in global view) within the 3.x Analyzer and 3.x Web template.
    My first question is about the concept of BWGIS:
    1) I want to use geo-drilldown (double-click) to navigate to the lower layers. For example in the global view I see only the QA result per region (shape file of region object) -> doubleclick on Europe, I expect to zoom in to Europe and see the QA results for all the countries in Europe (shape file of country object). How do I modell this in the web application designer?
    alt. 1a: 1 map – 1 layer - 1 dataprovider - underneath 1 query with region and country in the row is not allowed, so how to navigate between the two geo-relevant objects?
    alt. 1b: 1 map - 2 layers (2 shape files) - 2 dataproviders - 2 queries, one with QA result per region and one per country -> in that case both will be displayed at the same time, is not what I want. How to navigate between the two layers?
    alt. other ?
    2) I know how to make maps with multiple layers in ARCGIS, but do I need this for BWGIS, because one layer is one shape file? So do multiple layers in the map web item correspond to multiple layers in a ESRI ArcMap Document.
    More specific questions:
    3) Is there a lot of experience with the map web item in 7.0, documentation and working examples? Are there known problems (I can't find anything in sap notes). Is it better to still use the 3.5 Web Application Designer for this?
    4) There is very little information on SAP help, SDN and other forums about BEx Map and moreover the MAP web item. Does anyone have more documentation for me?
    Thanks in advance.
    With kind regards,
    Rick Stoll

    Hi Rick,
    I am working on the same topic. I am strongly interessted in solutions to your open questions, that you pulled forward in the past.
    Did you make any progress?
    Thanks in advance and regards
    Marcus

  • I can't seem to make a working profile to connect to office 365 on a windows 7 pc with only the mapi cdo runtime version 6.5.8320.0 installed using mfcmapi nor programmatically

    Hi,
    I have been struggling with this for a few days now.
    i have pc where no outlook is installed, where i installed the MAPI CDO Runtime may update (version 6.5.8320.0). i checked in the registry that the default mail provider was set to exchangemapi (HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail) .. it is.
    I downloaded the lastest version of mfcmapi, which i believe was the version of december 2013
    but i can't seem to create a profile for office 365 in it. I followed http://blogs.msdn.com/b/dvespa/archive/2013/05/21/how-to-mfcmapi-create-mapi-profile-exchange-2013.aspx and then i changed the properties to what was proposed here http://blogs.msdn.com/b/dvespa/archive/2013/07/15/create-profile-connect-mfcmapi-to-office-365.aspx
    That did not work, i keep getting an error one ore more properties are invalid when i try to use that created profile to connect to office 365 (from within mfcmapi).
    I also changed some of those proposed values to what autodiscover was telling me like setting PR_PROFILE_RPC_AUTH_PACKAGE to RPC_C_AUTHN_ANONYMOUS which should be the value $8000F001 instead of RPC_C_AUTH_NONE (at least i think so)
    I builded a simple program to encrypt my password using CryptProtectData and entered the value using mfcmapi in PR_PROFILE_AUTH_PASSWORD as was suggested in the last page.
    but nothing seems to work, i keep getting wrong configured errors and i'm totally clueless atm. This is supposed to work right on a pc where outlook is not installed ?
    I also tried this on another pc where outlook 2010 is installed and i am able to create the profile there and connect without a problem given that i enter the logon credentials once and let them be remember (they get stored / cached in the windows key store,
    like when using CREDWRITE function) from then on i can connect without a problem.
    also when calling configuremsgservice on the EMS service i created for a new profile in mfcmapi and let the UI show i can see on the pc where outlook is installed in the UI options to enter proxy information however when i do the same thing on the pc
    where only the mapi cdo runtime is installed i do not see any UI option to configure the proxy server information ... is this normal ?
    Hopefully someone can shed some light on what i'm doing wrong or might be wrong.
    Thanks in advance
    Willems Davy

    The window would open and I would get the hourglass cursor suggesting something was happening, but the Apple home page (default from the install) would not load, nor would any other page I tried (google, yahoo, cnn).
    Even though it's about a different application, I'd try the following document with that:
    iTunes 10.5 for Windows: May see performance issues and blank iTunes Store
    (Safari uses the same webkit engine to render web pages as iTunes uses to render the Store pages. So an issue that can cause the iTunes Store to blank can also cause a Safari for Windows application on the same PC to produce blank pages.)

  • I can't open the app store, safari the mail app, youtube app and the maps app. they try to open then close very quickly. what can I do?

    I can't open the app store, safari the mail app, youtube app and the maps app. they try to open then close very quickly. what can I do?

    Try downloading another app - any free app - that seems to reset something and the apps may start working again. Try that first. If that doesnt work, try these steps
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    Close all apps. Go to the home screen first by tapping the home button. Quit/close open apps by double tapping the home button and the task bar will appear with all of you recent/open apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner to close the apps. Restart the iPad. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.

  • How do I search and work in the map module without losing my selection

    I'm going through my old photographs that predate geotracking and adding my best guess as to their locations via the  map module but I'm getting frustrated.
    My biggest angst is the selections.  In the library module, I look around and find a set of photographs that were taken at the same place and I select them.  I then go to the map module and move found, sometimes search, for the place where the photographs were taken.  Now, I go back to drop the selection into the map and ... OH NO!!! .. there is no selection.  Double angst is I click back in Library and I'm scrolled all the way to the start of my group of photographs.
    Deselecting the photos is the biggest UI mistake that Lightroom is making in this sequence.  I'm wondering if there is something that I can do to either prevent it or perhaps have a second method of a quick temporary group of photographs.
    The other related question I have is if anyone has a suggestion of how to mark these photos as the type of GPS information.  e.g. it could come from the camera, it could come via a track log, or it could be just my best guess.  Perhaps that is already possible to determine.

    When you find the photos you want that were taken in a single location, select them and put them in a Quick Collection (press B)
    Then select the Quick Collection and go to the Map Module with the filmstrip turned on. You will then be able to work ONLY with this set of photos that are taken in one location

Maybe you are looking for