diff --git a/src/main/java/umontreal/ssj/simevents/Simulator.java b/src/main/java/umontreal/ssj/simevents/Simulator.java index 56f160463..672a29b12 100644 --- a/src/main/java/umontreal/ssj/simevents/Simulator.java +++ b/src/main/java/umontreal/ssj/simevents/Simulator.java @@ -26,7 +26,6 @@ import umontreal.ssj.simevents.eventlist.EventList; import umontreal.ssj.simevents.eventlist.SplayTree; -import java.util.ListIterator; /** * Represents the executive of a discrete-event simulator. This class diff --git a/src/main/java/umontreal/ssj/simevents/eventlist/BinaryTree.java b/src/main/java/umontreal/ssj/simevents/eventlist/BinaryTree.java index e58c0f755..2bd08be06 100644 --- a/src/main/java/umontreal/ssj/simevents/eventlist/BinaryTree.java +++ b/src/main/java/umontreal/ssj/simevents/eventlist/BinaryTree.java @@ -28,14 +28,9 @@ import java.util.ListIterator; import java.util.ConcurrentModificationException; import java.util.NoSuchElementException; -import umontreal.ssj.util.PrintfFormat; import umontreal.ssj.simevents.Event; import umontreal.ssj.util.PrintfFormat; -/** - * Implantation de l'interface EventList ayant comme structure de - * donnees un arbre binaire. - */ /** * An implementation of @ref EventList using a binary search tree. Every @@ -55,24 +50,25 @@ public class BinaryTree implements EventList { // racine de l'arbre private Entry root = null; - // liste d'objets qui peuvent etre reutilises - private Entry freeEntries = null; - // compteur de modifications sur l'iterateur. private int modCount = 0; + + @Override public boolean isEmpty() { return root == null; } + @Override public void clear() { while (root != null) remove (root); } + @Override public void add (Event ev) { // fonction qui ajoute un evenement dans l'arbre // note : si deux evenements ont le meme temps, alors il faut - // toujours faire en sorte que ces evenements se retrouvement + // toujours faire en sorte que ces evenements se retrouvent // comme les fils droits les uns des autres Entry cursor = root; @@ -101,6 +97,7 @@ public void add (Event ev) { ++modCount; } + @Override public void addFirst (Event ev) { /** * Ajoute "ev" comme premier evenement dans l'arbre. @@ -128,6 +125,7 @@ public void addFirst (Event ev) { ++modCount; } + @Override public void addBefore (Event ev, Event other) { Entry otherEntry = findEntry (other); Entry evEntry = add (ev , null); @@ -164,6 +162,7 @@ public void addBefore (Event ev, Event other) { ++modCount; } + @Override public void addAfter (Event ev, Event other) { // on va chercher le "Entry" de other Entry otherEntry = findEntry (other); @@ -183,6 +182,7 @@ public void addAfter (Event ev, Event other) { ++modCount; } + @Override public Event getFirst() { if (root==null) return null; @@ -192,6 +192,7 @@ public Event getFirst() { return cursor.event; } + @Override public Event getFirstOfClass (String cl) { Entry cursor = root; if (root != null) @@ -207,6 +208,7 @@ public Event getFirstOfClass (String cl) { } @SuppressWarnings("unchecked") + @Override public E getFirstOfClass (Class cl) { Entry cursor = root; if (root != null) @@ -221,14 +223,17 @@ public E getFirstOfClass (Class cl) { return null; } + @Override public Iterator iterator() { return listIterator(); } + @Override public ListIterator listIterator() { return new BTItr(); } + @Override public boolean remove (Event ev) { Entry evEntry = findEntry(ev); if (evEntry == null) @@ -237,6 +242,7 @@ public boolean remove (Event ev) { return remove(evEntry); } + @Override public Event removeFirst() { if (root == null) return null; @@ -251,8 +257,9 @@ public Event removeFirst() { return first; } + @Override public String toString() { - StringBuffer sb = new StringBuffer ("Contents of the event list BinaryTree:"); + StringBuilder sb = new StringBuilder ("Contents of the event list BinaryTree:"); Entry cursor = root; if (root != null) @@ -271,19 +278,7 @@ public String toString() { } private Entry add (Event ev, Entry father) { - // On regarde la liste freeEntries - if (freeEntries != null) { - Entry tempo = freeEntries; - freeEntries = freeEntries.right; - tempo.event = ev; - tempo.left = null; - tempo.right = null; - tempo.father = father; - return tempo; - } - // on cree un nouvel objet - else - return new Entry(ev, null, null, father); + return new Entry(ev, null, null, father); } private boolean remove (Entry e) { @@ -345,9 +340,6 @@ else if (filsGauche) while (cursor.left != null) cursor = cursor.left; - // echange entre e et cursor et elimination de e - cursor.father.left = cursor.right; - if (isRoot) root = cursor; else if (filsGauche) @@ -355,6 +347,7 @@ else if (filsGauche) else e.father.right = cursor; + // echange entre e et cursor et elimination de e cursor.father.left = cursor.right; if (cursor.right != null) cursor.right.father = cursor.father; @@ -369,11 +362,10 @@ else if (filsGauche) } // recupere l'espace du noeud - e.right = freeEntries; + e.right = null; e.left = null; e.event = null; - freeEntries = e; - e = null; + ++modCount; return true; } @@ -465,6 +457,7 @@ private class BTItr implements ListIterator { nextIndex = 0; } + @Override public void add(Event ev) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -519,18 +512,21 @@ public void add(Event ev) { ++expectedModCount; } + @Override public boolean hasNext() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); return next != null; } + @Override public boolean hasPrevious() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); return prev != null; } + @Override public Event next() { if (!hasNext()) throw new NoSuchElementException(); @@ -543,6 +539,7 @@ public Event next() { return ev; } + @Override public int nextIndex() { if (!hasNext()) throw new NoSuchElementException(); @@ -550,6 +547,7 @@ public int nextIndex() { return nextIndex; } + @Override public Event previous() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -562,6 +560,7 @@ public Event previous() { return ev; } + @Override public int previousIndex() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -569,6 +568,7 @@ public int previousIndex() { return nextIndex - 1; } + @Override public void remove() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -586,6 +586,7 @@ public void remove() { ++expectedModCount; } + @Override public void set (Event ev) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); diff --git a/src/main/java/umontreal/ssj/simevents/eventlist/DoublyLinked.java b/src/main/java/umontreal/ssj/simevents/eventlist/DoublyLinked.java index b4d883a6b..2824937d0 100644 --- a/src/main/java/umontreal/ssj/simevents/eventlist/DoublyLinked.java +++ b/src/main/java/umontreal/ssj/simevents/eventlist/DoublyLinked.java @@ -46,38 +46,27 @@ public class DoublyLinked implements EventList { // First and last elements in the list. private Node first = null, last = null; - private static Node free = null; // Pointer to stack of free nodes. + + @Override public boolean isEmpty() { return first == null; } + @Override public void clear() { if (first == null) return; - /* Node p = first; - while (p != null) { - p.ev.setTime(-20.0); - p.ev = null; - p = p.succ; - } - */ - synchronized (DoublyLinked.class) { - last.succ = free; free = first; - } + + last.succ = null; last = first = null; ++modCount; } + @Override public void add (Event ev) { Node newNode; - synchronized (DoublyLinked.class) { - if (free == null) - newNode = new Node(); - else { - newNode = free; - free = free.succ; - } - } + newNode = new Node(); + newNode.ev = ev; ++modCount; if (last == null) { // Easy: the event list was empty. @@ -104,16 +93,11 @@ public void add (Event ev) { } } + @Override public void addFirst (Event ev) { Node newNode; - synchronized (DoublyLinked.class) { - if (free == null) - newNode = new Node(); - else { - newNode = free; - free = free.succ; - } - } + newNode = new Node(); + newNode.ev = ev; newNode.prec = null; if (first == null) { @@ -128,6 +112,7 @@ public void addFirst (Event ev) { ++modCount; } + @Override public void addBefore (Event ev, Event other) { Node node = last; while (node != null && node.ev.compareTo(other) >= 0 && node.ev != other) @@ -136,14 +121,8 @@ public void addBefore (Event ev, Event other) { throw new IllegalArgumentException ("Event not in list."); Node newNode; - synchronized (DoublyLinked.class) { - if (free == null) - newNode = new Node(); - else { - newNode = free; - free = free.succ; - } - } + newNode = new Node(); + newNode.ev = ev; newNode.prec = node.prec; @@ -156,6 +135,7 @@ public void addBefore (Event ev, Event other) { ++modCount; } + @Override public void addAfter (Event ev, Event other) { Node node = last; while (node != null && node.ev.compareTo(other) >= 0 && node.ev != other) @@ -164,14 +144,8 @@ public void addAfter (Event ev, Event other) { throw new IllegalArgumentException ("Event not in list."); Node newNode; - synchronized (DoublyLinked.class) { - if (free == null) - newNode = new Node(); - else { - newNode = free; - free = free.succ; - } - } + newNode = new Node(); + newNode.ev = ev; newNode.prec = node; @@ -184,10 +158,12 @@ public void addAfter (Event ev, Event other) { ++modCount; } + @Override public Event getFirst() { return first == null ? null : first.ev; } + @Override public Event getFirstOfClass (String cl) { Node node = first; while (node != null) { @@ -199,6 +175,7 @@ public Event getFirstOfClass (String cl) { } @SuppressWarnings("unchecked") + @Override public E getFirstOfClass (Class cl) { Node node = first; while (node != null) { @@ -209,6 +186,7 @@ public E getFirstOfClass (Class cl) { return null; } + @Override public boolean remove (Event ev) { // Find the node corresponding to this event ev. Node node = last; @@ -236,13 +214,13 @@ public boolean remove (Event ev) { } } node.ev = null; - synchronized (DoublyLinked.class) { - node.succ = free; free = node; // Recycle node. - } + node.succ = null; + ++modCount; return true; } + @Override public Event removeFirst() { if (first == null) return null; @@ -256,23 +234,25 @@ public Event removeFirst() { first.prec = null; temp.ev = null; - synchronized (DoublyLinked.class) { - temp.succ = free; free = temp; // Recycle node. - } + temp.succ = null; + ++modCount; return ev; } + @Override public Iterator iterator() { return listIterator(); } + @Override public ListIterator listIterator() { return new DLItr(); } + @Override public String toString() { - StringBuffer sb = new StringBuffer ("Contents of the event list DoublyLinked:"); + StringBuilder sb = new StringBuilder ("Contents of the event list DoublyLinked:"); Node node = first; while (node != null) { sb.append (PrintfFormat.NEWLINE + @@ -306,6 +286,7 @@ private class DLItr implements ListIterator { nextIndex = 0; } + @Override public void add(Event ev) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -321,14 +302,8 @@ public void add(Event ev) { } Node newNode; - synchronized (DoublyLinked.class) { - if (free == null) - newNode = new Node(); - else { - newNode = free; - free = free.succ; - } - } + newNode = new Node(); + newNode.ev = ev; ++nextIndex; ++modCount; @@ -362,18 +337,21 @@ else if (prev == null) { // Must be inserted first. } } + @Override public boolean hasNext() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); return next != null; } + @Override public boolean hasPrevious() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); return prev != null; } + @Override public Event next() { if (!hasNext()) throw new NoSuchElementException(); @@ -386,6 +364,7 @@ public Event next() { return ev; } + @Override public int nextIndex() { if (!hasNext()) throw new NoSuchElementException(); @@ -393,6 +372,7 @@ public int nextIndex() { return nextIndex; } + @Override public Event previous() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -405,6 +385,7 @@ public Event previous() { return ev; } + @Override public int previousIndex() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -412,6 +393,7 @@ public int previousIndex() { return nextIndex - 1; } + @Override public void remove() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -445,14 +427,14 @@ public void remove() { } } lastRet.ev = null; - synchronized (DoublyLinked.class) { - lastRet.succ = free; free = lastRet; // Recycle node. - } + lastRet.succ = null; + lastRet = null; ++modCount; ++expectedModCount; } + @Override public void set (Event ev) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); diff --git a/src/main/java/umontreal/ssj/simevents/eventlist/Henriksen.java b/src/main/java/umontreal/ssj/simevents/eventlist/Henriksen.java index d5c229620..b28df1440 100644 --- a/src/main/java/umontreal/ssj/simevents/eventlist/Henriksen.java +++ b/src/main/java/umontreal/ssj/simevents/eventlist/Henriksen.java @@ -37,7 +37,7 @@ * of Henriksen @cite sKIN86a  (see also @cite sFIS01a  (p. * 207)). * - * Events are stored in a normal doubly-linked list. An additionnal index + * Events are stored in a normal doubly-linked list. An additional index * array is added to the structure to allow quick access to the events. * *
@@ -63,7 +63,6 @@ public class Henriksen implements EventList { Ceci permet un certain balancement des elements presents dans l'index, et donc une meilleure efficacite de la recherche binaire sans avoir a mettre tous les elements dans l'index. - */ private static final double MIN_VALUE = -10E38; //n'importe quoi < 0 @@ -96,10 +95,12 @@ public Henriksen() { entryVec[0] = lastEntry; } + @Override public boolean isEmpty() { return firstEntry.right == entryVec[0]; } + @Override public void clear() { if(isEmpty()) return; @@ -116,6 +117,7 @@ public void clear() { } + @Override public void add (Event ev) { Entry prec = findEntry(ev, false); @@ -125,6 +127,7 @@ public void add (Event ev) { modCount++; } + @Override public void addFirst (Event ev) { Entry e = new Entry(ev, firstEntry, firstEntry.right, ev.time()); firstEntry.right.left = e; @@ -133,6 +136,7 @@ public void addFirst (Event ev) { modCount++; } + @Override public void addBefore (Event ev, Event other) { Entry otherEntry = findEntry(other, true); if(otherEntry == null) @@ -144,6 +148,7 @@ public void addBefore (Event ev, Event other) { modCount++; } + @Override public void addAfter (Event ev, Event other) { Entry otherEntry = findEntry(other, true); if(otherEntry == null) @@ -156,10 +161,12 @@ public void addAfter (Event ev, Event other) { } + @Override public Event getFirst() { return firstEntry.right.event; } + @Override public Event getFirstOfClass (String cl) { Entry e = firstEntry.right; while(e.right != null) { @@ -171,6 +178,7 @@ public Event getFirstOfClass (String cl) { } @SuppressWarnings("unchecked") + @Override public E getFirstOfClass (Class cl) { Entry e = firstEntry.right; while(e.right != null) { @@ -181,14 +189,17 @@ public E getFirstOfClass (Class cl) { return null; } + @Override public Iterator iterator() { return listIterator(); } + @Override public ListIterator listIterator() { return new HItr(); } + @Override public boolean remove (Event ev) { Entry e = findEntry (ev, true); if (e == null) @@ -218,6 +229,7 @@ public boolean remove (Event ev) { return true; } + @Override public Event removeFirst() { // si la premiere moitie de l'index est composee d'entrees perimees, // on coupe de moitie l'index @@ -245,8 +257,9 @@ public Event removeFirst() { } + @Override public String toString() { - StringBuffer sb = new StringBuffer + StringBuilder sb = new StringBuilder ("Contents of the event list Henriksen:"); Entry e = firstEntry.right; while (e.right != null) { @@ -273,6 +286,7 @@ private static class Entry { this.time = time; } + @Override public String toString() { return "[" + event + " |" + time + "|]"; } @@ -294,6 +308,7 @@ private HItr() { nextIndex = 0; } + @Override public void add (Event ev) { if(modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -319,18 +334,21 @@ public void add (Event ev) { expectedModCount++; } + @Override public boolean hasNext() { if(modCount != expectedModCount) throw new ConcurrentModificationException(); return next != entryVec[0]; } + @Override public boolean hasPrevious() { if(modCount != expectedModCount) throw new ConcurrentModificationException(); return next != firstEntry; } + @Override public Event next() { if (!hasNext()) throw new NoSuchElementException(); @@ -343,6 +361,7 @@ public Event next() { return ev; } + @Override public int nextIndex() { if(!hasNext()) throw new NoSuchElementException(); @@ -350,6 +369,7 @@ public int nextIndex() { return nextIndex; } + @Override public Event previous() { if(!hasPrevious()) throw new NoSuchElementException(); @@ -362,6 +382,7 @@ public Event previous() { return ev; } + @Override public int previousIndex() { if(!hasPrevious()) throw new NoSuchElementException(); @@ -370,6 +391,7 @@ public int previousIndex() { } + @Override public void remove() { if(modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -407,6 +429,7 @@ public void remove() { expectedModCount++; } + @Override public void set (Event ev) { if(modCount != expectedModCount) throw new ConcurrentModificationException(); diff --git a/src/main/java/umontreal/ssj/simevents/eventlist/RedblackTree.java b/src/main/java/umontreal/ssj/simevents/eventlist/RedblackTree.java index c1becd661..2e4e8715a 100644 --- a/src/main/java/umontreal/ssj/simevents/eventlist/RedblackTree.java +++ b/src/main/java/umontreal/ssj/simevents/eventlist/RedblackTree.java @@ -33,7 +33,6 @@ import java.util.NoSuchElementException; import umontreal.ssj.util.PrintfFormat; import umontreal.ssj.simevents.Event; -import umontreal.ssj.simevents.Sim; /** * An implementation of @ref EventList using a *red black* tree, which is @@ -52,23 +51,22 @@ *
*/ public class RedblackTree implements EventList { - private TreeMap tree = new TreeMap(new EventComparator()); - private static Node free = null; + private final TreeMap tree = new TreeMap(new EventComparator()); private int modCount = 0; + + @Override public void clear() { Iterator itr = tree.values().iterator(); while (itr.hasNext()) { Node node = itr.next(); node.events.clear(); itr.remove(); - synchronized (RedblackTree.class) { - node.nextNode = free; - free = node; - } + node.nextNode = null; } ++modCount; } + @Override public void add (Event ev) { Node node = tree.get (ev); if (node != null) @@ -78,8 +76,8 @@ public void add (Event ev) { ++modCount; } + @Override public void addFirst (Event ev) { - // ev.setTime (Sim.time()); // necessaire si eventime n'est pas deja a 0 Node node = tree.get (ev); if (node != null) node.events.add (ev); @@ -88,29 +86,31 @@ public void addFirst (Event ev) { ++modCount; } + @Override public void addBefore (Event ev, Event other) { Node node = tree.get (other); if (node == null) throw new IllegalArgumentException ("Event not in list."); - // ev.setTime (other.time()); node.addBefore (ev, other); ++modCount; } + @Override public void addAfter (Event ev, Event other) { Node node = tree.get (other); if (node == null) throw new IllegalArgumentException ("Event not in list."); - // ev.setTime (other.time()); node.addAfter (ev, other); ++modCount; } + @Override public Event getFirst() { return isEmpty() ? null : tree.get (tree.firstKey()).events.get (0); } + @Override public Event getFirstOfClass (String cl) { Iterator itr = tree.values().iterator(); while (itr.hasNext()) { @@ -122,6 +122,7 @@ public Event getFirstOfClass (String cl) { return null; } + @Override public E getFirstOfClass (Class cl) { Iterator itr = tree.values().iterator(); while (itr.hasNext()) { @@ -133,20 +134,20 @@ public E getFirstOfClass (Class cl) { return null; } + @Override public boolean remove (Event ev) { Node node = tree.get (ev); if (node == null) return false; if (node.remove (ev)) { tree.remove (ev); - synchronized (RedblackTree.class) { - node.nextNode = free; free = node; - } + node.nextNode = null; } ++modCount; return true; } + @Override public Event removeFirst() { if (tree.isEmpty()) return null; @@ -156,16 +157,15 @@ public Event removeFirst() { node.events.remove (0); if (node.events.isEmpty()) { tree.remove (evKey); - synchronized (RedblackTree.class) { - node.nextNode = free; free = node; - } + node.nextNode = null; } ++modCount; return first; } + @Override public String toString() { - StringBuffer sb = new StringBuffer ("Contents of the event list RedblackTree:"); + StringBuilder sb = new StringBuilder ("Contents of the event list RedblackTree:"); for (Node node : tree.values()) { for (Event ev : node.events) sb.append (PrintfFormat.NEWLINE + @@ -176,14 +176,17 @@ public String toString() { return sb.toString(); } + @Override public Iterator iterator() { return listIterator(); } + @Override public ListIterator listIterator() { return new RBItr(); } + @Override public boolean isEmpty() { return tree.isEmpty(); } @@ -261,8 +264,9 @@ public boolean remove (Event ev) { throw new IllegalArgumentException ("Event not in node."); } + @Override public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); boolean first = true; Iterator itr = events.iterator(); while (itr.hasNext()) { @@ -277,11 +281,10 @@ public String toString() { } private static class EventComparator implements Comparator { + @Override public int compare (Event ev1, Event ev2) { return ev1.compareTo(ev2); } - - public boolean equals (Object obj) { return true; } } private class RBItr implements ListIterator { @@ -313,10 +316,12 @@ private class RBItr implements ListIterator { } } + @Override public void add(Event ev) { throw new UnsupportedOperationException(); } + @Override public boolean hasNext() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -324,6 +329,7 @@ public boolean hasNext() { nextNodeIndex < nextNode.events.size(); } + @Override public boolean hasPrevious() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -331,6 +337,7 @@ public boolean hasPrevious() { prevNodeIndex >= 0; } + @Override public Event next() { if (!hasNext()) throw new NoSuchElementException(); @@ -347,6 +354,7 @@ public Event next() { return ev; } + @Override public int nextIndex() { if (!hasNext()) throw new NoSuchElementException(); @@ -354,6 +362,7 @@ public int nextIndex() { return nextIndex; } + @Override public Event previous() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -371,6 +380,7 @@ public Event previous() { return ev; } + @Override public int previousIndex() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -378,26 +388,19 @@ public int previousIndex() { return nextIndex - 1; } + @Override public void remove() { throw new UnsupportedOperationException(); } + @Override public void set (Event ev) { throw new UnsupportedOperationException(); } } private Node newNode (Event ev) { - Node temp; - synchronized (RedblackTree.class) { - if (free == null) - return new Node (ev); - - temp = free; - free = free.nextNode; - } - temp.events.add (ev); - return temp; + return new Node (ev); } private class EventMapKey extends Event { @@ -406,6 +409,7 @@ public EventMapKey(Event ev) { this.priority = ev.priority(); } + @Override public void actions() { } } } \ No newline at end of file diff --git a/src/main/java/umontreal/ssj/simevents/eventlist/SplayTree.java b/src/main/java/umontreal/ssj/simevents/eventlist/SplayTree.java index 2a8c0ec91..296a078f7 100644 --- a/src/main/java/umontreal/ssj/simevents/eventlist/SplayTree.java +++ b/src/main/java/umontreal/ssj/simevents/eventlist/SplayTree.java @@ -44,7 +44,6 @@ */ public class SplayTree implements EventList { private Entry root = null; - private static Entry free = null; private int modCount = 0; private int myCompareTo (Event ev, Event other) { @@ -59,10 +58,12 @@ private int myCompareTo (Event ev, Event other) { return 1; return 0; } + @Override public boolean isEmpty() { return root == null; } + @Override public void clear() { // Simply root = null would be more efficient but the // entries would not be recuperated. @@ -70,6 +71,7 @@ public void clear() { remove (root); } + @Override public void add (Event ev) { //ajoute un element dans l'arbre en faisant un "splay" @@ -173,6 +175,7 @@ else if (myCompareTo(ev, temp.event) > 0) { ++modCount; } + @Override public void addFirst (Event ev) { if (root == null) root = add (ev, null); @@ -185,6 +188,7 @@ public void addFirst (Event ev) { ++modCount; } + @Override public void addBefore (Event ev, Event other) { Entry otherEntry = findEntry (other); if (otherEntry == null) @@ -215,6 +219,7 @@ public void addBefore (Event ev, Event other) { ++modCount; } + @Override public void addAfter (Event ev, Event other) { Entry otherEntry = findEntry (other); if (otherEntry == null) @@ -228,6 +233,7 @@ public void addAfter (Event ev, Event other) { ++modCount; } + @Override public Event getFirst() { if (root == null) return null; @@ -237,6 +243,7 @@ public Event getFirst() { return cursor.event; } + @Override public Event getFirstOfClass (String cl) { Entry cursor = root; if (root != null) @@ -251,6 +258,7 @@ public Event getFirstOfClass (String cl) { } @SuppressWarnings("unchecked") + @Override public E getFirstOfClass (Class cl) { Entry cursor = root; if (root != null) @@ -264,14 +272,17 @@ public E getFirstOfClass (Class cl) { return null; } + @Override public Iterator iterator() { return listIterator(); } + @Override public ListIterator listIterator() { return new SPItr(); } + @Override public boolean remove (Event ev) { //on trouve le noeud correspondant a l'evenement pour l'enlever if (root == null) @@ -282,6 +293,7 @@ public boolean remove (Event ev) { return remove (e); } + @Override public Event removeFirst() { if (root == null) return null; @@ -293,8 +305,9 @@ public Event removeFirst() { return first; } + @Override public String toString() { - StringBuffer sb = new StringBuffer + StringBuilder sb = new StringBuilder ("Contents of the event list SplayTree:"); Entry cursor = root; if (root != null) @@ -343,6 +356,7 @@ private class SPItr implements ListIterator { nextIndex = 0; } + @Override public void add(Event ev) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -399,18 +413,21 @@ public void add(Event ev) { ++expectedModCount; } + @Override public boolean hasNext() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); return next != null; } + @Override public boolean hasPrevious() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); return prev != null; } + @Override public Event next() { if (!hasNext()) throw new NoSuchElementException(); @@ -423,6 +440,7 @@ public Event next() { return ev; } + @Override public int nextIndex() { if (!hasNext()) throw new NoSuchElementException(); @@ -430,6 +448,7 @@ public int nextIndex() { return nextIndex; } + @Override public Event previous() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -442,6 +461,7 @@ public Event previous() { return ev; } + @Override public int previousIndex() { if (!hasPrevious()) throw new NoSuchElementException(); @@ -449,6 +469,7 @@ public int previousIndex() { return nextIndex - 1; } + @Override public void remove() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -466,6 +487,7 @@ public void remove() { ++expectedModCount; } + @Override public void set (Event ev) { if (modCount != expectedModCount) throw new ConcurrentModificationException(); @@ -492,18 +514,7 @@ public void set (Event ev) { * Creates a new entry object. */ private Entry add (Event ev, Entry father) { - Entry e; - synchronized (SplayTree.class) { - if (free == null) - return new Entry (ev, null, null, father); - - e = free; - free = free.right; - } - e.event = ev; - e.left = e.right = null; - e.father = father; - return e; + return new Entry (ev, null, null, father); } @@ -669,14 +680,9 @@ private boolean remove(Entry e) if(rightTree != null) rightTree.father = null; - // Recupere l'espace de l'avis d'evenement e.left = null; e.event = null; - synchronized (SplayTree.class) { - e.right = free; - free = e; - } - + e.right = null; if(rightTree == null) root = leftTree; @@ -697,7 +703,6 @@ else if(leftTree == null) root = newRoot; } - ++modCount; return true; @@ -870,4 +875,4 @@ public String toString() { } } */ -} \ No newline at end of file +}