Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Another LinkedList problem...
Posted by Eduardo on November 08, 2001 at 10:33 AM
There you go... I have 2 lists, one has the time and the other the events. I created a copy of both, as I had to sort the first one by ascendent order, using my LongComparator class, that converts to Long before using the Collections.sort. Everything looks fine, but I don't get the results. I do have partial results, but it doesn't work, as you can see below. Does anybody have a clue about how to solve that? Thanks, again! Eduardo PS: Let's see how many times this message will be replicated! LOL ******************> sorting the time LinkedList <**************************************** Collections.sort(TimeList, new LongComparator()); //********************> sorting the events LinkedList <************************************** try{ ListIterator g = EventList.listIterator(); ListIterator h = TimeList.listIterator(); while (h.hasNext() == true) { Index = Collections.binarySearch(TempTime,h.next(), new LongComparator()); if (Index>(-1)) { sortedEventList.add(TempEvent.get(Index)); sortedTimeList.add(TempTime.get(Index)); } else {System.out.println("Index = "+Index);} }}catch( ClassCastException e){System.out.println("There is a casting error in the list");} catch( NumberFormatException t){System.out.println("It's not the correct Number Format");} Results GlobalList: ThermostatDay 10000 GlobalList: WindowMalfunction 15000 GlobalList: WaterOff 8000 GlobalList: FansOff 6000 GlobalList: LightOff 2000 GlobalList: FansOn 4000 GlobalList: WaterOn 3000 GlobalList: LightOn 1000 GlobalList: Restart 20000 GlobalList: Bell 9000 GlobalList: ThermostatNight 0 GlobalList: Bell 11000 GlobalList: Bell 13000 GlobalList: Bell 15000 GlobalList: Bell 17000 Index = -1 Index = -1 Index = -1 Index = -1 Index = -1 Index = -1 Index = -1 Index = -1 Index = -2 Index = -2 Index = -9 Sorted Lists: ThermostatDay 10000 Sorted Lists: WindowMalfunction 15000 Sorted Lists: WindowMalfunction 15000 Sorted Lists: Restart 20000 LinkedListPrinting: ThermostatDay 0 Setting thermostat day 0 LinkedListPrinting: WindowMalfunction 1000 LinkedListPrinting: WaterOff 2000 etc...
Replies:
|