/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.applications.adaptiveTL; import java.util.*; import vnsim.vehicular.simulator.intersections.*; public class SortedIntersectionRecordList extends ArrayList{ DirectedRoadSegment segment; RecordComparator comparator = null; public SortedIntersectionRecordList(DirectedRoadSegment segment) { super(); this.segment = segment; comparator = new RecordComparator(segment); } public RecordComparator getComparator() { return comparator; } public boolean add(IntersectionCarRecord newCar) { int idx = Collections.binarySearch(this, newCar, comparator); if (idx < 0){ super.add( - idx - 1, newCar); return true; } return false; } }