    001/*-
    002 *******************************************************************************
    003 * Copyright (c) 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 a broadcasted single-item dataset
    017 */
    018public class SingleItemIterator extends IndexIterator {
    019        final private int size;
    020        final private int offset;
    021        private int i;
    022
    023        /**
    024         * Constructor for an iterator over single item that will be broadcast over
    025         * given size of broadcast shape
    026         * @param offset offset to single item
    027         * @param size size of dataset
    028         */
    029        public SingleItemIterator(final int offset, final int size) {
    030                this.size = size;
    031                this.offset = offset;
    032                reset();
    033        }
    034
    035        @Override
    036        public boolean hasNext() {
    037                return i++ < size;
    038        }
    039
    040        @Override
    041        public int[] getPos() {
    042                return null;
    043        }
    044
    045        @Override
    046        public void reset() {
    047                index = offset;
    048                i = 0;
    049        }
    050}