Migrate concepts to use JDT annotations
[yangtools.git] / common / concepts / src / main / java / org / opendaylight / yangtools / concepts / AbstractObjectRegistration.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.concepts;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import org.eclipse.jdt.annotation.NonNull;
14
15 /**
16  * Utility registration handle. It is a convenience for register-style method which can return an AutoCloseable realized
17  * by a subclass of this class. Invoking the close() method triggers unregistration of the state the method installed.
18  */
19 public abstract class AbstractObjectRegistration<T> extends AbstractRegistration implements ObjectRegistration<T> {
20     private final T instance;
21
22     protected AbstractObjectRegistration(final @NonNull T instance) {
23         this.instance = requireNonNull(instance);
24     }
25
26     @Override
27     public final T getInstance() {
28         return instance;
29     }
30
31     @Override
32     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
33         return super.addToStringAttributes(toStringHelper).add("instance", instance);
34     }
35 }
36