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

ru.curs.celesta.CurrentScore Maven / Gradle / Ivy

The newest version!
package ru.curs.celesta;

import ru.curs.celesta.score.AbstractScore;

/**
 * ThreadLocal score accessor during the initialization of Celesta.
 */
public final class CurrentScore {
    private static final ThreadLocal CURRENT = new ThreadLocal<>();
    private static AbstractScore global = null;
    private static boolean globalMode;

    private CurrentScore() {
        throw new AssertionError();
    }

    /**
     * Returns score object. If global mode is on, single global score is returned.
     * Otherwise score object on a per thread basis is returned.
     */
    public static AbstractScore get() {
        if (globalMode) {
            return global;
        } else {
            return CURRENT.get();
        }
    }

    /**
     * Sets score object. If global mode is on, the score is saved as a global score.
     * Otherwise score object on a per thread basis is saved.
     *
     * @param score  Score object.
     */
    public static void set(AbstractScore score) {
        if (globalMode) {
            global = score;
        } else {
            CURRENT.set(score);
        }
    }

    /**
     * Sets if current score is in global mode.
     *
     * @param isGlobal  {@code true} - global mode on, {@code false} - off.
     */
    public static void global(boolean isGlobal) {
        CurrentScore.globalMode = isGlobal;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy