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

nl._42.jarb.populate.DatabasePopulatorChain Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
package nl._42.jarb.populate;

import java.util.Collection;
import java.util.LinkedList;

/**
 * Chain of database populators, executes the population in sequence.
 *
 * @author Jeroen van Schagen
 * @since Apr 10, 2015
 */
public class DatabasePopulatorChain implements DatabasePopulator {

    /**
     * Delegate database populate elements.
     */
    private Collection populators = new LinkedList();
    
    public DatabasePopulatorChain() {
        // Do nothing
    }
    
    public DatabasePopulatorChain(DatabasePopulator populator) {
        this.populators.add(populator);
    }

    public DatabasePopulatorChain(Collection populators) {
        this.populators.addAll(populators);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public void execute() {
        for (DatabasePopulator populator : populators) {
            populator.execute();
        }
    }
    
    /**
     * Add another populate to this chain.
     * 
     * @param populator the populate to add
     * @return {@code this} instance for chaining
     */
    public DatabasePopulatorChain add(DatabasePopulator populator) {
        populators.add(populator);
        return this;
    }

    /**
     * Checks if the chain is empty.
     * 
     * @return {@code true} if empty
     */
    public boolean isEmpty() {
        return populators.isEmpty();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy