General Comparator help?

I'm creating an "OrderedList<E>" (class name) which is like an arraylist but inside has an array of Objects to add, remove, get, etc. from and I would like to know if there is a link to a general comparator i could look at? because I can't really get the list in order without making my own general comparator for the general OrderedList. Thanks =].

Not sure what you mean by "general comparator," but maybe these will help:
[http://www.onjava.com/lpt/a/3286]
[http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html]
[http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-sort.html]

Similar Messages

  • Using Comparator-Help

    Hi,
    Below is my code.It compare values and print the results.When i input five values,out of which two are same(ABCD) .So the output i get is:
    ABCD:1234.0
    ABCDE:1234.0
    NJKIOP:1234.0
    WASD:1234.0
    But i want all the five values i want results to be like this:
    ABCD:1234.0
    ABCD:1234.0
    ABCDE:1234.0
    NJKIOP:1234.0
    WASD:1234.0
    So what change should i make in my code .Please help
    import java.util.*;
    class TComp implements Comparator
    public int compare(Object a,Object b)
    int i,j,k;
    String aStr,bStr;
    aStr=(String)a;
    bStr=(String)b;
    return aStr.compareTo(bStr);
    class Ordering1
    public static void main(String a[])
    TreeMap tm=new TreeMap(new TComp());
    tm.put("ABCD",new Double(1234));
    tm.put("ABCDE",new Double(1234));
    tm.put("ABCD",new Double(1234));
    tm.put("WASD",new Double(1234));
    tm.put("NJKIOP",new Double(1234));
    Set set=tm.entrySet();
    Iterator itr=set.iterator();
    while(itr.hasNext())
    Map.Entry me=(Map.Entry)itr.next();
    System.out.println(me.getKey()+":"+me.getValue());
    Thanks in advance for any help.
    Vineet

    A tree does only hold unique values.A Map holds unique key values only. You cannot store many "ABCD" keys in a TreaMap or HashMap.
    What you'll can do is to store a list of items for a specific key using for example a LinkedList to handle collisions. What you get is a HashMap with two type of items. On item is a plain String, and the other is a LinkedList of Strings.

  • Chapter end action triggers General Error - Help please!

    Hi, I am working on a project and have come to a big problem in the last hurdle, classic! Really need your help, experts!
    I have 2 Timelines, each one with 6 audio tracks and 2 subtitle tracks
    One of the timelines is longer than the other one because it has two different films in it.
    Everything was working fine until I realised I had forgotten to set the end action to the last chapter of the first video in the timeline, I need it to either stop or return to main menu or last menu, otherwise it will go on to play the second film and i don't want this to happen.
    When I set the end action to the chapter 10, it looks fine, I check and no problems.
    But when it starts transcoding... after a bit, when it has transcoded all the languages it goes to prepare to build and I get GENERAL ERROR and it freezes.
    Please please please if somebody can help me it would be very much appreciated.
    Mariana
    ps I have no overrides or anything like that in the whole project

    Please list the Assets on each of the two Timelines with full detail. A screen-cap of each would probably be very useful and save you some typing.
    Some things to also think about is are there any spots where your Audio is longer (even very slightly) than the accompanying Video? Are there any gaps on any of the Timelines? When you added that "End Action," exactly how/where did you add it? Also, if you have any Chapter Playlists, or Playlists, please give details on those.
    Note: to attach the screen-caps, us the little "camera" icon on the editing screen:
    Good luck,
    Hunt

  • Airport General Config Help Required

    I've got a wireless Thomson broadband router hooked up downstairs running DHCP server, and upstairs I've got an airport extreme configured in bridge mode. I've got a MAC Mini directly ethernet cabled to the AE.
    I can connect to the internet from the Mac, but cannot see a couple of ethernet devices connected to the remaining two AE ethernet ports (Windows Home Server and Buffalo Linkstation).
    I can change the config so that the AE acts as the DHCP server, am then able to use WHS and the Linkstation, but not internet.
    Can anyone give me any pointers as to how to configure it up (if at all possible). Does the AE need to be hard wired to the router?
    Thanks

    Hello Sai Narayana,
    Our client wants to implement whole travel management in ESS, I am new to SAP travel management, Could you please help me in starting the configuration of create travel request, which node the master cost center is configured. I looked under financial accounting->travel management->Travel Planning and Travel Expenses but couldnt figure out where the travel request will be configured. We are using ECC 6.0. Your help is very much appreciated as I am doing configuration alone i dont have any other help.
    I have question regading Travel Planning if we want to implement travel planning do we have to use AMADEUS or can we integrate the clients present used travel link to R/3 using RFCs.
    Regards,
    Latha

  • Comparable help

    Hi
    I am trying to get rid of an "unchecked" warning, but I guess I have problems understanding how generics work.
    I have an enum defined in the following way:
    public enum Domain {
         INT(Number.class) {
              public Integer parse(Token token) {
                   return Integer.decode(token.getValue());
         KEY(String.class) {
              public String parse(Token token) {
                   return token.getValue();
         TEXT(String.class)  {
              public String parse(Token token) {
                   return token.getValue();
         OCTET(String.class)  {
              public String parse(Token token) {
                   return token.getValue();
         OCTETS(String.class)  {
              public String parse(Token token) {
                   return token.getValue();
         DATE(java.sql.Timestamp.class) {
              public java.util.Date parse(Token token) {
                   return new Timestamp(Long.parseLong(token.getValue()) * 1000);
         INT8(Number.class) {
              public Short parse(Token token) {
                   return Short.decode(token.getValue());
         INT64(Number.class) {
              public Long parse(Token token) {
                   return Long.decode(token.getValue());
         final Class sqlType;
         Domain(Class sqlType) {
              this.sqlType = sqlType;
         public Class getSqlType() {
              return sqlType;
         abstract public Comparable<? extends Comparable<?>> parse(Token token);
    }When I want to use it, I get the value using
    Comparable<Object> value = domain.parse(token)which gives me the unchecked error. Later I want to compare to values:
    value1.compareTo(value2)Any declaration of "value" other than Comparable<Object> fails to compile the compareTo() call.
    Any ideas how I need to declare "value" ?

    Here's a version that compiles warning-free and allows you to compare arbitrary Domain instances mutually.
    The catch: you can't leverage the added typesafety that the covariant return type provided. OTOH, this would only kick in if you used one of the enum constants directly. I guess you can't have it both ways...
    public enum Domain {
         INT(Number.class) {
              public Comparable<Object> parse(Token token) {
                   return wrap(Integer.decode(token.getValue()), Integer.class);
         KEY(String.class) {
              public Comparable<Object> parse(Token token) {
                   return wrap(token.getValue(), String.class);
         final Class sqlType;
         Domain(Class sqlType) {
              this.sqlType = sqlType;
         public Class getSqlType() {
              return sqlType;
         abstract public Comparable<Object> parse(Token token);
         static <T extends Comparable<T>> Comparable<Object> wrap(final T value, final Class<T> cl) {
              return new Comparable<Object>() {
                   public int compareTo(Object o) {
                        return value.compareTo(cl.cast(o));
    }

  • General sql help

    hi,
    i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like:
    Table1:
    (id, name, street, city, zip, phone, fax, etc...) about 20 more columns
    Table2:
    name
    what i need help with is that table2 contains about 200 distinct names that i need to insert into table1, i'm using sql server, is there a way to insert them into table1?? i'm not sure how to write a query within the insert statment to get them inserted into table1? something like:
    insert into table(id, name, street, zip, phone, fax, ...) values(newid(), (select distinct name from table2), null, null, null....)
    and is there a way to do it without all the nulls having to be put in, there are about 20 more columns in table1, and id in table1 is unique. i know this doens't have much to do with java but the project does involve jdbc, just wasn't sure how to do this query.

    You've got the right idea, but I believe the number of columns you INSERT has to match the number selected. So your query would have to look like:
    INSERT INTO TABLE2(NAME)
    SELECT DISTINCT NAME FROM TABLE1;MOD

  • Hi guys Im using 4.3.2 version and want to upgrade to 5.1.1.So Im not getting any update when i turned on the wifiand i dont have option like "update software" in the settings general ,plz help me out by showing path when i connected to wifi

    do the needful

    Hi mendel tanx for ur quick reply and I'm not founding the settings>general>"software update" option in my IOS 4.3.2...so do I have a option of downloading or updating from WIFI or I have to download from Itunes only,if I am downloading from itunes i need to download full IOS which is 783mb large..do the needful

  • I have no software updates in general settings, help ?

    For some reason my ipod does not have the software update's option in general settings, any idea's on what i can do or is their a different way to update it. its the old ipod 8gb and i would like to know how to update the IOS because its on a really old version.

    1st generation ipod touch can only go to 3.1
    2nd gen can go to 4.2.1
    3rd and 4th gen can go to 5.1.1
    What do you have?
    Read this link:
    Identifying iPod models

  • SQL Exception: General Error - Help Needed

    Hi,
    I am getting an error at QuerySales.executeUpdate() statement in the following code.
    I never had this kind of problem with other examples using executeUpdate statement. I even checked with "addBatch" but got the same error. Please help me if you know anything.
    Thanks,
    Ravi
    PreparedStatement QuerySales;
    insertString= "insert into TestNoName values (?, ?)";
    String query2 = "SELECT Number, Name FROM TestNoName";
    Statement stmt;
    try {
    con = DriverManager.getConnection(url,"","");
    System.out.println("Successfully Connected to Database");
    stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    QuerySales = con.prepareStatement(insertString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet rs2 = stmt.executeQuery(query2);
    for (int i=0; i<=10; i++)
    rs2.last();
    int count = rs2.getRow();
    System.out.println(count);
    if (count == 0)
    lNumber = 1;
    else {
    lNumber = rs2.getInt("Number");
    lNumber++;
    QuerySales.setInt(1,lNumber);
    QuerySales.setString(2,"Ravi");
    QuerySales.executeUpdate();
    System.out.println("Hi");
    System.out.println("Exececuted SQL Statement- Inserted One Record");
    System.out.println("Fields of TestNoName");
    int count1=0;
    ResultSet rs3 = stmt.executeQuery(query2);
    //rs2.beforeFirst();
    while (rs3.next()) {
    count1++;
    int n = rs3.getInt("Number");
    String Name1 = rs3.getString("Name");
    System.out.println(n + " " + Name1);
    System.out.println(count1);
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    }

    I found the reason for error. I declared the result set object within the for loop. Now it is working fine.
    Ravi

  • General diagnostics help - things are crashing!

    I just got Logic Studio and it's big program with lots of parts to it and before I install it I wanted to make sure things are cool with my iMac. It's been crashing a fair amount recently. I called Apple and the girl (really nice) in the general section said it's probably good to take the imac to an apple store or apple authorized tecnhnician (and she gave me several in the area) and have them give it a once over. Then I spoke with a guy in the pro apps department (nasty and bored) who said the thing to do is:
    1) Try running disk utility from a system bootup disk (Leopard, wchih I have around here somewhere)
    2) Do an Archive and Install from the Leopard Disk (and then get all the updates etc). which will just replace the system, not anything else.
    3) Do an erase and install from the Leopard disk, which will mean having to reinstall any third party apps.
    Whadaya think?

    My system currently is Leopard, 10.5.8. Can I do any/all of these processes (1,2 and 3) with a Snow Leopard disk? Or should it be the same system I currently have?

  • General OCCI help

    Okey this is something I am unable to find. Perhaps someone could help me out....
    I have AIX 5.1 and Oracle 9.2.0
    I need to write a C++ program that access the database on this program. What do I need ????
    What compiler, what filesets and so on. Where can I find this information??
    Thank you,
    Baldur

    Okey now I got VisualAge C++ 6.0
    Could you perhaps tell me how a normal VisualAge compile command looks like ???
    I can't find an executeable file in the directory...

  • General design help for a basic web app with DB

    I'm fairly new to Java EE development (lots of years of Java SE experience). In the not-so-distant future I'm going to be tasked with writing a web access feature for a database-backed catalog-like application. The application helps biologist keep track of all the dead animals they have in their research collections. It is meant to be a full-featured desktop application with the ability to setup a web portal to allow other researchers to search the contents of a collection (to see if there are specimens that they would like to see or borrow, etc). So, I have to write a bunch of servlets, JSPs, JSF pages, or something like that to provide a search page and a number of results views including tables, forms, maps, etc. Our desktop app uses Hibernate for ORM.
    From what I've seen of the framework, I would really like to use JSF to do the views and navigation. Can I use JSF with Hibernate persistence? My Hibernate mappings are in *.hbm.xml files. How can I meld these technologies together. Better yet, can this be done using the Visual Web Developer pack for Netbeans 5.5?

    web app or desktop app? pick oneOur main product is a desktop app. However, we also ship with the feature to install a webapp that allows searching the collections via a web browser.
    with the ability to
    setup a web portal to allow other researchers to
    search the contents of a collection (to see ifthere
    are specimens that they would like to see orborrow,
    etc). you don't HAVE to have a portal for that you know...I realize that I could pull this off even with a few CGIs written in perl, but I want to make something that would later be expandable into a full-featured web app, allowing for data entry as well as searching.
    It sounds to me like a very simply web app and you
    are going way overboard. You don't need much code,
    much less a bunch of extra frameworks, API's, etc.
    I'd make a few servlets/jsp's and avoid getting into
    JSF, hibernate, etc. unless you know they are worth
    your time.I'm planning on using Hibernate because all of the Hibernate data classes and bindings are already setup. I guess in the initial version that doesn't do anything but view the data, I could avoid Hibernate since I don't need any ability to detect user changes to objects and commit those back to the DB.
    I'd really like to write the web app using the Java EE 5 persistance API (JPA) and not have any Hibernate-specific code in the mix.
    One requirement I forgot to mention was the need for a login page that can allow for access above the standard, anonymous guest level. Some information that these guys collect, such as where they located a rare plant variety, is highly sensative (since pharma companies have been known to want this information). For that reason, some of the info is not made available to anonymous web access users. Users with a registered account can get at more info.

  • General Scripting Help

    I am having some problems with getting a script to end before the next one starts. I tried using 'do shell script' but couldn't get the 'su' and 'sudo -s' commands to work properly.
    I am pretty new to applescripts and any help would be great. Thanks
    Applescript #1 - It works, but only if the delays are long enough for things to finish. Sometimes it takes longer, sometimes it's ok.
    set pass to ""
    tell application "Terminal"
    activate
    display dialog "Please enter your password. Everything else is automated. Please do not press anything beyond this password and the final \"Success\" window." default answer pass buttons {"OK"} default button 1
    set pass to text returned of the result
    do script "su \"USER NAME\"" in front window
    delay 2
    do script pass in front window
    delay 2
    do script "sudo -s" in front window
    delay 2
    do script pass in front window
    delay 2
    do shell script "date '+%Y.%m.%d'"
    set datelist to result
    time of (current date)
    set timelist to result
    do script "cd /System/Library" in front window
    delay 2
    do script "tar cfz UserTemplateBackup" & datelist & timelist & ".tar.gz \"User Template\"" in front window
    delay 8
    do script "cd /Users/Guest" in front window
    delay 2
    do script "cp .DS_Store \"/System/Library/User Template/English.lproj/.DS_Store\"" in front window
    delay 2
    do script "rm -R \"/System/Library/User Template/English.lproj/Library/\"" in front window
    delay 2
    do script "cp -R Library/ \"/System/Library/User Template/English.lproj/Library\"/" in front window
    delay 2
    do script "rm -R \"/System/Library/User Template/English.lproj/Desktop\"/" in front window
    delay 2
    do script "cp -R Desktop/ \"/System/Library/User Template/English.lproj/Desktop\"/" in front window
    delay 2
    do script "rm -R \"/System/Library/User Template/English.lproj/Documents\"/" in front window
    delay 2
    do script "cp -R Documents/ \"/System/Library/User Template/English.lproj/Documents\"/" in front window
    display dialog "SUCCESS!!! (I think)" buttons {"OK"} default button 1
    quit
    end tell
    Applescript #2 - This one doesn't work, it returns errors at several steps.
    display dialog "Are you sure that you want to save the Guest User Settings? Everything else is automated. Please do not press anything until the final \"Success\" window." buttons {"OK"} default button 1
    do shell script "su" with administrator privileges
    do shell script "sudo -s" with administrator privileges
    do shell script "date '+%Y.%m.%d'"
    set datelist to result
    time of (current date)
    set timelist to result
    do shell script "cd /System/Library"
    do shell script "tar cfz UserTemplateBackup" & datelist & timelist & ".tar.gz \"User Template\""
    do shell script "cd /Users/Guest"
    do shell script "cp .DS_Store \"/System/Library/User Template/English.lproj/.DS_Store\""
    do shell script "rm -R \"/System/Library/User Template/English.lproj/Library/\""
    do shell script "cp -R Library/ \"/System/Library/User Template/English.lproj/Library\"/"
    do shell script "rm -R \"/System/Library/User Template/English.lproj/Desktop\"/"
    do shell script "cp -R Desktop/ \"/System/Library/User Template/English.lproj/Desktop\"/"
    do shell script "rm -R \"/System/Library/User Template/English.lproj/Documents\"/"
    do shell script "cp -R Documents/ \"/System/Library/User Template/English.lproj/Documents\"/"
    display dialog "SUCCESS!!! (I think)" buttons {"OK"} default button 1
    Thanks

    nevermind, I had deleted some folders when I was testing my last scripts and didn't replace them. I made new folders and it all works now.
    Thanks so much for your help. This saved me hours of work.
    I have also removed the initial dialogue asking for a password since it asks for the admin name and password anyways.
    So for anyone who wants to know, here is the final script. It seems to work just fine.
    display dialog "This will save the current settings for the Guest account as the default settings. >Things like open windows, saved passwords, website history, resolutions, items in the documents >folder etc. are all saved.
    It will ask for an administrator name and password. After inputing that, please wait until the final >\"Success\" window." default button 1 with hidden answer
    set datelist to do shell script "date '+%Y.%m.%d'"
    set timelist to time of (current date)
    do shell script "cd /System/Library/;
    tar cfz UserTemplateBackup" & datelist & timelist & ".tar.gz 'User Template';
    cd /Users/Guest/;
    cp .DS_Store '/System/Library/User Template/English.lproj/.DS_Store';
    rm -R '/System/Library/User Template/English.lproj/Library/';
    vcp -R Library/ '/System/Library/User Template/English.lproj/Library/';
    rm -R '/System/Library/User Template/English.lproj/Desktop/';
    cp -R Desktop/ '/System/Library/User Template/English.lproj/Desktop/';
    rm -R '/System/Library/User Template/English.lproj/Documents/';
    cp -R Documents/ '/System/Library/User Template/English.lproj/Documents/'" with administrator privileges
    display dialog "SUCCESS" buttons {"OK"} default button 1

  • HT3819 Hello, I just bought a new computer with windows8.  I am trying to tranfer my plylist in Itunes to the new computer after reading teh support info.  I still don't see the playlist as well as many songs in general.  help!!

    Hello, I just bougth a new computer with windows 8 on it.  i am trying to transfer my itunes playlist to the new computer.  I used a transfer cable with a disc "easy transfer cable by Belkin" but not all the songs or playlist were transfrerred.  what am I doing wrong.  Help!  The old computer has windows XP

    From your OLD computer...
    Copy your ENTIRE iTunes FOLDER to an External Drive... and then from the External Drive to your New Computer..
    Full Details Here  >  http://support.apple.com/kb/HT1751
    Also see this migrate iTunes library post by turingtest2

  • Comparing, help please

    I have a program that is supposed to compare an array of 3 characters and determine if that set of characters is good or bad, a good set being a char of R and Y and the third char not being B, but i cant figure it out, seems to not like me. could i get some pointers on what i did wrong?
    char[] toxic;
              boolean doorIsToxic = false;
              for(int i=0;i<door;i++){
                   toxic = new char[3];
                   for(int c=0;c<3;c++){
                        if(rightDoor[2] == 'B')
                             toxic[2] = 'B';
                        else
                             toxic[2] = 'N';
                        if(rightDoor[i][2] == 'R')
                             toxic[2] = 'R';
                        else
                             toxic[2] = 'N';
                        if(rightDoor[i][2] == 'Y')
                             toxic[2] = 'Y';
                        else
                             toxic[2] = 'N';
                        if(rightDoor[i][1] == 'R')
                             toxic[1] = 'R';
                        else
                             toxic[2] = 'N';
                        if(rightDoor[i][1] == 'Y')
                             toxic[1] = 'Y';
                        else
                             toxic[2] = 'N';
                        if(rightDoor[i][0] == 'R')
                             toxic[0] = 'R';
                        else
                             toxic[2] = 'N';
                        if(rightDoor[i][0] == 'Y')
                             toxic[0] = 'Y';
                        else
                             toxic[2] = 'N';
                   if(toxic[2] == 'B')
                        doorIsToxic = false;
                   else{
                        doorIsToxic = false;
                        if(toxic[2] == 'R' && toxic[1] == 'Y')
                             doorIsToxic = true;
                        if(toxic[2] == 'Y' && toxic[1] == 'R')
                             doorIsToxic = true;
                        if(toxic[2] == 'R' && toxic[0] == 'Y')
                             doorIsToxic = true;
                        if(toxic[2] == 'Y' && toxic[0] == 'R')
                             doorIsToxic = true;
                        if(toxic[1] == 'R' && toxic[2] == 'Y')
                             doorIsToxic = true;
                        if(toxic[1] == 'Y' && toxic[2] == 'R')
                             doorIsToxic = true;
                        if(toxic[1] == 'R' && toxic[0] == 'Y')
                             doorIsToxic = true;
                        if(toxic[1] == 'Y' && toxic[0] == 'R')
                             doorIsToxic = true;
                        if(toxic[0] == 'R' && toxic[2] == 'Y')
                             doorIsToxic = true;
                        if(toxic[0] == 'Y' && toxic[2] == 'R')
                             doorIsToxic = true;
                        if(toxic[0] == 'R' && toxic[1] == 'Y')
                             doorIsToxic = true;
                        if(toxic[0] == 'Y' && toxic[1] == 'R')
                             doorIsToxic = true;
                   if(doorIsToxic == true){
                        System.out.println("Door "+i+" is Toxic: "+toxic[0]+toxic[1]+toxic[2]);

    I think this is the logic to code.
    1. If array[2] is 'B' then the result is false.
    2. Otherwise, loop through the array. Use variables to track whether any of the characters are R and whether any of them are Y.
    3. When the loop is complete, if both variables indicate that at least one R and at least one Y was found, then the result is true. Otherwise the result is false.

Maybe you are looking for