Hashmap and array list problems

This is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go from here. Any guidance would be very welcomed.
We were given code that used just an Array lisThis is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go next. Any guidance would be very welcomed.
We were given code and told to "Modify the MailServer so that it uses a HashMap to store MailItems. The keys to the HashMap should be the names of the recipients, and each value should be an ArrayList containing all the MailItems stored for that recipient. " Originally it was just an ArrayList named messages. There is also a MailClient and MailItem class.
I think I can post the messages using the HashMap now, but can't test it. I get a compiler error saying else without if even though I have an if statement. Even if I can compile, I need to make sure I am on the right track with the getNextMailItem method. It is the one I am stuck on and if I can get it to work, I can probably modify the other methods.
I would really appreciate feedback on that one method.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class MailServer
     // Storage for the arbitrary number of messages to be stored
     // on the server.
     private HashMap messages;
     private ArrayList list;
     private MailItem item;
      * Construct a mail server.
     public MailServer()
         messages = new HashMap();
         list = new ArrayList();
      * Return the next message for who. Return null if there
      * are none.
      * @param who The user requesting their next message.
     public MailItem getNextMailItem(String who)
          Iterator it = list.iterator();
          while(it.hasNext())
            MailItem item = (MailItem)it.next();
            if(messages.containsKey(who));
                return item;
           else
               return null;
      * Add the given message to the message list.
      * @param item The mail item to be stored on the server.
     public void post(String name, MailItem item)
         if(messages.containsKey(name))
                list = (ArrayList) messages.get(name);
                else {
                    list = new ArrayList();
                    list.add(item);
                    messages.put(name, list);
}[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

The way I understand this is that MailItems are stored in per user ArrayLists, and that the ArrayLists are stored in the HashMap, and use the username as a key,
HashMap messages = new HashMap();
//ArrayList userMailItems = new ArrayList(); this should not be declared here, only the messages mapso given a User name, you need to get the list of mail items for that user out of the hashMap, and then return the next MailItem from the list. So given that, you don't even need to Iterate over the list:
public MailItem getNextMailItem(String who)
ArrayList list = (ArrayList)messages.get(who);
if(list == null || list.size() == 0)
return null;
//now we get the next item from the list, we can call remove, since it returns the object we are removing.
MailItem item = (MailItem)list.remove(0);
return item;
}

Similar Messages

  • HashMaps and Arrays

    I am extracting data from MYSQL in a result set. The values are then stored in HashMap. The total count of rows would be around 650 - 700 approx. I get a Array out of Bound exception.
    (Note: I have a HashMap array- HashMap hm[] = new HashMap[800]; )
    Any one to comment on this. If you need any more information.. let me know...
    -Krish

    PMJain wrote:
    Why do you allocate a HashMap[]?
    you would need a single instance of HashMap to be populated with some key/value pairs
    where key might be your primary key and the value could be the object with the data from a single record.My guess is that Cubby was turning each result set row into a Map that mapped the column name to the row's value. Meh.

  • 5800 homescreen problem and ringtone list problem.

    i am facing two problems:
    1.Usually when the music player is running you can see the song name and duration on the homescreen. This has disappeared for me. Calendar entries dont show as well. I use handy shell whose task manager i used to kill the homescreen accidentally. I tried restarting the phone and restoring the factory settings. Kindly help.
    2.In my gallery and in my ringtone list there is this one track which appears 96 times! i deleted the track but the entry wont go away. how the hell do i get rid of it??!!
    thank you.

     use option #3, its not usually what it is meant for but if you cant remove a file then that might be a way to go. also did you try to remove it from your memory card via card reader in your computer and see if this helps any ? the option #3 will erase everything off your phone so make sure that you do have a back up. also i think that you store your stuff on the memory card so try this first and see if it works for you. 
    1. *#7780# - Restore factory settings - resets all the settings to the default ( you will not lose any data)
    Make sure you back up your data as you will lose all of it when you perform option 2 or 3 on this list. The default code for all operations listed here is 12345
    2. *#7370# - Reformat your phone
    3. This you perform as a last resort. Nothing else is working.If the phone is not showing any activity, proceed with hard formatting , turn off your phone, hold the following buttons while pressing the power button. (the default code is 12345)
    hard reset - hold the following buttons *, 3 (number button) and talk/green key. turn on the phone and do not release those buttons until you see the Nokia boot up screen. once you feel the phone power up you can let go off the power button while still holding all three buttons ( for Nokia 5800XM - use the following buttons to do a hard reset, GREEN/RED/CAMERA keys pressed all at once on power up. this will only work on 5800's that have firmware version 20... and up. )
    If these codes are not working the only thing for you to do is contact your Nokia Care Center/Service for assistance.
    You know what I love about you the most, the fact that you are not me ! In love with technology and all that it can offer. Join me in discovery....

  • Bookmarks and reading list problems

    Since the iOS7 upgrade, I've been unable to save bookmarks or add to the reading list.  The problem seems localized to my iPad, as Safari functions normally on other devices.  Suggestions for a fix would be appreciated.

    If you see a black bar at the top, Private Browsing is enabled. You have to turn it off.
    http://i1224.photobucket.com/albums/ee374/Diavonex/7bda479db053922760cb4c8e68f86 480_zps14016317.jpg

  • Adding two array lists together and a text file to an array list

    I'm having problems coding these two methods... Could someone explain how to do this? I can't find information on it anywhere... :(
    "MagazineList" is the class I'm coding in right now, and I already declared "list" as an array list of another class called "Magazine".
    public boolean addAll(MagazineList magazines)
           if (list == magazines) {
               return false;
            else {
                list.addAll(magazines);
           return true;
       public boolean addAll(String filename)
           Scanner in = ResourceUtil.openFileScanner(filename);
            if (in == null) {
               return false;
            String line = source.nextLine();
            while (!line.equals("")) {
              list.add(Magazine(source));
           in.close();
       }

    I assume "addAll(MagazineList magazines)" is defined in the MagazineList class?
    Then,
    list.addAll(magazines);probably needs to be something like:
    list.addAll(magazines.list);This uses the private variable ( should be private) list from the input MagazineList, and adds all of those Magazine objects to the list in the current MagazineList.
    But, yes, describe your problems more clearly, and you'll get better answers more quickly (because people will be able to understand you and give you a suggestion without asking you another question first).

  • How to get keep one column as a key and the other columns as a array list

    Hello,
    I am really new to Java...I am trying to read a text file containing different columns separated by comma and then create a hash map for the first column (key) and then rest as a array list for the key.I am not able to create the hash map and the corresponding key.Could someone help me in this regard.
    The text document is :
    AcctNo,AcctMngr,AcctType,ProdList,Volume,AcctPrice,Returns
    12345,Vikram,2,MSFS:IBM:XYZ:MAN,28000,4500,1.25
    53278,Anand,1,PLYS:AIX:YET:WON,85000,8500,2.32
    94005,Vincent,3,UTIL:FLY:YEL:WIN,67000,5600,3.21
    45000,Abhishek,2,WENS:KYL:MEN:ABS,34000,9800,4.21
    76000,Chris,3,MENS:IBM:ROC:QUE,25000,2500,2.15
    67000,Kiran,4,FORS:ITI:MOC:REM,32000,3500,1.54
    87000,Rohit,2,MSNF:IIT:HOT:ROC,54000,5400,4,23
    45600,Sathyan,3,HELP:FOR:PRO:GRA,65000,3400,2,1.98
    84600,Vinay,4,PLZE:TES:ROC:WEN,76000,7300,3,4.32
    65000,Venkat,2,HETT:WEL:SEE:RED,89000,9800,1,3.23
    and the code which i have so far is
    import java.io.*;
    import java.util.*;
    class SearchHash {
    public static void main (String args[]) {
    int i=0;
    int j=0;
    Object newKey = new Object();
    Object newValue = new Object();
    Map map1 = new HashMap();
    ArrayList a1 = new ArrayList();
    String val;
    try {
    BufferedReader br1 = new BufferedReader ( new FileReader ( new File ("progress.txt")));
    String s="";
    s = br1.readLine();
    while (s!=null) {
    StringTokenizer st = new StringTokenizer (s ,",");
    int k=0;
    while (st.hasMoreTokens()) {
    while (k<=6) {
    val= st.nextToken();
    if (k==0) {
    newKey = val;
    else{
    newValue = val;
    a1.add(newValue);
    k = k+ 1;
    map1.put(newKey,a1);
    map1.put(newKey,a1);
    a1.clear();
    s = br1.readLine();
    // System.out.println(map1);
    }catch (Exception e) {
    System.out.println("Exception Raised : " + e);
    Thanks.,...

    Array? Don't live in object denial. Define a class (Account?) and parse each line as an Account object. Then you put them into a Map<Integer, Account> by their account number.

  • How to find and display the posistion in an array list

    hi all,
    i know this is proballly simple but i have an arraylist where every time someone connects to my system it adds them to an arraylist, how can i post back somelike like hi user "1" thanks for connecting and so on. i just dont understand how to find their unique posistion in the array list and display it as a number.
    any help would be great

    So to be clear...
    You have an arraylist of connections .... for example
    ArrayList<ConnectedPeople> connPplArr = new ArrayList();And then each time someone connects you would add a connected people object to the arraylist.
    ConnectedPeople, migh contain username etc etc.
    You could then do:
    ConnectedPeople newConnection..... ;
    int index = connPplArr.indexOf( newConnection );
    if(int == -1){
        add them to your array
        index = connPplArr.size();
    return "Hello user "+ index;That what you mean?
    I know some of it is sudo code, but have I understood your problem?
    Edited by: Azzer_Mac on Apr 29, 2008 2:20 AM
    Edited by: Azzer_Mac on Apr 29, 2008 2:20 AM

  • Problem passing multiple array lists to a single method

    Hi, all:
    I have written a generic averaging method that takes an array list full of doubles, adds them all up, divides by the size of the array list, and spits out a double variable. I want to pass it several array lists from another method, and I can't quite figure out how to do it. Here's the averager method:
         public double averagerMethod (ArrayList <Double> arrayList) {
              ArrayList <Double> x = new ArrayList <Double> (arrayList); //the array list of integers being fed into this method.
              double total = 0;//the total of the integers in that array list.
              for (int i = 0; i < x.size(); i++) {//for every element in the array list,
                   double addition = x.get(i);//get each element,
                   total = total + addition; //add it to the total,
              double arrayListSize = x.size();//get the total number of elements in that array list,
              double average = total/arrayListSize;//divide the sum of the elements by the number of elements,
              return average;//return the average.
         }And here's the method that sends several array lists to that method:
         public boolean sameParameterSweep (ArrayList <Double> arrayList) {
              sameParameterSweep = false;//automatically sets the boolean to false.
              arrayList = new ArrayList <Double> (checker);//instantiate an array list that's the same as checker.
              double same = arrayList.get(2); //gets the third value from the array list and casts it to double.
              if (same == before) {//if the third value is the same as the previous row's third value,
                   processARowIntoArrayLists(checker);//send this row to the parseAParameterSweep method.
                   sameParameterSweep = true;//set the parameter sweep to true.
              if (same != before) {//if the third value is NOT the same,
                   averagerMethod(totalTicks);//go average the values in the array lists that have been stored.
                   averagerMethod(totalNumGreens);
                   averagerMethod(totalNumMagentas);
                   sameParameterSweep = false;
              before = same; //problematic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         return sameParameterSweep;
         }Obviously, the problem is that I'm not passing the array lists from this method to the averager method the right way. What am I doing wrong?

    Encephalopathic wrote:
    There are several issues that I see, but the main one is that you are calculating average results but then just discarding them. You never assign the result to a variable.
    In other words you're doing this:
    averagerMethod(myArrayList);  // this discards the resultinstead of this:
    someDoubleVariable = averagerMethod(myArrayList); // this stores the resultAlso, do you wish to check for zero-sized array lists before calculating? And what would you return if the array list size were zero?So in solving that problem, I've come up with another one that I can't figure out, and I can't fix this problem until I fix that.
    I have several thousand lines of data. They consist of parameter sweeps of given variables. What I'm trying to do is to store pieces of
    data in array lists until the next parameter adjustment happens. When that parameter adjustment happens, I want to take the arraylists
    I've been storing data in, do my averaging thing, and clear the arraylists for the next set of runs under a given parameter set.
    Here's the issue: I'm having the devil of a time telling my application that a given parameter run is over. Imagine me doing stuff to several variables (number of solders, number of greens, number of magentas) and getting columns of output. My data will hold constant the number of soldiers, and for, say, ten runs at 100 soldiers, I'll get varying numbers of greens and magentas at the end of each of those ten runs. When I switch to 150 soldiers to generate data for ten more runs, and so forth, I need to average the number of greens and magentas at the end of the previous set of ten runs. My problem is that I can't figure out how to tell my app that a given parameter run is over.
    I have it set up so that I take my data file of, say, ten thousand lines, and read each line into a scanner to do stuff with. I need to check a given line's third value, and compare it to the previous line's third value (that's the number of soldiers). If this line has a third value that is the same as the previous line's third value, send this line to the other methods that break it up and store it. If this line has a third value that is NOT the same as the previous line's third value, go calculate the averages, clear those array lists, and begin a new chunk of data by sending this line to the other methods that break it up and store it.
    This is not as trivial a problem as it would seem at first: I can't figure out how to check the previous line's third value. I've written a lot of torturous code, but I just deleted it because I kept getting myself in deeper and deeper with added methods. How can I check the previous value of an array list that's NOT the one I'm fiddling with right now? Here's the method I use to create the array lists of lines of doubles:
         public void parseMyFileLineByLine() {
              totalNumGreens = new ArrayList <Double>();//the total number of greens for a given parameter sweep
              totalNumMagentas = new ArrayList <Double>();//the total number of magentas for a given parameter sweep.
              totalTicks = new ArrayList <Double>();//the total number of ticks it took to settle for a given parameter sweep.
              for (int i = 8; i < rowStorer.size() - 2; i++) {//for each line,
                   checker = new ArrayList <Double>();//instantiates an array list to store each piece in that row.
                   String nextLine = rowStorer.get(i); //instantiate a string that contains all the information in that line.
                   try {
                        Scanner rowScanner = new Scanner (nextLine); //instantiates a scanner for the row under analysis.
                        rowScanner.useDelimiter(",\\s*");//that scanner can use whitespace or commas as the delimiter between information.
                        while (rowScanner.hasNext()) {//while there's still information in that scanner,
                             String piece = rowScanner.next(); //gets each piece of information from the row scanner.
                             double x = Double.valueOf(piece);//casts that stringed piece to a double.
                             checker.add(x);//adds those doubles to the array list checker.
                   catch (NoSuchElementException nsee) {
                        nsee.printStackTrace();
                   //System.out.println("checker contains: " + checker);
                   processARowIntoArrayLists(checker);//sends checker to the method that splits it up into its columns.
         }

  • All the xml and arrays are getting NULL Problem

    Hello guys
    I am working on a project which uses xml loading, e4x and array manipulation extensively, and it was going good but now I got stuck on a strange problem.  Whole code was fine and application was working and responding in a desired way, but then mystourisly it stopped working and started to retun NULL values to almost all the actionscript (internal) Arrays and XML varibales.
    Now Whenever i load xml file and assign the loaded values to internal xml variables, internal values get only NULL instead of data.
    Same is the situation with Arrays, I created some components in mxml, and when i passed them to arrays by reference, code gets compiled successfully, but again Array has only null values [that code was working fine too]
    I am wondering if Adobe Flex did a silenced update or something similar and it is the result of that things !
    I am using Adobe Flex 3.2 with SDK 3.3 on windows Vista Ultimate.
    Please check this attached project, Import it and see if you face the same problem
    Thanks
    Link to Problem Project
    http://isolatedperson.googlepages.com/problemXperiment.zip
    Problem Screenshot
    http://isolatedperson.googlepages.com/xmlissue.JPG

    Use HTTPService to load the data. You'll have fewer problems.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application creationComplete="dataSvc.send();"
      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
         <mx:Script>
              <![CDATA[
                import mx.collections.XMLListCollection;
                import mx.rpc.events.ResultEvent;
                [Bindable] private var xlc:XMLListCollection;
                   private function loadXML(evt:ResultEvent):void{
                    xlc =  new XMLListCollection(evt.result.individual.@id as XMLList);
              ]]>
         </mx:Script>
         <mx:HTTPService resultFormat="e4x" result="loadXML(event)" url="alirazaTree.xml" id="dataSvc"/>
         <mx:ComboBox id="cbx" dataProvider="{xlc}"/>
    </mx:Application>

  • Accessing Array and Iterating Array list - Need Oracle Pro Assistance

    Hi,
    This is the third time i am posting the question, :( .
    I want some advice on how to iterate through a Array list which has an array of tasks/processes and make calls to the corresponding subprocess for each element in the list.
    We are looking for a BPMN approach.
    Any example or ideas would be of great help.
    My requirement states that i will get a list of tasks from a Rules Engine and i have to use BPM to iterate through the tasks and make calls to each tasks(which is a subprocess call).
    In Oracle BPM 11g I would like to use a multi-instance subprocess to send a task to a user for each item in an array. There are an unknown number of rows in the array. Does anyone have a good example of how to do this?
    I am using BPM Oracle 11g but any help 10 will also help us.
    I am reposting again this question , hoping that someone will help us
    Thanks
    Edited by: user9083699 on Aug 28, 2010 4:03 AM

    I am not the expert on 11g, however, in 10g, if I understand correctly... it sounds like you should be able to use PAPI to notify instances/sub processes, etc....
    With a list of Instances, you can search for that instance and notify it...
    If you have a list of processes, that need to be started, you can create an instance within that process....
    user9083699 wrote:
    My requirement states that i will get a list of tasks from a Rules Engine and i have to use BPM to iterate through the tasks and make calls to each tasks(which is a subprocess call).If you are just trying to initiate a sub-process, (btw, why would they have to be subprocesses?), It sounds like you should be able to create a global in the process, and just call it with PAPI...
    I'm still a little fuzzy, on how this business requirement turned up... however, maybe this helps a little?
    -Kevin

  • Accessing Array and Iterating Array list

    Hi,
    I want some advice on how to iterate through a Array list which has an array of tasks/processes and make calls to the corresponding subprocess for each element in the list using BPM 11g
    We are looking for a BPMN approach.
    Any example or ideas would be of great help.
    My requirement states that i will get a list of tasks from a Rules Engine and i have to use BPM to iterate through the tasks and make calls to each tasks(which is a subprocess call).
    In Oracle BPM 11g I would like to use a multi-instance subprocess to send a task to a user for each item in an array. There are an unknown number of rows in the array. Does anyone have a good example of how to do this?
    I am using BPM Oracle 11g but any help 10 will also help us.
    I am reposting again this question , hoping that someone will help us
    Thanks

    Others probably are getting it, but I'm not really sure what it is that you're tyring to do with the list of instances.
    I'm getting lost in two areas. First, you mentioned you have a rules engine returning a list of instances. Mostly out of curiosity - why do you have an array of instances being created by a rules engine? What is the use case? Asking because I'm sure to learn something new from you on this - I'm used to seeing a lot of things coming back from an invoked rule, but never an array of instances before.
    Second (sure you know this), in both 10g and 11g there is a Split-N activity that you can use to parse (as the name implies) "N" number of instances. This "N" is discoverable at runtime. If you have 14 instances in your array at runtime, it would go into a Split-N activity and 14 instances would automatically be spawned. The 14 instances would flow from the Split-N to its corresponding Join activity in the process.
    Dan

  • How to read XI Data type in Java code and populate as array list, using UDF

    Hi,
    How to read XI Data type in Java code and populate as array list, using UDF?
    Is there any API using which  the XI data types can be read?
    Kindly reply.
    Richa

    Input Structure:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:CustomerCreateResp xmlns:ns0="urn:bp:xi:up:re:cust_mdm:cmdm:pr5:100">
       <CUSTOMER>
          <item>
             <CUSTOMERNO/>
             <MDMCUSTOMER/>
             <CREATE_DATE/>
             <RETURN>
                <TYPE/>
                <MESSAGE/>
             </RETURN>
             <PT_CONTPART_RETURN>
                <item>
                   <MDM_CONTACT/>
                   <CONTACT/>
                </item>
             </PT_CONTPART_RETURN>
             <PARTNERS>
                <item>
                   <CUSTOMERNO/>
                   <PARTNER_FUNCTION/>
                   <PARTNER_NUMBER/>
                   <DEFAULT_PARTNER/>
                </item>
             </PARTNERS>
          </item>
       </CUSTOMER>
    </ns0:CustomerCreateResp>
    Output structure
    (Sample output structure.This actually needs to be mapped and generated using UDF)
    <?xml version="1.0" encoding="UTF-8"?>
    <ns1:updateCustomer xmlns:ns1="urn:xiSericeVi"><ns1:customer><ns2:ArrayList xmlns:ns2="java:sap/standard">[]</ns2:ArrayList></ns1:customer><ns1:name>2344566</ns1:name></ns1:updateCustomer>

  • Sort array list and using comparable

    With the following code I would like to setup a score object for the current player.
    Change it to a string(Is it correct to say parse it to a string type)
    Then add it to the arraylist.
    So I can sort the array list according to the string size.
    That's why I have the variables in that order.
    So if 3 players have the same amount of guesses, they can be positioned on the high score list according to their gameTime.
    //create score object
                   Score currentScore = new Score(guessCount, gameTime, name);
                   String currentScoreToString = currentScore.toString();
                   //add score to arrayList
                   scores.add(currentScoreToString);So the error message says " The method add(Score) in the type arrayList <Score> is not applicable for the arguments(string)"
    Now, I understand that, I would like to know if there is another way to achieve what I am trying to do.
    Is the string idea I am trying here possible? is it practical or should I use comparable?
    I have looked at comparable, but I don't get it.
    Will my Score class implement comparable. I am looking at an example with the following code.
    Employee.java
    public class Employee implements Comparable {
        int EmpID;
        String Ename;
        double Sal;
        static int i;
        public Employee() {
            EmpID = i++;
            Ename = "dont know";
            Sal = 0.0;
        public Employee(String ename, double sal) {
            EmpID = i++;
            Ename = ename;
            Sal = sal;
        public String toString() {
            return "EmpID " + EmpID + "\n" + "Ename " + Ename + "\n" + "Sal" + Sal;
        public int compareTo(Object o1) {
            if (this.Sal == ((Employee) o1).Sal)
                return 0;
            else if ((this.Sal) > ((Employee) o1).Sal)
                return 1;
            else
                return -1;
    ComparableDemo.java
    import java.util.*;
    public class ComparableDemo{
        public static void main(String[] args) {
            List ts1 = new ArrayList();
            ts1.add(new Employee ("Tom",40000.00));
            ts1.add(new Employee ("Harry",20000.00));
            ts1.add(new Employee ("Maggie",50000.00));
            ts1.add(new Employee ("Chris",70000.00));
            Collections.sort(ts1);
            Iterator itr = ts1.iterator();
            while(itr.hasNext()){
                Object element = itr.next();
                System.out.println(element + "\n");
    }The thing I don't understand is why it returns 0, 1 or -1(does it have to do with the positioning according to the object is being compared with?)
    What if I only use currentScore in a loop which loops every time the player restarts?
    //create score object
                   Score currentScore = new Score(guessCount, gameTime, name);
                   String currentScoreToString = currentScore.toString();
                   //add score to arrayList
                   scores.add(currentScoreToString);Also why there is a method compareTo, and where is it used?
    Thanks in advance.
    Edited by: Implode on Oct 7, 2009 9:27 AM
    Edited by: Implode on Oct 7, 2009 9:28 AM

    jverd wrote:
    Implode wrote:
    I have to hand in an assignment by Friday, and all I have to do still is write a method to sort the array list. Okay, if you have to write your own sort method, then the links I provided may not be that useful. They show you how to use the sort methods provided by the core API. You COULD still implement Comparable or Comparator. It would just be your sort routine calling it rather than the built-in ones.
    You have two main tasks: 1) Write a method that determines which of a pair of items is "less than" the other, and 2) Figure out a procedure for sorting a list of items.
    The basic idea is this: When you sort, you compare pairs of items, and swap them if they're out of order. The two main parts of sorting are: 1) The rules for determining which item is "less than" another and 2) Determining which pairs of items to compare. When you implement Comparable or create a Comparator, you're doing #1--defining the rules for what makes one object of your class "less than" another. Collections.sort() and other methods in the core API will call your compare() or compareTo() method on pairs of objects to produce a sorted list.
    For instance, if you have a PersonName class that consists of firstName and lastName, then your rules might be, "Compare last names. If they're different, then whichever lastName is less indicates which PersonName object is less. If they're the same, then compare firstNames." This is exactly what we do in many real-life situations. And of course the "compare lastName" and "compare firstName" steps have their own rules, which are implemented by String's compareTo method, and which basically say, "compare char by char until there's a difference or one string runs out of chars."
    Completely independent of the rules for comparing two items is the algorithm for which items get compared and possibly swapped. So, if you have 10 Whatsits (W1 through W10) in a row, and you're asked to sort them, you might do something like this:
    Compare the current W1 to each of W2 through W10 (call the current one being compared Wn). If any of them are less than W1, swap that Wn with W1 and continue on, comparing the new W1 to W(n+1) (that is, swap them, and then compare the new first item to the next one after where you just swapped.)
    Once we reach the end of the list, the item in position 1 is the "smallest".
    Now repeat the process, comparing W2 to W3 through W10, then W3 to W4 through W10, etc. After N steps, the first N positions have the correct Whatsit.
    Do you see how the comparison rules are totally independent of the algorithm we use to determine which items to compare? You can define one set of comparison rules ("which item is less?") for Whatsits, another for Strings, another for Integers, and use the same sorting algorithm on any of those types of items, as long as you use the appropriate comparison rules.Thanks ;)
    massive help
    I understand that now, but I am clueless on how to implement it.
    Edited by: Implode on Oct 7, 2009 10:56 AM

  • Accessing Array and Iterating Array list - call corresponding subprocess

    Hi,
    I want some advice on how to iterate through a Array list which has an array of tasks/processes and make calls to the corresponding subprocess for each element in the list.
    Any example or ideas would be of great help.
    My requirement states that i will get a list of tasks from a Rules Engine and i have to use BPM to iterate through the tasks and make calls to each tasks(which is a subprocess call).
    Thanks

    Are you using Oracle BPM 10 or are you using 11?
    Dan

  • List and justified text problems

    I'm creating a PDF that uses justified text for all paragraphs and centered headers. One of the problems I'm having is that if the last sentance in a paragraph contains just a few words, it ends up far to spaced out. It ends up looking rediculous, in extreme cases there is a word against the left margine and one against the right margin. How do I limit the space allowed between words?
    Second, how do I creat a numbered list without it indenting the left margin of the paragraph that comes after each number? I need the number to be indented, just as you would indent the first sentance of a paragraph, but the rest of the justified text needs to have the same left margin as the non-numbered paragraphs.
    Third, how do I keep the space between the number and the text the same with justified text? As it is now, it changes to acount for the number of charicters in the line of text. I aso need to keep the distance for number to left margin the same, I'm just pressing the tab button twice right now. I'm not using the list function right now because of the margine issues, I'm just including the number in the text.

    1. To prevent the last line of text from spacing out, make sure you use a hard return at the end of the last sentence in the paragraph. That marks it as the end of a paragraph, and Buzzword won't try to justify the last line of what it recognizes as a paragraph.
    2. You can use the ruler to adjust the indents and margins for paragraphs. For more details, open up the Help documentation, click on Buzzword tips (it's under Using Buzzword on the left), then click on Editing, then select the first item -- How do I create indents. It's a little tricky, but I think that you'll find that it provides the control you're looking for. Note that when you're adjusting the formatting of list paragraphs, all paragraphs in that list that are at the same list level will have the same paragraph formatting.
    3. I think that if you use the paragraph formatting (via the ruler, as noted in #2) and the list functionality, the problem of the inter-character spacing will go away.
    Hope this is helpful!

Maybe you are looking for