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

xyz.thepathfinder.android.ModelRegistry Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package xyz.thepathfinder.android;

import java.util.HashMap;
import java.util.Map;

/**
 * The ModelRegistry keeps track of all {@link Model}s created by
 * the Pathfinder SDK.
 *
 * @author David Robinson
 */
class ModelRegistry {

    /**
     * Map to all the {@link Model}s created by the SDK. The keys are the string
     * version of paths.
     */
    private final Map models;

    /**
     * Constructs a ModelRegistry object with an empty registry of {@link Model}s.
     */
    protected ModelRegistry() {
        this.models = new HashMap();
    }

    /**
     * Adds a {@link Model} to the registry.
     *
     * @param model the model to be added to the registry.
     * @throws IllegalStateException the path has already been used by another
     *                               model.
     */
    protected void registerModel(Model model) {
        if (this.models.containsKey(model.getPath())) {
            throw new IllegalStateException("Path already exists: " + model.getPath());
        }

        this.models.put(model.getPath(), model);
    }

    /**
     * Removes a {@link Model} from the registry.
     *
     * @param path to the model.
     * @return the model removed.
     */
    protected Model unregisterModel(String path) {
        return this.models.remove(path);
    }

    /**
     * Returns if a {@link Model} has been registered with the specified path.
     *
     * @param path of the model to check.
     * @return true if a model has been registered with that path,
     * false otherwise.
     */
    protected boolean isModelRegistered(String path) {
        return this.models.containsKey(path);
    }

    /**
     * Returns the {@link Model} associated with the specified path in the registry.
     *
     * @param path to the model.
     * @return the model associate with the path specified. If no model is associated
     * with a path it returns null.
     */
    protected Model getModel(String path) {
        return this.models.get(path);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy