0

我有在 Java 中对元素进行排序的方法,它工作正常,但我需要在排序后清除缓冲区。看起来旧值保留在缓冲区中并替换当前数据及其坏数据。任何人都可以知道解决方案吗?

我的排序方法:

public List<InterimOrders> getInterimOrdersList() {

    if(interimOrdersList == null){
        interimOrdersList = new ArrayList<InterimOrders>();
        interimOrdersList.addAll(interimOrdRepo.findByLocation(location));


        for(InterimOrders io: interimOrdersList){

            if(io.isOnceAMonth()){
                List<Object[]> tmpList = new ArrayList<Object[]>();
                long[] datyLongTab = new long[3];

                    Object[] tmpOb = new Object[1];
                    tmpOb[0] = (Object)io.getDate1();


                    if(io.getDate1() != null){
                        datyLongTab[0] =  io.getDate1().getTime();
                    }
                    else{
                        datyLongTab[0] = 9223372036854775807L;
                    }
                    tmpList.add(tmpOb);


                    tmpOb = new Object[1];
                    tmpOb[0] = (Object)io.getDate2();

                    if(io.getDate2() != null){
                        datyLongTab[1] =  io.getDate2().getTime();
                    }
                    else{
                        datyLongTab[1] = 9223372036854775807L;
                    }
                    tmpList.add(tmpOb);


                    tmpOb = new Object[1];
                    tmpOb[0] = (Object)io.getDate3();


                    if(io.getDate3() != null){
                        datyLongTab[2] =  io.getDate3().getTime();
                    }
                    else{
                        datyLongTab[2] = 9223372036854775807L;
                    }
                    tmpList.add(tmpOb);
                    Arrays.sort(datyLongTab);  for(int i=0; i<3; i++){
                        long dat = 9223372036854775807L;
                        for(Object[] ele: tmpList){
                             if(ele[0] != null){
                                 dat = ((Date)ele[0]).getTime();
                             }


                             if(dat==datyLongTab[i]){

                                switch(i){
                                    case 0:
                                        io.setDate1((Date)ele[0]);

                                        break;
                                    case 1:
                                        io.setDate2((Date)ele[0]);

                                        break;
                                    case 2:
                                        io.setDate3((Date)ele[0]);

                                        break; }


                                break;
                            }
                        }

                    }


            }return interimOrdersList;
4

1 回答 1

0

clear()清除列表内容:

interimOrdersList.clear();

来自 JavaDoc:

从此列表中删除所有元素(可选操作)。此调用返回后,列表将为空。

于 2013-11-14T19:42:18.287 回答