source: proiecte/ptvs/src/vnsim/applications/adaptiveTL/SortedIntersectionRecordList.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 1.0 KB
Line 
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 ***********************************************************************************/
6package vnsim.applications.adaptiveTL;
7
8
9
10import java.util.*;
11
12import vnsim.vehicular.simulator.intersections.*;
13
14
15public 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.