    001/*-
    002 *******************************************************************************
    003 * Copyright (c) 2011, 2016 Diamond Light Source Ltd.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the Eclipse Public License v1.0
    006 * which accompanies this distribution, and is available at
    007 * http://www.eclipse.org/legal/epl-v10.html
    008 *
    009 * Contributors:
    010 *    Peter Chang - initial API and implementation and/or initial documentation
    011 *******************************************************************************/
    012
    013package org.eclipse.january.dataset;
    014
    015/**
    016 * Class to run over contiguous datasets
    017 */
    018public class ContiguousIterator extends IndexIterator {
    019        final private int imax; // maximum index in array
    020        final private int istep; // step over items
    021        final private int element;
    022
    023        /**
    024         * Constructor for an iterator over the items of a contiguous dataset that are
    025         * within the dimensions
    026         *
    027         * @param length of entire data array
    028         */
    029        public ContiguousIterator(final int length) {
    030                this(length, 1);
    031        }
    032
    033        /**
    034         * Constructor for an iterator over the items of a contiguous dataset that are
    035         * within the dimensions
    036         *
    037         * @param length of entire data array
    038         * @param isize number of elements in an item
    039         */
    040        public ContiguousIterator(final int length, final int isize) {
    041                this(length, isize, 0);
    042        }
    043
    044        /**
    045         * Constructor for an iterator over the items of a contiguous dataset that are
    046         * within the dimensions
    047         *
    048         * @param length of entire data array
    049         * @param isize number of elements in an item
    050         * @param element element to start with (for compound datasets)
    051         */
    052        public ContiguousIterator(final int length, final int isize, final int element) {
    053                istep = isize;
    054                index = -istep + element;
    055                imax = length*isize;
    056                this.element = element;
    057        }
    058
    059        @Override
    060        public boolean hasNext() {
    061                index += istep;
    062                return index < imax;
    063        }
    064
    065        @Override
    066        public int[] getPos() {
    067                return null;
    068        }
    069
    070        @Override
    071        public void reset() {
    072                index = -istep + element;
    073        }
    074}