src/share/classes/sun/swing/AccumulativeRunnable.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 104     /**
 105      * {@inheritDoc}
 106      *
 107      * <p>
 108      * This implementation calls {@code run(List<T> args)} mehtod
 109      * with the list of accumulated arguments.
 110      */
 111     public final void run() {
 112         run(flush());
 113     }
 114 
 115     /**
 116      * appends arguments and sends this {@cod Runnable} for the
 117      * execution if needed.
 118      * <p>
 119      * This implementation uses {@see #submit} to send this
 120      * {@code Runnable} for execution.
 121      * @param args the arguments to accumulate
 122      */
 123     @SafeVarargs

 124     public final synchronized void add(T... args) {
 125         boolean isSubmitted = true;
 126         if (arguments == null) {
 127             isSubmitted = false;
 128             arguments = new ArrayList<T>();
 129         }
 130         Collections.addAll(arguments, args);
 131         if (!isSubmitted) {
 132             submit();
 133         }
 134     }
 135 
 136     /**
 137      * Sends this {@code Runnable} for the execution
 138      *
 139      * <p>
 140      * This method is to be executed only from {@code add} method.
 141      *
 142      * <p>
 143      * This implementation uses {@code SwingWorker.invokeLater}.
   1 /*
   2  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 104     /**
 105      * {@inheritDoc}
 106      *
 107      * <p>
 108      * This implementation calls {@code run(List<T> args)} mehtod
 109      * with the list of accumulated arguments.
 110      */
 111     public final void run() {
 112         run(flush());
 113     }
 114 
 115     /**
 116      * appends arguments and sends this {@cod Runnable} for the
 117      * execution if needed.
 118      * <p>
 119      * This implementation uses {@see #submit} to send this
 120      * {@code Runnable} for execution.
 121      * @param args the arguments to accumulate
 122      */
 123     @SafeVarargs
 124     @SuppressWarnings("varargs") // Copying args is safe
 125     public final synchronized void add(T... args) {
 126         boolean isSubmitted = true;
 127         if (arguments == null) {
 128             isSubmitted = false;
 129             arguments = new ArrayList<T>();
 130         }
 131         Collections.addAll(arguments, args);
 132         if (!isSubmitted) {
 133             submit();
 134         }
 135     }
 136 
 137     /**
 138      * Sends this {@code Runnable} for the execution
 139      *
 140      * <p>
 141      * This method is to be executed only from {@code add} method.
 142      *
 143      * <p>
 144      * This implementation uses {@code SwingWorker.invokeLater}.