001/*- 002 * Copyright 2016 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 datasets with only the second dataset read 014 */ 015public class ContiguousSingleIterator extends BroadcastSelfIterator { 016 private final int aMax; // maximum index in array 017 private final int aStep; // step over items 018 private final int bStep; 019 020 public ContiguousSingleIterator(Dataset a, Dataset b) { 021 super(a, b); 022 aStep = a.getElementsPerItem(); 023 aMax = a.getSize() * aStep; 024 bStep = b.getElementsPerItem(); 025 maxShape = a.getShape(); 026 asDouble = aDataset.hasFloatingPointElements(); 027 reset(); 028 } 029 030 @Override 031 public boolean hasNext() { 032 aIndex += aStep; 033 bIndex += bStep; 034 035 if (aIndex >= aMax) { 036 return false; 037 } 038 if (read) { 039 if (asDouble) { 040 bDouble = bDataset.getElementDoubleAbs(bIndex); 041 } else { 042 bLong = bDataset.getElementLongAbs(bIndex); 043 } 044 } 045 return true; 046 } 047 048 @Override 049 public int[] getPos() { 050 return null; 051 } 052 053 @Override 054 public void reset() { 055 aIndex = -aStep; 056 bIndex = -bStep; 057 if (read) { 058 storeCurrentValues(); 059 } 060 } 061}