Skip to content
Snippets Groups Projects
ConstantCellInitializer.java 801 B
Newer Older
  • Learn to ignore specific revisions
  • Guyslain's avatar
    Guyslain committed
    package model;
    
    import datastruct.Coordinate;
    
    import datastruct.Matrix;
    
    Guyslain's avatar
    Guyslain committed
    import datastruct.MatrixInitializer;
    
    
    /**
     *  An initializer for {@link Matrix} of {@link Cell}s, where each cell is initialized to the
     *  same value.
     *
     * @param <T> the type of content of each cell
     */
    
    Guyslain's avatar
    Guyslain committed
    public class ConstantCellInitializer<T>  implements MatrixInitializer<Cell<T>> {
        private final T defaultValue;
    
    
        /** Make a new {@link MatrixInitializer} with cells containing a {@link Cell} with the same
         * value.
         *
         * @param defaultValue the value stored in each cell.
         */
    
    Guyslain's avatar
    Guyslain committed
        public ConstantCellInitializer(T defaultValue) {
            this.defaultValue = defaultValue;
        }
    
        @Override
        public Cell<T> initialValueAt(Coordinate coordinate) {
            return new Cell<>(defaultValue);
        }
    }