Deprecate CheckedValue.orElseThrow(Supplier)
[yangtools.git] / common / concepts / src / main / java / org / opendaylight / yangtools / concepts / AbstractObjectRegistration.java
index 24044e61e5a5866fd277ab11e7c9555f93646c06..1fec43ca13cd5cea1c4c6a9b7adfa149fdd5f7a5 100644 (file)
@@ -7,17 +7,20 @@
  */
 package org.opendaylight.yangtools.concepts;
 
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.base.MoreObjects.ToStringHelper;
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
- * 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 AbstractObjectRegistration<T> extends AbstractRegistration implements ObjectRegistration<T> {
     private final T instance;
 
-    protected AbstractObjectRegistration(final T instance) {
-        this.instance = instance;
+    protected AbstractObjectRegistration(final @NonNull T instance) {
+        this.instance = requireNonNull(instance);
     }
 
     @Override
@@ -26,8 +29,8 @@ public abstract class AbstractObjectRegistration<T> extends AbstractRegistration
     }
 
     @Override
-    public String toString() {
-        return "AbstractObjectRegistration{instance=" + instance + '}';
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return super.addToStringAttributes(toStringHelper).add("instance", instance);
     }
 }