001/*-
002 * Copyright 2022 Diamond Light Source Ltd.
003 *
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
010package org.eclipse.january.dataset;
011
012/**
013 * Class to run over a pair of contiguous and elemental datasets with only the second dataset read
014 * @since 2.3
015 */
016public class ContiguousSingleIteratorElemental extends BroadcastSelfIterator {
017        private final int aMax; // maximum index in array
018
019        public ContiguousSingleIteratorElemental(Dataset a, Dataset b) {
020                super(a, b);
021                aMax = a.getSize();
022                maxShape = a.getShape();
023                asDouble = aDataset.hasFloatingPointElements();
024                reset();
025        }
026
027        @Override
028        public boolean hasNext() {
029                aIndex++;
030                bIndex = aIndex;
031                if (aIndex >= aMax) {
032                        return false;
033                }
034                if (read) {
035                        if (asDouble) {
036                                bDouble = bDataset.getElementDoubleAbs(aIndex);
037                        } else {
038                                bLong = bDataset.getElementLongAbs(aIndex);
039                        }
040                }
041                return true;
042        }
043
044        @Override
045        public int[] getPos() {
046                return null;
047        }
048
049        @Override
050        public void reset() {
051                aIndex = -1;
052                bIndex = -1;
053                if (read) {
054                        storeCurrentValues();
055                }
056        }
057}