Perform partial substatement initialization
[yangtools.git] / common / concepts / src / main / java / org / opendaylight / yangtools / concepts / AbstractIdentifiable.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import com.google.common.base.MoreObjects.ToStringHelper;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17
18 @Beta
19 @NonNullByDefault
20 public abstract class AbstractIdentifiable<T> implements Identifiable<T> {
21     private final @NonNull T identifier;
22
23     protected AbstractIdentifiable(final T identifier) {
24         this.identifier = requireNonNull(identifier);
25     }
26
27     @Override
28     public final T getIdentifier() {
29         return identifier;
30     }
31
32     @Override
33     public final String toString() {
34         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
35     }
36
37     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
38         return toStringHelper.add("identifier", getIdentifier());
39     }
40 }