Rev | Line | |
---|
[31] | 1 | /************************************************************************************ |
---|
| 2 | * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University |
---|
| 3 | * All rights reserved. |
---|
| 4 | * Refer to LICENSE for terms and conditions of use. |
---|
| 5 | ***********************************************************************************/ |
---|
| 6 | package vnsim.vehicular.generator; |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | import java.util.ArrayList; |
---|
| 10 | |
---|
| 11 | import vnsim.vehicular.simulator.CarInstance; |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | public class SortedEventsVector { |
---|
| 15 | |
---|
| 16 | private ArrayList<NewCarEvent> theArray; |
---|
| 17 | |
---|
| 18 | public SortedEventsVector() { |
---|
| 19 | theArray=new ArrayList<NewCarEvent>(); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | public int size() { |
---|
| 23 | return theArray.size(); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public String toString() { |
---|
| 27 | String ret=" [ "; |
---|
| 28 | for(int i=0;i<theArray.size();i++) { |
---|
| 29 | ret=ret+" ( "+ theArray.get(i)+" ) ; "; |
---|
| 30 | } |
---|
| 31 | ret+=" ] "; |
---|
| 32 | return ret; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | public NewCarEvent removeFirst() { |
---|
| 36 | if(size()==0) |
---|
| 37 | return null; |
---|
| 38 | return theArray.remove(0); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | public NewCarEvent first() { |
---|
| 42 | if(size()==0) |
---|
| 43 | return null; |
---|
| 44 | return theArray.get(0); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | public void addEvent(NewCarEvent ev) { |
---|
| 48 | for(int i=0;i<theArray.size();i++) { |
---|
| 49 | NewCarEvent nev=theArray.get(i); |
---|
| 50 | if(ev.compareTo(nev)<0) { |
---|
| 51 | //insert it |
---|
| 52 | theArray.add(i,ev); |
---|
| 53 | return; |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | theArray.add(ev); |
---|
| 57 | } |
---|
| 58 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.