jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Arzberger, Gerd (E F IE TI 1)" <gerd.arzber...@siemens.com>
Subject Bug in class org.apache.jcs.utils.struct.SortedPreferentialArray
Date Wed, 26 Jan 2011 15:45:36 GMT
Hello,

see the following test case:

public void testSortedPreferentialArray()
{
    SortedPreferentialArray test = new SortedPreferentialArray(10);
    test.setPreferLarge(true);

    for(int i = 1; i <= 10; i++)
    {
        test.add(new Integer(i));
    }

    assertEquals(1,((Integer)test.getSmallest()).intValue());  // o.k
    assertEquals(10,((Integer)test.getLargest()).intValue()); // o.k

    test.add(new Integer(11));

    logger.info(test.dumpArray());

    // Result of Dump is
    // 0=2
    // 1=3
    // 2=4
    // 3=5
    // 4=6
    // 5=7
    // 6=8
    // 7=9
    // 8=11
    // 9=10

    assertEquals(2,((Integer)test.getSmallest()).intValue());  // o.k.
    assertEquals(11,((Integer)test.getLargest()).intValue()); // will fail !!!
}

I think in the following code of SortedPreferentialArray.java "nLar-1" has to be replaced
with "nLar":

if ( preferLarge )
{
    if ( isFull )
    {
        // is full, prefer larger, remove smallest by shifting left
        int pnt = nLar-1; // set iteration stop point
        for ( int i = 0; i < pnt; i++ )
        {
            array[i] = array[i + 1];
        }
       // use nLar-1 for insertion point
       array[nLar-1] = obj;
       if ( log.isDebugEnabled() )
       {
            log.debug( "Inserted object at " + ( nLar - 1 ) );
        }
}



Best Regards
Gerd

Siemens AG
Energy Sector
Fossil Power Generation Division
Instrumentation & Electrical
E F IE TI 1
Freyeslebenstr. 1
91058 Erlangen, Deutschland
Tel.: +49 (9131) 18-82096
Fax: +49 (9131) 18-6878
mailto:gerd.arzberger@siemens.com

Siemens Aktiengesellschaft: Vorsitzender des Aufsichtsrats: Gerhard Cromme; Vorstand: Peter
Löscher, Vorsitzender; Wolfgang Dehen, Brigitte Ederer, Joe Kaeser, Barbara Kux, Hermann
Requardt, Siegfried Russwurm, Peter Y. Solmssen; Sitz der Gesellschaft: Berlin und München,
Deutschland; Registergericht: Berlin Charlottenburg, HRB 12300, München, HRB 6684; WEEE-Reg.-Nr.
DE 23691322



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message