Sort function issue...

     public void sortDate() {
          ArrayList<Round> temp = new ArrayList<Round>();
          ArrayList<Round> list = new ArrayList<Round>();
//rounds is and arrayList defined in the class
          rounds.trimToSize();
          temp = rounds;
          int oldestIndex = 0, oldestRound = rounds.get(0).getDate();
          // Sort date from oldest to newest based on yymmdd format
          for (int i = 0; i < temp.size(); i++) {
               oldestIndex = temp.get(0).getDate();
               for (int j = 0; j < temp.size(); j++) {
                    if (temp.get(j).getDate() < oldestRound) {
                         oldestRound = temp.get(j).getDate();
                         oldestIndex = j;
               // Add oldest in the pass to list
               list.add(temp.get(oldestIndex));
               temp.remove(oldestIndex);
          // After all passes to sort dates list is set to this.round
          this.rounds = list;
     }What is wrong with this sort function?

wiebs2334 wrote:
          for (int i = 0; i < temp.size(); i++) {
               temp.remove(oldestIndex);
          }You are iterating over the temp arraylist from 0-temp.size(), during that time you are removing elements. This is most likely the cause of your index out of bounds exception.
A solution is to use an iterator and the corresponding remove methods.
Mel

Similar Messages

  • How does the SORT function in ALV grid work?

    Hi,
    I have a report for which the o/p is displayed in ALV grid format.There is one column in the O/p strcuture which is "No of days".Based on certain conditions,i need to display the value for some of the days as Negative e.g. " - 45".Becasuse of this,I have declared the field for the "No of days" of the type "CHAR".
    Now when i sort(using ALV grid SORT function) the list on basis of this column,it doesnt give me the correct o/p.
    CAN anyone tell me how do i handle this?I want the list to be sorted correctly on basis of the "No of days" column.
    Thanks!

    This is your Fourth Cross Posting in last three days on same issue!!
    CHAR type column doesnt work for SORT function in ALV grid!
    How to sort a column of type CHAR
    I dont,ve link for your Fourth Thread on same,though i'm short memory loss.

  • How to remove the sort function on the drill down and then save

    how to remove the sort function on the drill down and then save in the  change local view of the Query
    Is it possible to change the porperties of any characteristic in the local view and then save?
    If so please post the answer.

    I do not think that option is possible.
    Regards,
    Venkata Boga.

  • Sort functionality in Data Grid

    Hi Gurus,
    I am new to this DataGrid control.I want to establish the sort functionality when clicking on the headercolumns as in matrices.
    (ie.When double clicking the header column , sort the data in ascending or descending order of that column) like in system form matrices.
    How ever this is not possible when I tried with grid control.
    The problem I am facing is that I cannot get the column headers of the grid programmatically.(in duble click event or itempressed event)
    Anybody did this one previously? Also how
    we can change the column order of the grid using screen painter?
    The columns that actually come visible in the grid  are actually columns of the linked datatable object.
    In the designer ,there is no "swap" button for column re-ordering.
    Only one way I know is changing the query associated with datatable.
    This is a crucial thing ,since client may ask for re-ordering of columns frequently.
    Can anybody help?
    Regards,
    Deepesh

    Hi Deepesh,
    1. This functionality is not available with the SDK. Thus it's not possible to change it on the fly. Your only option is to change the query associated with datatable (as you mentioned). You may set up a user preference table, that the user can configure with its preference. That's the best you can do.
    2. To swap the columns in screen painter you must use SBO 2005 (it's not available on previous release). What you must do is, click on the one column you want to swap and the other you want to swap and click on the swap button (on the left bottom of the page in the columns tab)

  • Javascript sort() function not working correctly

    I have an image gallery that automatically loads via a PHP readdir function which populates an array, and then I have a Javascript sort() function which sorts the images in order numerically. In Chrome and Safari, the images display as numbered in the directory. However, in Firefox and Internet Explorer, they display out of order (firefox) and not at all (ie). Here is the code for the php file: <?
    Header("content-type: application/x-javascript");
    function returnimages($dirname=".") {
    $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
    $files = array();
    $curimage=0;
    if($handle = opendir($dirname)) {
    while(false !== ($file = readdir($handle))){
    $file = basename($file,".jpg");
    echo 'myImg['.$curimage.']="'.$file .'";';
    $curimage++;
    closedir($handle);
    return($files);
    echo 'var myImg=new Array();';
    returnimages()
    ?>
    and here is the code for the javascript sort:
    function sortNumber(a,b)
    return a - b;
    myImg.sort(sortNumber);
    // Tell browser the type of file
    myImgEnd = ".jpg";
    var i = 0;
    // Create function to load image
    function loadImg(){
    document.imgSrc.src = myImg[i] + myImgEnd;
    Any ideas as to why Firefox is behaving this way?

    After you check the box to sort on the column, are you making sure to select a sort order for the same column?
    Earl

  • Function issue of Cross-Reference

    Hi,
    thanks for your attention on this topic.
    there is function issue of Cross-Reference.
    when click the Cross-Reference after re-installed the software (adobe Framemaker 7.10), the function is not working. please kindly check the screenshots below:
    Error message below:
    Please help to check this issue.
    software: Adobe Framemaker 7.10
    System: windows xp sp3
    thanks in advance for your support .
    Message was edited by: Lu Steven

    Fire the error log off to the e-mail address indicated in the error message and then contact Adobe Support.

  • Sort function doesn't work E12

    the sort function doesn't work half the time on Elements 12 organizer.

    What about FUNCTION CLOCK_INFormula
    RETURN NUMBER
    IS
        l_hours_worked  NUMBER;
        l_to_return     NUMBER;
    BEGIN
        l_hours_worked := TO_NUMBER(NVL(:ATX_CLOCK_IN,'0'));
        IF (MOD((l_hours_worked - 0.02),0.25) = 0) THEN
            l_to_return := TRUNC((l_hours_worked - 0.02) * 4) / 4;
        ELSE
            l_to_return := TRUNC((l_hours_worked + 0.23) * 4) / 4;
        END IF;
        RETURN (l_to_return);
    EXCEPTION  
        WHEN VALUE_ERROR THEN
            RAISE_APPLICATION_ERROR ( -20100
            ,   'ERROR, Cannot represent '
            ||  :ATX_CLOCK_IN
            ||  ' as a number.');
    END CLOCK_INFormula;?
    This function assumes :ATX_CLOCK_IN is always positive.
    T.

  • Sorting /Grouping Issue: Single Artist Compilation Album Doesn't Group

    iTunes 8 Sorting / Grouping Issue
    EXAMPLE
    • Album: Essential Willie Nelson
    • There are 22 songs on this Disc
    • 19 of them are labelled "Willie Nelson" in the artist field
    • 3 of them are lebelled "Willie Nelson Feat. Waylon Jennings" in the artist field
    PROBLEM
    • Album will not stay grouped together when in the standard "Sort by Artist" in Grid View. A very legitimate expectation to be able to have Willie's name listed along with his pals in the artist field and have them grouped together in one album within Willie's albums section. 19 songs group within one album in the Willie Nelson section and the other 3 are placed separately either in the compilation section or as separate albums within the regular artists grid view.
    I've read most if not all postings that suggest solutions but no matter what... they don't work. The only way that I know to work is to strip out all other names and leave only "Willie Nelson" in the Artist field. All other sorting and grouping options don't work for this issue... I've tied every combination. My opinion is that this is just a limitation at this time and there is no solution until future updates. I don't want a cheezy work-around either, that's very "unApple like". I assume it to be fixed in future updates.
    Bueller... Bueller?
    Anyone?

    There's a few other "goodies" I have found also but haven't had time to check out.
    If you have songs not in iTunes that you want to add to iTunes in a different format than the song is in...
    (This is carried over from at least 7.4)
    Set the Importing prefs to what you want the new file to be.
    Hold the Option key and go to menu Advanced and select *Convert selection to* AAC (or whatever is in the Import prefs}.
    This will add it to iTunes in the new format.
    Previously, you had to Import the file, change the prefs, go to Advanced - *Convert selection to*, convert the file, then delete the original from iTunes.
    This is new...
    In iTunes 8, go to to File - > *Show duplicates*. (moved from View menu).
    Now hold Option and go to to File and it now displays *Show exact duplicates*.
    Don't know what it means by *exact duplicate* though.

  • Sort function not working

    I have a SQL report with different fields. At the report attribute when I checked sort, it gives me error "ORA-00911: invalid character". Any idea?
    My report is working fine without selecting sort function.
    Thanks,
    Mushtak

    After you check the box to sort on the column, are you making sure to select a sort order for the same column?
    Earl

  • DRQ#  Payment Wizard Sort Function

    Hi,
    The sort function in the SAP payment wizard, loses it's settings in Step 6.  In Step 3, you can sort the BP name field to sort by alpha, but in Step 6 the sort converts back to numeric, by BP Code.  Our client is having problems with this when making their invoice selections in the wizard, as their invoice filing system is alphabetic and they have a large pile to sort through when making payments. 
    I would have thought the sort option should retain throughout the wizard from Step 3 to Step 6.  Additionally it would be nice if in Step 6 there was also the option to sort again if needed.
    Edited by: Lianne Plant on Nov 9, 2010 3:42 AM

    Hi Janne,
    I trust you are well.
    Please post the DRQ in the forum ['SAP Business One Product Development Collaboration'|/community [original link is broken];.
    All the best,
    Jesper

  • Sort function in web report using servlet

    Dear all
    Please help me this out. I'm doing an online report using servlet. When the report is displayed as a table on the web, is there a way to have a sort function-when you click on the tabs, it will sort the data accordingly.
    If I didn't state my question clearly, please let me know.
    Thank you all for your kind help!
    Grace

    You could probably do that using Javascript, but it's beyond my competence to even suggest how. Alternatively you could make the tabs behave as buttons that send a "sort me" request to the server, which would send out new, resorted, HTML.

  • Using SORT function in mapping

    Hi,
    I am having trouble getting my head around using the SORT function.
    My interface is IDOC to File, The IDOC has a repeating segment (PAYLOAD) that can be of 3 types, either type A, B or C (this is set using a "TYPE" field).
    In my file structure I have a repeating "ROW" element which has all of the fields for each row.
    I want to group all the Type A data together, the Type B together and the Type C.
    I have tried the following mapping on the "ROW" element but it doesn't seem to work:
    "TYPE"--"sort"Split By Value (Value Change)--collapseContext--"ROW"
    for each of the mappings under ROW I just have fields copied directly.
    I think I am doing something wrong.
    Thanks.

    Hi,
       You could make this mapping
         TYPE --- +----------------+     +----------------+
               |                |     |                |
               | Concat         | --- | mySortFunction | --- NAME
               |                |     |                |
         NAME --- +----------------+     +----------------+
         TYPE --- +----------------+     +----------------+
               |                |     |                |
               | Concat         | --- | mySortFunction | --- ADDR
               |                |     |                |
         ADDR --- +----------------+     +----------------+
       Where source code of mySortFunction is like this:
    public void mySortFunction(String[] inputValues,ResultList result,Container container){
         for(int i=0;i<inputValues.length;i++)
              if(inputValues<i>.substring(0,1).equals("A"))
                   result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);               
         for(int i=0;i<inputValues.length;i++)
              if(inputValues<i>.substring(0,1).equals("B"))
                   result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);
         for(int i=0;i<inputValues.length;i++)
              if(inputValues<i>.substring(0,1).equals("C"))
                   result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);
       It is very simple. You concat TYPE whit your data, and then you sort all queue, so you have a new sort queue data. You must only then put out data.

  • Sorting functionality : Project systems information system

    Hello Experts,
    I have a problem,as discribed below. Please give me your expert suggestion.
    Requirement is : in report CN41 I need to display one custom field "XXXXX"
    and I need to enable sorting functionality on  this field.
    For this have created a sort profile in "define profiles for srting crietria" and assigned
    field "XXXXX".The sort criteria for this is assending order.
    Then have assigned this sorting profile to the PS info profile.
    Now when i Run CN41...the field 'XXXXX" is displayed and the sort icon appears
    on the top of the field collumn' 'XXXXX". BUT i am not able sort my CN41 report based on this.
    Did I miss anything here ? Even View--> sort/summarize/group ( from the top bar )
    is also not enabled.
    Can you please guide me where have gone wrong. Any other suggestions to enable this sorting functionality are welcome.
    Thanks in advance
    Sandeep

    Hi,
    I think in CN41 sort/summarize/group under 'View' menu is related to 'PS hier. type' of project view in OPUR.
    If you have fixed sort criteria then you can::
    Create a profile for sort criteria in OPTV.
    Add sort criteria profile in profile for calling overviews in OPSL.
    Add profile for calling overview in overall profiles for info. sys. under 'Structure overv' Field.
    Regards,
    Harsh.

  • Sort Function is being Overridden by Some default

    I've created a simple HFR report using Financial Reporting Studio to do budget vs. actual on a particular dimension (cost center). The dimemsion member selected is part of an alternate heirarchy which aggregrates the same way that I'd like the report to display. The particular member is selected as Decendents Inclusive (and is defined in the report as opposed to a prompt) so that I can capture the two levels below the selected member.
    No matter what I do using the Sort function (Name, Heirarchy, Description) in the member selection area when it generates the report the hierarchy is upside down (base, level 1, level 2), completely contrary the the actual heirarchy in EPMA. What am I missing and how do I get it to display from the top down?
    Thanks!
    Edited by: user13058666 on Jun 2, 2010 10:47 AM
    Edited by: user13058666 on Jun 2, 2010 10:53 AM

    A file under Private What? Where are you seeing this and how are you accessing it?

  • Getting UNCAUGHT_EXCEPTION CX_WD_CONTEXT at using alv sort function

    Dear colleagues,
    I developed a simple application which displays records in an ALV and at lead-selection shows detailed data in a form. Everthing is working fine except one is clicking on the sort functionality at the top of the ALV short dump is thrown.
    In trx ST22 I find :
    The lead selection has not been set. V_DEFAULT
    "UNCAUGHT_EXCEPTION" "CX_WD_CONTEXT"
    "CL_WDR_CONTEXT_NODE===========CP" or "CL_WDR_CONTEXT_NODE===========CM00R"
    "_RAISE_ELEMENT_NOT_FOUND"
    Lead selection is checked and also debugging the code did not bring me any further.
    Any help is greatly appreciated.
    Thanks in advance
    Michael

    Hi Regina,
    first of all thanks for your quick answer and explanation. I'm not sure what you mean with 'register to the standard functions of the ALV' because this is a functionality which works in other ALVs without register any event method to them or do you mean that in my case I have to react to the sorting in a new method in the view controller? Concerning 'refill the subnode via supply function' I'm doing this already.
    Disabling the sorting is no option anymore because the users already know and love this feature
    Regards
    Michael

Maybe you are looking for

  • 10.6 notice to restart computer when shutting down

    Twice now I got this notice when in process of shutting down computer that it tells me to press and hold power button and reboot. Both time I do this I get back to the desktop and then it tells me to send a report to Apple which I do, ideas on proble

  • How do I print a week of calendar events as a list

    How do I print a week of calendar events as a list?

  • Oracle Control Problem

    hi i'm new in oracle and i know that my question might be quite simple but i cannot manage this problem. here's my question i have two table (lets say A(name,number,code) and B (task,event) ) and A's number and B's task have same values. what i'm try

  • Does it matter that my AIR app was created in OSX 10.5.8 and revised in OSX 10.6.8?

    Hello, I don't know if this is the correct forum for this post, but here it goes. I created my AIR app on my desktop running OSX 10.5.8. I'm able to publish and install the app just fine. I'm also installing the same AIR app on my laptop running OSX

  • XI 3.0 SAMPLE Interactive Editor Integration Java Sample

    Hi I am trying to run XI 3.0 sampe for Interactive Editor Integration provided at resdk_java_ieditIntegr_sample.zip. When I try to login I am getting the following error: org.apache.jasper.JasperException: /viewers/cdz_adv/wistartpage.jsp(16,0) The v