Ordering certain keys in TreeMap / comparator question

I have a TreeMap of currencies. Keys are ("USD", "EUR"...) and each value holds some collection.
I want to sort the TreeMap so that "GBP", "USD", "CAD" and "EUR" are the first 4 keys in the map and other currencies are in their natural order following these 4 keys. I don't know which currency I'll be getting from a certain operation so it could be that "USD" is encountered last which means it will be the last key in my TreeMap.
How would I do this using the Comparator and compareTo method?
Any help would be greatly appreciated.
Cheers
Norm.

Your Comparator's compare() method could have to have a lot of hard-coding in it. Like this:public int compare(Object a, Object b) {
  Thing at = (Thing) a;
  Thing bt = (Thing) b;
  String acurr = a.getCurrency();
  String bcurr = b.getCurrency();
  if (acurr.equals(bcurr)) return 0; // return 0 for equals
  if (acurr.equals("GBP")) return -1; // GBP before everything
  if (bcurr.equals("GBP")) return 1; // GBP before everything
  if (acurr.equals("USD")) return -1; // USD before the rest
  if (bcurr.equals("USD")) return 1; // USD before the rest
  // and so on
}

Similar Messages

  • Planning book values for certain key figures show doubled up numbers

    currently on SCM 7.0, we are facing a strange intermittent issue of doubled up values in planning book for certain key figures when compared to the underlying Infocube.
    This happens when the Input process step happens, some times when the process step fails in chain and is run again.
    After its run then we load data to the planning book , then when the key figures show up for the current week bucket they show Doubled up values
    We tried to run a consistency check /SAPAPO/OM17 (DP time series option) but no result.
    Can anyone mention what could be the reason ?

    Hi,
    Please check the data in the cube for the codes . There could be double request for the same keyfigure. When you copy from cube whatever value avilable in the cube gets into Planning book.
    Transaction : LISTCUBE
    Solution : Delete the old request and check the value agina in cube. Execute the TSCUBE.
    Thanks,
    Jeysraj

  • TreeMap -  Comparator how to get it to work

    Hi All,
    I am a newbie java programmer. Ik trying to understand de TreeMap en Compator and objects. I got some questions maybe that someone could help me.
    I have a class Customer:
    import java.util.TreeMap;
    import java.util.Set;
    import java.util.Iterator;
    import java.util.Collection;
    import java.util.Map;
    public class Customer
         private TreeMap customertable = new TreeMap();
         public void put(Object key, String value)
              // Record subscriber
              customertable.put(key,value);
         public Abonnee get(String key) // Abonnee in english means subscriber
              return (Abonnee)customertable.get(key);
         public void remove(String key)
              customertable.remove(key);
    and a comparator class like:
    import java.util.*;
    class Vergelijk implements Comparator
         public int compare(Object obj1, Object obj2)
         String str = (String)obj1;
         return str.compareTo((String)obj2);
    public boolean equal(Object obj)
         return obj == this;
    How do i get the Customer class working with the Vergelijk class (comparator) which statements do i have to add and in which class?
    My program can add a object but when i add a second object i get a errors like:
    java.lang.ClassCastException: Abonnee
    at java.util.TreeMap.compare(TreeMap.java:1081)
    at java.util.TreeMap.put(TreeMap.java:459)
    at Klanten.put(Klanten.java:33)
    at GuiVb.toeVoegen(GuiVb.java:84)
    at GuiVb.actionPerformed(GuiVb.java:152)
    at java.awt.Button.processActionEvent(Button.java:381)
    at java.awt.Button.processEvent(Button.java:350)
    at java.awt.Component.dispatchEventImpl(Component.java:3598)
    at java.awt.Component.dispatchEvent(Component.java:3439)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:197)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    hope get some good hints.

    Maestro, you may want to change you the put method in the Klanten class to public void put(String key, value)
        klantentabel.put(key, value);
    }and then replace any occurances of
    klant.put(p, p.getNaam());with
    klant.put(p.getNaam(), p);Why?
    Quote from http://java.sun.com/j2se/1.4.1/docs/api/java/util/TreeMap.html
    "This class guarantees that the map will be in ascending key order, ..."
    So, if use Strings as keys, you don't need to write your own comparator, since Strings are already comparable.
    You did use your Abonne object as key and its name as value when putting data into the map, but on retrieval and deletion you did use Abonne's name as key => obviously can't work (i.e. no matching entry will ever be found).
    If you do not understand the concepts of Maps, refer to
    http://java.sun.com/j2se/1.4.1/docs/api/java/util/Map.html

  • UID key in TreeMap causing ClassCastException

    Hello all,
    I'm trying to use the UID class as a key in a TreeMap, but I'm running into a ClassCastException when I try to lookup using a UID as a key. From the docs, I see that a ClassCastException is thrown when the "key cannot be compared with the keys currently in the map." My guess is that the key needs to implement the comparable interface but I can't find mention of it anywhere in the docs. (other than the 'compared with keys' statement) ... So, two questions:
    1) Can someone verify my suspicions about comparable interface?
    2) Is there a better solution that implementing my own 'comparable subclass of UID? (I don't mind subclassing, but I'm loath to write/maintain/test/document a custom solution if I can use a built in class)
         protected void testTreemapUID() {
              TreeMap tree = new TreeMap();
              Double testDouble = new Double(23);
              tree.put( testDouble, new String("frank"));
              String result = (String)tree.get(testDouble);
              System.out.println("about to get value from Double " );
              System.out.println("Double result = " + result );
              tree = new TreeMap();
              UID uid = new UID();
              tree.put(uid, new String("bob"));
              System.out.println("about to get value from UID " );
              result = (String)tree.get( uid );
              System.out.println("UID result = " + result );
         }console output:
    about to get value from Double
    Double result = frank
    about to get value from UID
    Exception in thread "main" java.lang.ClassCastException: java.rmi.server.UID
         at java.util.TreeMap.compare(TreeMap.java:1093)
         at java.util.TreeMap.getEntry(TreeMap.java:347)
         at java.util.TreeMap.get(TreeMap.java:265)
         at SandBoxTester.testTreemapUID(SandBoxTester.java:70)
         at SandBoxTester.<init>(SandBoxTester.java:53)
         at SandBoxTester.main(SandBoxTester.java:100)
    as always, many thanks!
    Message was edited by:
    oldmicah

    Because you are using a TreeMap, which is a sorted map, the keys must be mutually comparable.
    java.rmi.server.UID doesn't implement Comparable. That's why the ClassCastException is thrown.
    If you need a sorted map, then you will have to provide a Comparator*.
    If you don't care about sorting, you could use a HashMap instead.

  • Occasionally when filling in forms in Safari 5.1.2 certain keys on the keyboard don"t work.  When I use the coma it opens up another tab.

    Occasionally when filling in forms in Safari 5.1.2 certain keys on the keyboard don"t work.  When I use the coma it opens up another tab. I've used other browsers to fill in the forms and they work fine so my keyboard is OK.

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It won’t solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of this exercise is to determine whether the problem is localized to your user account, or is system-wide. Enable guest logins and log in as Guest. For instructions, launch the System Preferences application, select “Help” from the menu bar, and enter “Set up a guest account” (without the quotes) in the search box.
    While logged in as Guest, you won’t have access to any of your personal files or settings. Any application you run will behave as if you were running it for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    As Guest, launch the application(s) and test. Same problem(s)?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.

  • When I turn on my MacBook pro, I get the 'macintosh he's symbol. Then, at my login, certain keys (I,e,u) get an error sound, and I can't log in. Anyone know what's up?

    Oh, I'm on my phone because if the problem, so I put the whole question in the title. But, the  problem is that my computer acts like I've got the alt key down   I start up, and gives me an error sound when I hit certain keys (e i, u, and a few othes) so I can't log in. Help?

    You showed a kernel panic file from OS X, apprantly Log Me In is installed into OS X or running when you log in.
    You should be using the developers installer/unistaller to remove Log Me In from OS X.
    Somehow it's in OS X, I don't know, but it's there and you need to remove it. I'm not dealing with Windows, just OS X.
    Talk to Log Me In people and find out what is installed where so you can do a manual deletion out of OS X.
    If that doesn't work, you have to reboot holding the Shift key down manually search for any Log Me In or Himachi files on your computer, in your System/Library/Extensions folder too, use the free Easy Find.
    https://s3.amazonaws.com/DTWebsiteSupport/download/freeware/easyfind/4.9/EasyFin d.app.zip

  • Liquid spill on keyboard. Certain keys not working. Any inexpensive repair? re

    Water spill on the keyboard of my Mac Book Air. Now certain keys not functioning. A Mac friend suggested submerging in rice upside down to dry out. Didn't work. Warranty expired. Help!

    Yes, the "magic rice trick" doesnt work.
    inexpensive repair? No.
    Liquid spills, why your MacBook chassis is a one-way valve for spills
    After a substantial spill many people will turn their notebook upside down and shake it, not only does this not work, but it spreads liquid havoc throughout your machine and makes things often as bad as possible.
    The keyboard itself acts like a one way valve in the case of a substantial liquid spill. While liquid pours into the bottom chassis easy, it does not come out easily at all, and in the case of any spill, most of it will not come out by turning it upside down. Disconnect all power and contact Apple for diagnostics and repair.
    Do not attempt to, after a spill, ‘dry out your MacBook’ and test it
    After a spill most people invariably try to “dry out” their notebook by various methods, including hair dryers and otherwise. This both does not work, and after a substantial spill of any magnitude, even if the liquid was water, residue is left behind.
    There are additionally many very tight places inside your notebook where liquids will linger for a very long time, and cause corrosion or worse.
    Immediately unplug your notebook and contact Apple for in shop diagnostics and parts replacement.
    In the case of very minor spills people will “dry out” their notebook and feel success that their notebook is working ok, however invariably in nearly all instances after 4-14 days an error / fault pops up and is usually followed by more.
    In case of a spill, damage estimates are impossible,.....anything can be fixed, without question.......the question is cost.
    contact Apple for in shop diagnostics and cost estimation ....possible parts replacement.  

  • [SL410:2842RK1] Certain keys work only when pressure is applied

    Certain keys on my laptop has started to fail. It started with the F2 key,then the F5 and now the backspace key. They work when they are pushed down hard. Do i need to change my keyboard.
    Solved!
    Go to Solution.

    Welcome to the Forum!
    First thing I would do is give the keyboard a thorough cleaning. This may help to relieve the "sticky" keys. Use a 50/50 mix of rubbing alcohol and water and follow the Keyboard cleaning instructions here: http://blog.lenovo.com/design/keeping-your-thinkpad-clean
    There is a method for changing out individual keys. However, it can be slightly tricky (if it's your first time) and might not be worth the hassle. Plus, this may not resolve the issue. Ordering a genuine Lenovo new or used and properly tested keyboard is probably your best bet. The cost to replace the entire keyboard (from your location) may not be much more than ordering and fiddling with 3 different keys. You may use the part numbers in this document to assist your search: Keyboard service parts - ThinkPad L410, L510, SL410, SL510
    Here is a useful guide for removing and replacing your keyboard: Keyboard removal and installation - ThinkPad L410, L412, L510, L512, SL410, SL510. And here is your Hardware Maintenance Manual.
    Have a great day. (I do not work for Lenovo)

  • Change order of key figure is not working in Web report output (using WAD)

    Hi,
    We are using BI 7.0, release 701 and level 008. We are facing problem in WAD (web report output). When ever we do 'Select filter' for key figures and 'change the order' of key figures, it does not get reflected in new order. Though drag and drop of key figures is working.
    Though same change order is working fine in Bex Analyser.
    Kindly suggest some inputs.
    Thanks.

    Hi,
    On Which Service Pack are you on?WAD has this feature of re arranging the keyfigures in BI 7.0 for SPS 14...
    Regards,
    Bhagyarekha.

  • Yoga 3 Pro - Certain Keys Missing from Keyboard. How to virtually use them?

    Hi.
    I have bought this for about a week and was not happy about the combination of "Home" and "End" keys since I use them a lot. In using VMWare I noticed there is no "Insert" key on the keyboard at all, thus I cannot use the Ctrl+Alt+Insert functionality in my virtual machines. Today, a random combination of keys was pressed on the keyboard and the "Scroll Lock" was enabled, and guess what: There is no scroll lock in the Yoga 3 Pro! Now I have no idea how to disable this again and non of the forums or manuals have addressed this.
    (Lenovo design team has made is specifically hard for users. Not only the keyboard layout and certain keys are removed, but even I cannot find a spare chargin cable for my officec. They have changed everything - even Yoga 2 Pro charging cable is not compatible - and yet not available in the market. Not a very smart strategy )
    Solved!
    Go to Solution.

    Welcome to the forum!
    I'm sorry to hear about your problem. I had to really take a look at my own Y3P to realize there is no Insert key, I guess I got too used to the touchscreen 
    To get rid of the Scroll Lock you can press the combination Fn+C.
    Alternatively you can also go to the Control Panel, then "Easy of Access Center" and start the On-Screen Keyboard, you can disable the Scroll lock from there too.
    /L40SX/240/240X/2*340CSE/360PE/365XD/380D/380E/380XD/380Z/390/560E/560X/2*570/2*600/600E/750Cs/755C/760CD/760EL/760XD/770E/A20p/A22p
    A31/i1600/G40/R50p/R61i/S30/SL510/2*T22/4*T4x/11*T6x/6*T4x0x/6*T5x0/3*W5x0/W700/3*X2x/4*X3x/3*X4x/5*X6x/3*X6xT/10*X2xx/2*X200T/4*X30x/Z60m/3*Z61x
    Comunidad en Español  English Community  Deutsche Community   Русскоязычное Сообщество

  • Change Order of key figures

    Hi Gurus,
    We are using BI 7.0. & MS excel 2003 & 2007 both.
    I've designed a query with 10 Key figures.
    After execution, based on Key figures I have Added Local Formula in query.
    Now I want to change the order of Key Figures and bring Newly added Local Formula column at 3rd position.
    I've tried using Select Filter... and changed the order of column as I want, but this doesn't work.
    I can drag the column & drop it at desired position. It's working that way in office 2003.
    But in office 2007, Drag and Drop not working at all. Even for characteristics also.
    Is this problem with BEx Excel Patch? I've installed excel patch for both 2003 & 2007. But still not working properly.
    Please suggest. If you know latest patch available for office 2003 & 2007, please suggest.
    Thanks.

    HI,
    I am on BI7, Excel 2007
    Drag and Drop Functionality for both Char & KF is working fine including the placement of Local Formula.
    seems you need to check with the Basis Team for proper installation of the BEx Excel patch
    Regards
    ReddY A

  • Macbook Pro keyboard typing in random letters and symbols with certain keys

    My mother is not a very tech savvy person. We recently upgraded her Windows PC to a Macbook Pro. A few days ago she went to some website about working from home. I'm pretty sure it was a scam website. Anyway after that the keyboard started acting weird.
    Certain keys will either not work or just type random keystrokes. The keys that I know of are
    7= 123477
    U= IOTUYw
    J= adfgjs
    M= Will sometimes minimize the active window and other times will type out random symbols (æ∆¬)
    :; key= 0 - Esc, and changes the volume
    ' key= Tab, random symbols, enables caps lock
    Eject Key= § changes volume
    I had Sophos Anti Virus installed on it, and after running a full scan it didn't come up with anything. To be safe i decided to completely wipe her Macbook. I also did the 7-pass DOD Standard erase.
    After that i resinstalled Lion on her computer. After restarting the same issue persists. I tried seeing if there was an OSX update that needed to be installed, and that didnt fix anything. I also ran the Apple hardware test. It came up with no issues.
    I also checked to see if foriegn keyboards were turned on, etc.
    I have no idea what to do now. Using my bluetooth keyboard works fine. The keys type what they should. She says he hasn't spilt anything on it, but she works as a daycare provider and sometimes the little kids watch movies or youtube videos on it.
    Any help would be appreciated!

    I just spent hour trying to fix tihs on my iMac and could find the answer so I wanted to post it for someone else. Mine was typing in crazy symbols (åß∂ƒ©).
    Also I could not Command + Tab (shoot me), and when I clicked on a window in another app it hid the windows I was working in.
    I tried new keyboards. And the system preferences stuff - system preferences - language & text - input sources. then select US. This didn't fix it.
    Then I tried to change the keyboard shortcuts in the same window - spotlight (on left), unclick the show spotlight search field and the other one bellow. Then hit the com + Spacebar. This didn't fix it.
    Then i did it and double check that i did it right and still didn't fix it.
    So I called apple support and they gave me the magical key to fix this.
    Turn off your computer. Unplug for 30 sec, and everything attached. Then power it back on and hurry and hold Command + Option + P + R. I held Command + Option + P with one hand and then after I hit power I added the R.
    The computer will make one chime. Keep holding it. I will then shut down and make one more chime and you can let go.
    Taa daa!!
    I have a 27" iMac 2.93Ghz i7 with 10.8.2 (FYI).

  • Acct determination for Account-assigned purchase order with keys not define

    Hi,
    I'm trying to post an IDOC of type BBPIV through XI to an R/3 system.
    The posted idoc in R/3 is in status 51 (Application document not posted) with the error message "Acct determination for Account-assigned purchase order with keys not defined in chart of acts WP2P"
    As per my understanding this is something related to FI.
    Long text of the error is "The system cannot generate an automatic posting because there is no account determination defined for Account-assigned purchase order with keys   in chart of accounts WP2P.
    Correct the account determination for Account-assigned purchase order"
    Please help me how to solve this.
    Regards,
    Rashmi

    Hiya,
    This looks like its a MM posting / transaction.
    You need to go to OBYC and maintain the account assignment. If you provide the business scenario (GR into Stock, Subcontracting, etc.) for the process, I may be able to help.
    VKOA is for SD account assignment and I don't believe you can use that here.
    Cheers.

  • Certain keys on my keyboard no longer work as intended

    All of a sudden my keyboard isnt working as it used to.  Certain keys dont work.  I attempted to trouble shoot, but I also had trouble with the steps listed.  I didnt have the places that it said to go to in my system preferences.  I dont have universal access or speech.  I dont understand what happened.  Its only certain keys.  For example, if I hit the apostrophe/quotation marks key I get and  : or * 
    I restarted and made sure that my USB connection was good.  I dont know what to do and its making me crazy!!  HELP please!

    One or more keys on the keyboard do not respond
    If keys on your keyboard don’t work

  • Can Captivate be set to advance when only a certain key is pressed

    I am doing software training simulation.  I am trying to teach the user how to do a set of tasks.  In the software you must press certain key to accomplish certain steps so  I want to set captivate to advance to the next slide only when the correct key is pressed such as the delete key. I am fairly new with captivate. Is this possible? Will I need an advanced action to do this?  Thanks

    Each interactive object, like a Click box, can be assigned a shortcut key. If you are capturing the software training simulation (Automatic), those click boxes are created for you. In the Properties panel of the Click box you can assign the shortcut key. Normally you do not need an advanced action for that. And be sure to give Infinite Attempts if the user can only proceed when that shortcut key is pressed (but avoid frustration, maybe with the Hint caption?)
    Lilybiri

Maybe you are looking for