org.opendaylight.yangtools.concepts.NoOpObjectRegistration Maven / Gradle / Ivy
/*
* Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.concepts;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import org.eclipse.jdt.annotation.NonNullByDefault;
/**
* Implementation of {@link ObjectRegistration} which does nothing in its {@link #close()} method.
*
* @param Type of registered object
*/
@NonNullByDefault
public class NoOpObjectRegistration implements Immutable, ObjectRegistration {
private final T instance;
NoOpObjectRegistration(final T instance) {
this.instance = requireNonNull(instance);
}
public static ObjectRegistration of(final T instance) {
return new NoOpObjectRegistration<>(instance);
}
@Override
public final T getInstance() {
return instance;
}
@Override
public final void close() {
// No-op
}
@Override
public final String toString() {
return MoreObjects.toStringHelper(this).add("instance", instance).toString();
}
}