001/*
002        AUTOMATICALLY GENERATED BY jTemp FROM
003        /Users/jsh2/Work/openimaj/target/checkout/core/core/src/main/jtemp/org/openimaj/util/iterator/Uniform#T#RangeIterable.jtemp
004*/
005/**
006 * Copyright (c) 2011, The University of Southampton and the individual contributors.
007 * All rights reserved.
008 *
009 * Redistribution and use in source and binary forms, with or without modification,
010 * are permitted provided that the following conditions are met:
011 *
012 *   *  Redistributions of source code must retain the above copyright notice,
013 *      this list of conditions and the following disclaimer.
014 *
015 *   *  Redistributions in binary form must reproduce the above copyright notice,
016 *      this list of conditions and the following disclaimer in the documentation
017 *      and/or other materials provided with the distribution.
018 *
019 *   *  Neither the name of the University of Southampton nor the names of its
020 *      contributors may be used to endorse or promote products derived from this
021 *      software without specific prior written permission.
022 *
023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
024 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
025 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
027 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
028 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
030 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
032 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033 */
034package org.openimaj.util.iterator;
035
036import java.util.Iterator;
037
038/**
039 * Numeric range iterator for short types. A range goes from 
040 * a number <code>start</code> (inclusive) to another number 
041 * <code>stop</code> (exclusive). There is an optional step
042 * size. 
043 * 
044 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
045 */
046public class UniformShortRangeIterable implements NumericIterable<Short> {
047        private short stop;
048        private short step;
049        private short current;
050        
051        /**
052         * Construct a UniformShortRangeIterator with the given values
053         * @param start the starting value (inclusive)
054         * @param stop the stopping number (exclusive)
055         * @param step the step size
056         */
057        public UniformShortRangeIterable(short start, short stop, short step) {
058                this.stop = stop;
059                this.step = step;
060                this.current = start;
061        }
062        /**
063         * Construct a UniformShortRangeIterator with the given values
064         *
065         * @param start the starting value (inclusive)
066         * @param stop the stopping number (exclusive)
067         */
068        public UniformShortRangeIterable(short start, short stop) {
069                this(start, stop, (short)1);
070        }
071        
072        @Override
073        public Iterator<Short> iterator() {
074                return new Iterator<Short>() {
075
076                        @Override
077                        public boolean hasNext() {
078                                return (current + step <= stop);
079                        }
080
081                        @Override
082                        public Short next() {
083                                short ret = current;
084                                current += step;
085                                return ret;
086                        }
087
088                        @Override
089                        public void remove() {
090                                throw new UnsupportedOperationException( "Not supported" );
091                        }
092                };
093        }
094}