0

I am doing automaton. I'm reading the data from database and select the specific data. Here my database contains a sequence number list. Initially I put it into a array list.

This is the db sequence number:

[1,2,3,1.5,5,6,7,4,5,6,7,12,13,1.75,4.5,16,17,6.5,7,12,13,16,17,24,25,14.50,14.51,6.75,7,12,13,14.5,14.51,16,17,24,25,38,39,31.5,41]

I am looping to check if(current value < previous value)..(1.5<3) then that value means 1.5 should be inserted before the immdiate greater value of that.

Here immediate greater value of 1.5 is 2, then the array list looks like this :

  • the first array [1,2,3] then [1,1.5,2,3,5,6] - here 1.5 is inserted before 2
  • second- [1,1.5,2,3,4,5,6,7,12,13] here 4 is inserted before 5
  • third- [1,1.5,1.75,2,3,4,5,6,7,12,13] here 1.75 is inserted before 2

public static void insertBefore() {
    int next=0;

    //here seqNo contains list of sequence number from db.
    List<Double> seqNo=new ArrayList<Double>();

    for(int i=0;i<alevents.size();i++) {
        sequenceNo = Double.parseDouble(alEvents.get(i).sequenceNumber.trim());
        seqNo.add(sequenceNo);
    }

    for(int s=0;s<seqNo.size();s++) {
        if(seq[s]>seq[s+1] {  //[1,2,3,1.5]
            next=seq[s+1]
            seqNo.sort(); //[1,1.5,2,3]
            seqNo.indexof(next); //take index value as 1
        }
    }
}

Here I have a concern about this function mainly used to identify the cell value from GUI application from using specfic index. I am able to get the exact cell value from GUI, but this function is called only when previous value greater than current value.

So others are normal entry events. So whenever this function is called I need to take next value means 7 and 4 then need to take the index value from that list. The list is [1,1.5,2,3,5,6,7] like this, then again this function is called, then I need to check 13 and 1.75 [1,1.5,2,3,4,5,6,7,12,13]. This should be continued, how it is possible?

1
  • 3
    Is there a reason you can't use the standard Java array sort?
    – Kate Paulk
    Oct 29, 2018 at 19:29

1 Answer 1

1

If you have a list with all those items just do:

list.sort()

Here is the doc for List methods: https://docs.oracle.com/javase/8/docs/api/java/util/List.html