Sorting Map on values rather than keys

Is it possible that I can have a Map which is sorted based on values rather than keys ?
If not is there an alternative.
Basically I have keys as strings and values as integers.
The values keep incrementing and at the end I want to get the top 50 keys based on the values.

Sorting a Map by values is not a good idea, I did something similar before, it doesn't support the design, but it is better in performance, which is implementing a custom class (name it Record) that contains two members: key and value, create a record and insert it into a SortedSet e.g. TreeSet.
make sure to do the following:
1. This custom class must implement Comparable and compares two values
2. Override euqlas method and accept strings (check using instanceof) then compare it to the key so you can retrieve the records using the key (to let it work as a map)
Now you have a sorted set with key,value pairs, use the add method to insert a new pair, use the remove to retrieve the desired object and the set is already sorted :)
Regards
Mohammed

Similar Messages

  • Change Dimension Attribute to group by name rather than key

    Hi
    I am taking over a cube which has been built for speed rather than functionality. For example if you bring one dimension in and a measure you would get a result like this.
    ? 200
    Mancheste 400
    Manchester 200
    ? 100
    Derby 5
    when really it should look like this
    ? 300
    Mancheste 600
    Derby 5
    I believe this can be changed in the dimension attributes group it on name rather than key (although you get slower performance) but I can't find where about I change this

    hi,
    If you in BIDS, select the attribute you want to change and look at properties.
    Under the properties group Source, you have the definition for KeyColumn and NameColumn.
    My understanding is that you would want a keycolumn which is on the same level as your name column.
    I e change the key column to a better one.
    (Optionally, but not as good, you could set the KeyColumn to the same column as your name column)
    best wishes /Carl
    thanks I would mark this as the answer but it won't let me for some strange reason.

  • My iPad display become white rather than keys are not working, i can not turn off .

    My iPad display become white rather than keys are not working, i can not turn off .
    version number iSO 8

    Your statement makes no sense at all. Please clarify.

  • Rendering Addnl Assign DFF displays  Context Value rather than its segments

    I am trying to personalize update appraise page to render Additional Assignments DFF but after rendering it to true..... It just displays Context Value rather than its segments........
    Oracle Guru's any suggestions?

    You need to provide the Descriptive Flexfield Segment List value in the format
    Global Data Elements|[global segment1]|[global segment2]||...||Context1|[segment1 for context1]|[segment2 for context1]||...||Context2|....
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to get the actual value rather than pixel value in vision assistant

    how to get the actual value rather than pixel value by vision assistant in my program.As shown in the figure            this is my programme   this is the result       But i want to get this result

    Check the documentation for the "ADF Dialog Framework"
    It may help
    Atilio

  • Mapping a value to a key column

    Hi,
    I need some information in understanding the 2nd point from below
    "2. UPDATE statement changes City from SF to LA on the source. This does not succeed on the
    target. The SQLEXEC query looks up the City column in TCUSTMER1 and returns a value of
    LA. Based on the COLMAP clause, the before and after versions of City both are now LA.
    This leads to SQL error 1403 when executing the target WHERE clause, because a value
    of LA does not exist for the City column in the target table."
    I am unable to follow what exactly it states.
    Can some one explain with a good example?
    Reference:
    Mapping a value to a key column
    If using COLMAP to map a value to a key column (which causes the operation to become a
    primary key update), the WHERE clause that Oracle GoldenGate uses to locate the target row
    will not use the correct before image of the key column. Instead, it will use the after image.
    This will cause errors if you are using any functions based on that key column, such as a
    SQLEXEC statement.
    The following illustrates what happens:
    This is the SQLEXEC statement in the MAP statement:
    SQLEXEC (id mytest, query "select city from TCUSTMER1 WHERE state = 'CA'",
    noparams, ERROR RAISE),
    This is the COLMAP statement in the MAP statement:
    COLMAP ( usedefaults, city = mytest.city );
    This is the sequence of events:
    1. INSERT statement inserts the following:
    INSERT into TCUSTMER1 values (Cust = ‘1234’, Name = ‘Ace’, City = ‘SF’,
    State = ‘CA);
    Commit;
    This succeeds, because the SQLEXEC query will return mytest.city = ‘SF, so the target table
    also will have a value of SF for City and CA for State.
    2. UPDATE statement changes City from SF to LA on the source. This does not succeed on the
    target. The SQLEXEC query looks up the City column in TCUSTMER1 and returns a value of
    LA. Based on the COLMAP clause, the before and after versions of City both are now LA.
    This leads to SQL error 1403 when executing the target WHERE clause, because a value
    of LA does not exist for the City column in the target table.

    user582604 wrote:
    I am unable to follow what exactly it states.Join the club. The description is admittedly a bit complicated to follow, but it's unlikely that you're actually experiencing a problem related to this.
    It's just saying (as far as i can tell) either don't do a pk (primary key) update.... or (presumably) if you must do a pk update, do not also try at the same time to map the pk column to the result of some GG function (e.g., a sqlexec). When you have a replicat map "colmap(usedefaults, pk=sqlexec.result)", then the "where" clause constructed to perform the pk update on the target DB will use the new, updated ("after") value of the pk, and not the old, original ("before") value. Therefore the row won't be found on the target, since the pk has not actually been updated yet.
    (To paraphrase, the docs could have just said: "See this? Don't do that.")

  • Display returns latest data value rather than maximum data value.

    I have requested the Maximum value using the Statistics VI.  The display returns the latest value rather than the maximum.  I think it may have to do with specifying the sample size or data packet size but I don't know how to do that.

    You probably are only taking a single reading with the DAQ Assistant and the Statistics function expects an array to determine the max value in that array. There are a couple ways to do what you want. One way is to use the Array Min & Max Single Point function (Signal Processing>Point by Point>Other Functions). This has a sample length input and a reset input. Another way is to create an array with a shift register and use the Statistics function or just the Array Min & Max function. You could limit the size of the array with Array Subset for example.
    To attach a file to your post, look below the message body. There is a Attachment field with a browse button.
    Message Edited by Dennis Knutson on 06-29-2007 09:41 AM
    Attachments:
    Max value.PNG ‏7 KB

  • OLAP query returning "name" rather than "key" attribute for a dimension

    Hello,
    I am busy with a project that involves drawing data from an OLAP cube (in SAP BW), then transforming and contextualising for use in an EMI environment. The project runs on MII 12.1.
    The standard OLAP connector and OLAP queries have been used (would prefer not to go the route of creating a call to the OLAP XMLA web service directly). One of the important dimensions is returned as a name (descriptive text) rather than a key (the cost element code itself), preventing us from reliably applying business rules to classify cost elements. Categorising cost elements based on their text descriptions is not a sustainable solution.
    The output needs to allow for two dimensions (cost element and an equipment identifier) against which individual cost values will be listed. It appears that the two dimensions must both be on the "x-axis", as result columns are automatically renamed, e.g. C000001, C000002, etc. If anyone knows of a way to suppress this renaming behaviour, please let me know.
    Is it possible to force the "key" attribute to be returned instead of the "name" attribute? I have identified two preferred options:
    1. MDX syntax of the query itself
    2. configuration of the OLAP connector
    I have not found a way to do this through MDX syntax, but would welcome any suggestions.
    Alternatively, perhaps there is a non-standard way of configuring the OLAP connector so that the key rather than the name attribute is returned for all dimensions. Has anyone anything, e.g. chosen a non-standard ColumnNameAttribute or DataTypeAttribute, in this regard?
    Thanks,
    Marc Chaplin

    <b>Apologies for the formatting above</b>
    Part 1:
    Hello,
    I am busy with a project that involves drawing data from an OLAP cube (in SAP BW), then transforming and contextualising for use in an EMI environment. The project runs on MII 12.1.
    The standard OLAP connector and OLAP queries have been used (would prefer not to go the route of creating a call to the OLAP XMLA web service directly). One of the important dimensions is returned as a name (descriptive text) rather than a key (the cost element code itself), preventing us from reliably applying business rules to classify cost elements. Categorising cost elements based on their text descriptions is not a sustainable solution.
    The output needs to allow for two dimensions (cost element and an equipment identifier) against which individual cost values will be listed. It appears that the two dimensions must both be on the <i>x-axis</i>, as result columns are automatically renamed, e.g. C000001, C000002, etc. If anyone knows of a way to suppress this renaming behaviour, please let me know.

  • Sorting map by value

    I need to sort a map by value, or just display its contents by value (in descending order). The value is an int. I'm using a treemap, but I'm guessing it's impossible to sort it by anything but the value...then again i'm not really sure.
    I've tried so many things, but I'm not experienced with maps so I'm having trouble.
    Thanks.

    Here is a class I wrote which will return a list of map.entrys in the order your comparator requires. Unfortunately, there is no way to get a Map sorted by values, only keys.
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.List;
    import java.util.Map;
    public class MapValueSorter {
         public static <K, V> List<Map.Entry<K, V>> sortValues(Map<K, V> unsorted, Comparator<V> c) {
              List<Map.Entry<K, V>> orderedList = new ArrayList<Map.Entry<K, V>>();
              Comparator<Map.Entry<K, V>> entryComparator = new MapEntryValueComparator<K, V>(c);
              for(Map.Entry<K, V> entry : unsorted.entrySet()) {
                   int insert = Collections.binarySearch(orderedList, entry, entryComparator);
                   if(insert<0)
                        insert = 1-insert;
                   orderedList.add(insert, entry);
              return orderedList;
         public static class MapEntryValueComparator<K, V> implements Comparator<Map.Entry<K, V>> {
              private Comparator<V> valueComparator = null;
              public MapEntryValueComparator(Comparator<V> c) {
                   valueComparator = c;
              public int compare(Map.Entry<K, V> entry1, Map.Entry<K, V> entry2) {
                   return valueComparator.compare(entry1.getValue(), entry2.getValue());
    }

  • Sort Map by Value

    Hello,
    I have the following map:
    Key Values
    "String1" 1
    "String2" 8
    "String3" 3
    "String4" 7
    "String5" 3
    "String6" 1
    As you can see all the KEY are unique STRINGS and the Values are non UNIQUE INTEGERS. I want to sort(descendent) this map BY VALUE.
    I have tried a lot of methods but I did not reach in a clear Result.
    Please help me by giving source code.
    I would also you to check if the following Comparator class is suitable for my problem
    class FrequencyComparator implements Comparator{
    public int compare(Object firstObject, Object secondObject){
    Map.Entry first = (Map.Entry)firstObject;
    Map.Entry second = (Map.Entry)firstObject;
    if (Integer.parseInt(first.getValue().toString()) < Integer.parseInt(second.getValue().toString()))
    return -1;
    if (Integer.parseInt(first.getValue().toString()) == Integer.parseInt(second.getValue().toString()))
    return 0;
    return 1;
    Thanks in advance

    Crossposted,
    http://forum.java.sun.com/thread.jsp?forum=31&thread=425045&tstart=0&trange=15

  • How to get the C309a to read an actual sized map on USGS rather than scale it down to one page size

    Once upon a time, long, long, ago, when DOS was king, a printer would print out multiple sheets of a screenshot, even though the screen was larger than the 8 1/2 x 10-14 paper size. So, what you got was, say, 8 sheets of paper, which you had to tape together to get the entire picture of the screen.
    I have been trying to figure out a way to print the MVUM maps from the USGS website, so we can go off-roading legally and responsibly.  To pull up one of these maps, you must click on an Acrobat formatted engine. Although you can resize the map itself to normal size, when it comes time to print, regardless of the print & printer settings, it will either print the enitre map on a single sheet of paper, or it will only print one thirtysecond of the entire map, with no option to continue printing.
    My question...is there a way to disable or enable the print mode to print the map its actual size, and not just one page of it?

    What operating system?  In Windows 7 x64 I opened this page in IE9, right clicked on the map and selected print, then selected "Tile large pages".  When I started printing it began spitting out the 24 pages properly tiled.  I only let it print the first 4 pages, but it seems to be doing the "right" thing.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • I'd like to modify how recently visited site are shown: Listed like before rather than thumbnails, and sorted by most recent rather than most frequent. Thanks.

    I did find one thread on creating a custom bookmarks folder that contains the recently visited sites sorted by recency, but I can't figure out how to create it. I'm pretty computer-savvy but the links provided don't go to a clear path on achieving what the topic is about.
    And I found nothing on changing back to the former list view that existed before the recent update that went to thumbnails. Note this is not an issue new browser windows but it is when opening a New Tab -- the new version shows thumbnails, but I'd prefer the list.
    Thanks!

    Firefox (version 13 and higher) shows thumbnails when opening a new tab. If you saw a list view at some point, then that feature was provided by an extension you've installed. Check if the extension in question has been updated for Firefox 13. Setting the new tab page to open ''about:blank'' may also restore the extension's functionality. See the following article for details:
    * [[New Tab Page – show, hide and customize top sites]]
    To create your own smart bookmark folders, you can use the following extension.
    * [https://addons.mozilla.org/firefox/addon/searchplaces/ addons.mozilla.org/firefox/addon/searchplaces/]

  • Illustrator creates individual circles for each value rather than creating one pie chart

    Illustrator makes these:
    Instead of this:
    What am I doing wrong?

    Apparently the problem is that I enterd in the data vertically instead of horizontally. So, nevermind.

  • Sorting files by file name rather than ID Tags

    Some of my files have incomplete or missing ID Tags ( a lot of mp3's from vinyl) making sorting more difficult and I typically find it more usefull to sort by file name rather than ID Tag anyway. Does anyone know how to sort by file name?

    Aloha!
    While this is not possible in iTunes right now, I might be able to help.
    It sounds like you've taken care to ensure that your music is properly labeled. That should make it easy to use a third party app to tag the lot as a batch. I am aware of one application that folks around here seem to like called "Tag & Rename" that can build a set of tags for you from folder and file names. I believe it has (or had) a free demo period as well. Try a google search or check out sites like versiontracker and you will find several apps that can do the task for you.
    Once done, iTunes will be able to handle the collection that has apparently been with you for some time. Hope this helps you decide on a course of action.

  • Which table contains collected values of metric key in EM repos?

    I've a metric group which has a metric key. When queying the collected values for the metric group, I don't see the metric key values from the result.
    select METRIC_GROUP_NAME, METRIC_COLUMN_NAME, VALUE
    from GC_METRIC_VALUES_LATEST
    where METRIC_GROUP_NAME = '<metric name>';
    Using the oracle_database [Type]/database [instance]/'Archive Area'[metric group] as example, 'Archive Area Destination' is the metric key.
    Run this query:
    select METRIC_GROUP_NAME, METRIC_COLUMN_NAME, VALUE
    from GC_METRIC_VALUES_LATEST
    where ENTITY_guid = (select target_guid from mgmt_targets where target_name ='database' and target_type='oracle_database')
    and METRIC_GROUP_NAME = 'archFull';
    result:
    archFull     archTotal     195570068
    archFull     archUsed     76805980
    archFull     archUsedPercent     42
    archFull     archAvail     118764088
    Where I can find collected values of the metric key?

    Thank you, Joseba. It does help to some extent. Now I have a non-updatable field with the climate name in it, and below that is the magnifying-glass icon that invokes the list of values. I guess that's not bad, and I can put a label next to the magnifying class saying "Click to select climate". So it's better, but still looks very odd compared to updating fields that are in the LOCATION table itself, where it's an updatable field and the maginfying glass is right next to it. Really the user should not have to behave differently just because the database chooses to hold the value that he wants to alter as a reference to another table.
    Is there at least a way to put the list of values magnifying-glass next to the field that displays teh value, rather than underneath it? They are all inside a thing called "af:panelFormLayout", and I tried setting MaxColumns to 2 in its properties, but it still won't let me move the list-of-values field alongside the other one.
    Thanks.

Maybe you are looking for

  • How can I continuously auto-save and auto-name the JPEG files with a controlled time interval

    Hi, I am newly involved in some Labview projects that out of my knowledge. I am trying to save multiple JPEG images from a live imaging task to a folder in the computer hard disk every certain minutes. I'd like to name these files with the date and t

  • Having trouble with one cash receipt...

    Hello, thanks for reading this.  I have a report that displays cash receipts for the day, using 3 different tables.  This report breaks down the daily receipts by payment method - cash, check, credit card, eft.   I recently added a field that would d

  • Connect iPad2 to Video Camera

    I've search on Google, but have yet to find anything that gives me the answer I'm looking for... What I'm wanting: I have a Canon Vixia HG20 video camera that I want to use for recording to it's HD, but I want to also connect my iPad2 to is as well s

  • Problems with replying to messages 6210 navigator

    I have the 6210 navigator and when I reply to messages that are in my inbox and then press send (no i do not save them I send them)  They - at random - go into my drafts box. Its very frustrating as I think I have replied to my messages and then figu

  • Having trouble with content-aware

    I am trying to use content-aware, but am having trouble finding out how to do it, even though I have watched the videos. When I outline the object that I want to remove and go to Edit>Content-aware, I can't find out how to finish the procedure. Also,