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.applications.adaptiveTL; |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | import java.util.*; |
---|
| 11 | |
---|
| 12 | import vnsim.vehicular.simulator.intersections.*; |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | public class SortedIntersectionRecordList extends ArrayList<IntersectionCarRecord>{ |
---|
| 16 | |
---|
| 17 | DirectedRoadSegment segment; |
---|
| 18 | RecordComparator comparator = null; |
---|
| 19 | |
---|
| 20 | public SortedIntersectionRecordList(DirectedRoadSegment segment) { |
---|
| 21 | super(); |
---|
| 22 | this.segment = segment; |
---|
| 23 | comparator = new RecordComparator(segment); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | public RecordComparator getComparator() { |
---|
| 27 | return comparator; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | public boolean add(IntersectionCarRecord newCar) { |
---|
| 31 | int idx = Collections.binarySearch(this, newCar, comparator); |
---|
| 32 | if (idx < 0){ |
---|
| 33 | super.add( - idx - 1, newCar); |
---|
| 34 | return true; |
---|
| 35 | } |
---|
| 36 | return false; |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
Note: See
TracBrowser
for help on using the repository browser.