Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[riena-dev] IDisposable ...

Hi Rienars,

 

Sorry, another stumble.

 

While looking at SwtUtilities I wondered why there is no dispose()/isDisposed() helper for IDisposables.

Maybe because SwtUtilities (ui.swt) is "too far away" from IDisposable (ui.core). Ok!

 

But I would like to have something similar. Introducing a new helper just for dispose in ui.core? Maybe!?

 

But, how about this:

 

public interface IDisposable {

 

      /**

       * Disposes this object, i.e. free any resources.

       */

      void dispose();

 

      /**

       * Check whether this object has already disposed or not.

       *

       * @return disposed or not

       */

      boolean isDisposed();

 

      /**

       * Provides a helper on {@code IDisposable}s.

       */

      public static final class Util {

 

            private Util() {

                  // utility

            }

 

            /**

             * Disposes the given {@code IDisposable}, if the {@code IDisposable} is

             * not {@code null} and is not already disposed.

             *

             * @param disposable

             *            {@code IDisposable} to dispose

             */

            public static void dispose(final IDisposable disposable) {

                  if (disposable != null && !disposable.isDisposed()) {

                        disposable.dispose();

                  }

            }

 

      }

}

 

Can be used like this:

 

      IDisposable.Util.dispose(getNavigationNode());

 

Yep, requires getting used to it!

 

Thoughts and feedback?

 

Tschüß,

Stefan

 

-------------------------------------------------------------
compeople AG
Untermainanlage 8
60329 Frankfurt/Main
fon: +49 (0) 69 / 27 22 18 0
fax: +49 (0) 69 / 27 22 18 22
web: www.compeople.de

Vorstand: Jürgen Wiesmaier
Aufsichtsratsvorsitzender: Christian Glanz

Sitz der Gesellschaft: Frankfurt/Main
Handelsregister Frankfurt HRB 56759
Ust-Ident.-Nr: DE207665352
-------------------------------------------------------------

Back to the top