001/*- 002 * Copyright 2015, 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 012import java.util.Arrays; 013 014/** 015 * Checks whether shape has changed between waits. Useful for where datasets are being extended. 016 * Note, {@link LazyDynamicDataset} already alerts its listeners when its shape is resized 017 */ 018public class ShapeChangeChecker implements IDatasetChangeChecker { 019 020 private ILazyDataset lazy; 021 private int[] shape; 022 023 @Override 024 public void setDataset(ILazyDataset dataset) { 025 if (dataset == null) { 026 throw new IllegalArgumentException("Dataset must not be null"); 027 } 028 lazy = dataset; 029 shape = lazy.getShape(); 030 } 031 032 @Override 033 public boolean check() { 034 int[] cshape = lazy.getShape(); 035 if (Arrays.equals(shape, cshape)) { 036 return false; 037 } 038 shape = cshape; 039 return true; 040 } 041}