Add yangtools.concepts.CheckedValue
[yangtools.git] / common / concepts / src / main / java / org / opendaylight / yangtools / concepts / AbstractRegistration.java
index c07b38b3ff7515ba064ff63d1701e537616b4a11..f0e6238e339a54dc52f1b576ac22e601f5509178 100644 (file)
@@ -7,33 +7,31 @@
  */
 package org.opendaylight.yangtools.concepts;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 
 /**
- * Utility registration handle. It is a convenience for register-style method
- * which can return an AutoCloseable realized by a subclass of this class.
- * Invoking the close() method triggers unregistration of the state the method
- * installed.
+ * Utility registration handle. It is a convenience for register-style method which can return an AutoCloseable realized
+ * by a subclass of this class. Invoking the close() method triggers unregistration of the state the method installed.
  */
-public abstract class AbstractRegistration implements AutoCloseable {
+public abstract class AbstractRegistration implements Registration {
     private static final AtomicIntegerFieldUpdater<AbstractRegistration> CLOSED_UPDATER =
             AtomicIntegerFieldUpdater.newUpdater(AbstractRegistration.class, "closed");
     private volatile int closed = 0;
 
     /**
-     * Remove the state referenced by this registration. This method is
-     * guaranteed to be called at most once. The referenced state must be
-     * retained until this method is invoked.
+     * Remove the state referenced by this registration. This method is guaranteed to be called at most once.
+     * Referenced state must be retained until this method is invoked.
      */
     protected abstract void removeRegistration();
 
     /**
-     * Query the state of this registration. Returns true if it was
-     * closed.
+     * Query the state of this registration. Returns true if it was closed.
      *
      * @return true if the registration was closed, false otherwise.
      */
-    protected final boolean isClosed() {
+    public final boolean isClosed() {
         return closed != 0;
     }
 
@@ -43,4 +41,13 @@ public abstract class AbstractRegistration implements AutoCloseable {
             removeRegistration();
         }
     }
+
+    @Override
+    public final String toString() {
+        return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
+    }
+
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return toStringHelper.add("closed", closed);
+    }
 }