@@ -0,0 +1,2467 @@
+/*%0A * Copyright 2006-2020 The MZmine Development Team%0A *%0A * This file is part of MZmine.%0A *%0A * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU%0A * General Public License as published by the Free Software Foundation; either version 2 of the%0A * License, or (at your option) any later version.%0A *%0A * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even%0A * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General%0A * Public License for more details.%0A *%0A * You should have received a copy of the GNU General Public License along with MZmine; if not,%0A * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA%0A */%0A%0Apackage io.github.mzmine.util;%0A%0Aimport io.github.mzmine.datamodel.features.FeatureList;%0Aimport io.github.mzmine.datamodel.features.FeatureListRow;%0Aimport it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;%0Aimport javax.annotation.Nonnull;%0Aimport javax.annotation.Nullable;%0A%0A/**%0A * This cache reduces the number of indexOf queries in feature lists when accessing %7B@link%0A * FeatureListRow%7Ds via their getID(). Use this method if rows might be accessed multiple times. In%0A * cases where many features are accessed use the %7B@link #preCacheRowIds%7D method to initialize a map%0A * of all rows and their IDs%0A *%0A * @author Robin Schmid (https://github.com/robinschmid)%0A */%0Apublic class FeatureListRowIdCache %7B%0A%0A  @Nonnull%0A  private final FeatureList featureList;%0A  private final Int2ObjectOpenHashMap%3CFeatureListRow%3E idRowCache = new Int2ObjectOpenHashMap%3C%3E();%0A%0A  public FeatureListRowIdCache(@Nonnull FeatureList featureList) %7B%0A    this.featureList = featureList;%0A  %7D%0A%0A  /**%0A   * Retrieves rows from a feature list in a cached way%0A   *%0A   * @param rowID the row id%0A   * @return the row or null if no row with this ID is present in the feature list%0A   */%0A  @Nullable%0A  public FeatureListRow get(int rowID) %7B%0A    return idRowCache.computeIfAbsent(rowID, featureList::findRowByID);%0A  %7D%0A%0A  /**%0A   * Initialize a map of row -%3E rowID for all rows in the feature list to improve the speed of%0A   * accessing rows by their IDs%0A   */%0A  public void preCacheRowIds() %7B%0A    for (FeatureListRow row : featureList.getRows()) %7B%0A      idRowCache.put(row.getID(), row);%0A    %7D%0A  %7D%0A%0A  /**%0A   * @return the underlying feature list%0A   */%0A  @Nonnull%0A  public FeatureList getFeatureList() %7B%0A    return featureList;%0A  %7D%0A%7D%0A

Add FeatureListRowIdCache to cache or map row ids for fast access of rows