    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 * <p>Class to provide iteration through whole data array that backs a dataset</p>
    017 * <p>Instantiate an iterator and use it in a while loop:
    018 * <pre>
    019 *  DoubleDataset ds = DatasetFactory.createLinearSpace(DoubleDataset.class, 0, 10, 0.25);
    020 *  IndexIterator iter = ds.getIterator();
    021 *  double[] data = ds.getData();
    022 *
    023 *  while (iter.hasNext()) {
    024 *      data[iter.index] = 1.2;
    025 *  }
    026 * </pre>
    027 *
    028 */
    029public abstract class IndexIterator {
    030        /**
    031         * Index in array
    032         */
    033        public int index;
    034
    035        /**
    036         * @return true if there is another iteration
    037         */
    038        abstract public boolean hasNext();
    039
    040        /**
    041         * @return position indices (nb this is reference not a copy so avoid changing and can be null)
    042         */
    043        abstract public int[] getPos();
    044
    045        /**
    046         * Reset iterator
    047         */
    048        abstract public void reset();
    049
    050        /**
    051         * @return shape of iterator (can be null, if not known or applicable)
    052         */
    053        public int[] getShape() {
    054                return null;
    055        }
    056}