01: /*
02: * This file is part of the GeOxygene project source files.
03: *
04: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
05: * the development and deployment of geographic (GIS) applications. It is a open source
06: * contribution of the COGIT laboratory at the Institut Géographique National (the French
07: * National Mapping Agency).
08: *
09: * See: http://oxygene-project.sourceforge.net
10: *
11: * Copyright (C) 2005 Institut Géographique National
12: *
13: * This library is free software; you can redistribute it and/or modify it under the terms
14: * of the GNU Lesser General Public License as published by the Free Software Foundation;
15: * either version 2.1 of the License, or any later version.
16: *
17: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
18: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser General Public License along with
22: * this library (see file LICENSE if present); if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: *
25: */
26:
27: package fr.ign.cogit.geoxygene.contrib.operateurs;
28:
29: import java.util.ArrayList;
30: import java.util.Iterator;
31: import java.util.List;
32:
33: /** Classe supportant les opérations sur les ensembles
34: * @author Mustiere
35: * @version 1.0
36: */
37: public class Ensemble {
38:
39: private static List combinaisons;
40:
41: /** Renvoie une liste de liste contenant l'ensemble des
42: * combinaisons des éléments de la liste en entrée.
43: * Exemple : si la liste contient A, B, C en entrée ça renvoie :
44: * [[], [A], [A, B], [A, B, C], [A, C], [B], [B, C], [C]]
45: */
46: public static List combinaisons(List listeIN) {
47: combinaisons = new ArrayList();
48: List currentList = new ArrayList();
49: combinaisons.add(currentList);
50: List toBeAddedList = new ArrayList(listeIN);
51: ajouteSuite(currentList, toBeAddedList);
52: return combinaisons;
53: }
54:
55: private static void ajouteSuite(List currentList, List toBeAddedList) {
56: Iterator itToAdd = toBeAddedList.iterator();
57: List copieAjout = new ArrayList(toBeAddedList);
58: while (itToAdd.hasNext()) {
59: Object ajout = itToAdd.next();
60: List nouvelleCombinaison = new ArrayList(currentList);
61: nouvelleCombinaison.add(ajout);
62: combinaisons.add(nouvelleCombinaison);
63: copieAjout.remove(ajout);
64: ajouteSuite(nouvelleCombinaison, copieAjout);
65: }
66: }
67:
68: }
|