Here you can find the source of hasDataChanged(List
Parameter | Description |
---|---|
newDatasets | the new list of datasets |
currentModel | the current model |
public static boolean hasDataChanged(List<String> newDatasets, ComboBoxModel<String> currentModel)
//package com.java2s; /*//w w w. jav a2 s . c om * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import javax.swing.ComboBoxModel; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { /** * Checks whether the data has changed and the model needs updating. * * @param newDatasets the new list of datasets * @param currentModel the current model * @return true if changed */ public static boolean hasDataChanged(List<String> newDatasets, ComboBoxModel<String> currentModel) { boolean result; int i; Set<String> setDatasets; Set<String> setModel; setDatasets = new HashSet<>(newDatasets); setModel = new HashSet<>(); for (i = 0; i < currentModel.getSize(); i++) setModel.add(currentModel.getElementAt(i)); // different datasets? result = (setDatasets.size() != setModel.size()) || !(setDatasets.containsAll(setModel) && setModel.containsAll(setDatasets)); // different order? if (!result) { for (i = 0; i < newDatasets.size(); i++) { if (!newDatasets.get(i).equals(currentModel.getElementAt(i))) { result = true; break; } } } return result; } }