All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.whaka.util.AbstractInitializable Maven / Gradle / Ivy

package org.whaka.util;

import java.util.concurrent.atomic.AtomicBoolean;

import com.google.common.base.Preconditions;

/**
 * 

Abstract implementation of the {@link Initializable}. Provides default implementations for all methods. * * @see #doInitialize() * @see #assertInitialized() */ public abstract class AbstractInitializable implements Initializable { private final AtomicBoolean initialized = new AtomicBoolean(); @Override public final void initialize() { if (initialized.compareAndSet(false, true)) doInitialize(); } /** * This method will be called only when {@link #initialize()} is called for the first time. */ protected void doInitialize() {} @Override public final boolean isInitialized() { return initialized.get(); } /** * @throws IllegalStateException if {@link #isInitialized()} returns false */ protected final void assertInitialized() throws IllegalStateException { Preconditions.checkState(isInitialized(), "Instance cannot be used before 'initialize()' method is called!"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy