@@ -0,0 +1,1839 @@
+/*-%0A * Copyright 2017 Diamond Light Source Ltd.%0A *%0A * All rights reserved. This program and the accompanying materials%0A * are made available under the terms of the Eclipse Public License v1.0%0A * which accompanies this distribution, and is available at%0A * http://www.eclipse.org/legal/epl-v10.html%0A */%0A%0Apackage org.eclipse.dawnsci.analysis.dataset;%0A%0Aimport java.lang.ref.SoftReference;%0Aimport java.util.IdentityHashMap;%0Aimport java.util.Map;%0A%0Aimport org.eclipse.dawnsci.analysis.dataset.impl.function.DatasetToDatasetFunction;%0Aimport org.eclipse.january.dataset.Dataset;%0Aimport org.eclipse.january.dataset.DatasetUtils;%0Aimport org.eclipse.january.dataset.IDataset;%0A%0A/**%0A * Cache of computed dataset values%0A */%0Apublic class DatasetCache %7B%0A%0A%09private DatasetToDatasetFunction function;%0A%09private Map%3CIDataset, SoftReference%3CDataset%3E%3E map;%0A%0A%09/**%0A%09 * Create a cache for given function%0A%09 * @param function%0A%09 */%0A%09public DatasetCache(DatasetToDatasetFunction function) %7B%0A%09%09this.function = function;%0A%09%09map = new IdentityHashMap%3CIDataset, SoftReference%3CDataset%3E%3E();%0A%09%7D%0A%0A%09/**%0A%09 * Retrieve computed value (evaluate if not cached)%0A%09 * @param input%0A%09 * @return computed value%0A%09 */%0A%09public Dataset get(IDataset input) %7B%0A%09%09SoftReference%3CDataset%3E ref = map.get(input);%0A%09%09Dataset output;%0A%09%09if (ref == null %7C%7C ref.get() == null) %7B%0A%09%09%09output = DatasetUtils.convertToDataset(function.value(input).get(0));%0A%09%09%09map.put(input, new SoftReference%3CDataset%3E(output));%0A%09%09%7D else %7B%0A%09%09%09output = ref.get();%0A%09%09%7D%0A%09%09return output;%0A%09%7D%0A%0A%09/**%0A%09 * Remove entry from cache%0A%09 * @param input%0A%09 * @return true if was cached%0A%09 */%0A%09public boolean remove(Dataset input) %7B%0A%09%09SoftReference%3CDataset%3E ref = map.remove(input);%0A%09%09if (ref == null %7C%7C ref.get() == null) %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%09ref.clear();%0A%09%09return true;%0A%09%7D%0A%0A%09/**%0A%09 * Clear cache%0A%09 */%0A%09public void clear() %7B%0A%09%09map.clear();%0A%09%7D%0A%7D%0A

Add new cache to store computed datasets