Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
1 package org.apidesign.openfixed;
3 import java.util.HashSet;
6 import java.util.concurrent.CopyOnWriteArrayList;
7 import java.util.concurrent.Executor;
8 import java.util.concurrent.Executors;
9 import org.apidesign.openfixed.Calculator.EventSupport;
13 * @author Jaroslav Tulach <jtulach@netbeans.org>
15 final class PostEventSupport implements EventSupport, Runnable {
16 private final List<ModificationListener> listeners = new CopyOnWriteArrayList<ModificationListener>();
17 private final List<Deliverable> deliverables = new CopyOnWriteArrayList<Deliverable>();
18 private static final Executor EXEC = Executors.newSingleThreadExecutor();
24 public void fireModificationEvent(ModificationEvent ev) {
25 synchronized (deliverables) {
26 final Deliverable d = new Deliverable(ev, listeners.toArray(new ModificationListener[0]));
33 public void add(ModificationListener l) {
38 public void remove(ModificationListener l) {
44 Deliverable[] pending;
45 synchronized (deliverables) {
46 if (deliverables.isEmpty()) {
49 pending = deliverables.toArray(new Deliverable[0]);
52 // BEGIN: openfixed.postimpl
53 Calculator calc = null;
54 Set<PostModificationListener> notify;
55 notify = new HashSet<PostModificationListener>();
56 int pendingCount = pending.length;
57 for (Deliverable d : pending) {
58 calc = (Calculator)d.ev.getSource();
59 d.ev.pending = --pendingCount;
61 for (ModificationListener l : d.listeners) {
66 for (PostModificationListener pml : notify) {
67 pml.postProcess(new PostModificationEvent(calc));
69 // END: openfixed.postimpl
72 private static class Deliverable {
73 final ModificationEvent ev;
74 final ModificationListener[] listeners;
76 public Deliverable(ModificationEvent ev, ModificationListener[] listeners) {
78 this.listeners = listeners;