Author: chatellier Date: 2011-03-22 14:40:09 +0000 (Tue, 22 Mar 2011) New Revision: 3189 Log: Fix javadoc and move FactorGroup to parent package Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/FactorGroup.java Removed: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/group/ Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/DesignPlan.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/Factor.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/RuleDomain.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/DesignPlan.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/DesignPlan.java 2011-03-22 14:39:17 UTC (rev 3188) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/DesignPlan.java 2011-03-22 14:40:09 UTC (rev 3189) @@ -68,7 +68,7 @@ /** * Add factor. * - * @param e factor to add + * @param f factor to add * @return {@code true} if factor has been added * @see java.util.List#add(java.lang.Object) */ Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/Factor.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/Factor.java 2011-03-22 14:39:17 UTC (rev 3188) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/Factor.java 2011-03-22 14:40:09 UTC (rev 3189) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2009 - 2010 Ifremer, CodeLutin + * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -34,9 +34,6 @@ /** * Facteur de variation des parametres de simulation. * - * @param <E> type des valeurs gérées par le facteur - * @param <F> type des labels - * * La classe doit être {@link Serializable} avec ses valeurs pour permettre * l'export XML. * Copied: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/FactorGroup.java (from rev 3148, isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/group/FactorGroup.java) =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/FactorGroup.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/FactorGroup.java 2011-03-22 14:40:09 UTC (rev 3189) @@ -0,0 +1,269 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric + * %% + * 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 2 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/gpl-2.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.simulator.sensitivity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; +import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; + +/** + * Factor group. Used for group screening. + * + * A factor mixed can accept both discrete and continuous factors (used + * for convenience : factor tree root). + * + * A factor group without factors is untyped. + * + * @author chatellier + * @version $Revision$ + * + * @since 3.3.1.0 + * + * Last update : $Date$ + * By : $Author$ + */ +public class FactorGroup extends Factor { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1893573810633639712L; + + /** Factors collection. */ + protected List<Factor> factors; + + protected static class FactorComparator implements Comparator<Factor> { + @Override + public int compare(Factor o1, Factor o2) { + int result = 1; + + if (o1 instanceof FactorGroup) { + if (o2 instanceof FactorGroup) { + result = o1.getName().compareTo(o2.getName()); + } + else { + result = -1; + } + } + else { // factor + if (o2 instanceof Factor) { + result = o1.getName().compareTo(o2.getName()); + } + } + return result; + } + }; + + /** + * Mixed factor composition. + * + * Default to false; + * + * To enable both {@link DiscreteDomain} and {@link ContinuousDomain} in current group. + * Currently used in UI to use it as tree root and drag'n'drop. + */ + protected boolean mixed; + + /** + * Init factor group. + * + * @param name group name + * @param mixed mixed property + */ + public FactorGroup(String name, boolean mixed) { + super(name); + this.mixed = mixed; + factors = new ArrayList<Factor>(); + } + + /** + * Init factor group. + * + * @param name group name + */ + public FactorGroup(String name) { + this(name, false); + } + + /** + * Add all checked factors. + * + * @param allFactors factors to add + */ + public void addAllFactors(List<Factor> allFactors) { + for (Factor factor : allFactors) { + // check all factors to add are from same types + checkFactor(allFactors, factor); + // add factors to add are from same type as current + checkFactor(factors, factor); + } + + factors.addAll(allFactors); + + // sort : factor group, by name, and factor by name + Collections.sort(factors, new FactorComparator()); + } + + /** + * Check factor type and add it into factor collection. + * + * @param factor + */ + public void addFactor(Factor factor) { + // if mixed enabled, don't check + if (!mixed) { + checkFactor(factors, factor); + } + + factors.add(factor); + + // sort : factor group, by name, and factor by name + Collections.sort(factors, new FactorComparator()); + } + + /** + * Check factor type with other factor collection types. + * + * @param factorsList factors list to check + * @param factor factor to check + * @throws IllegalArgumentException if factor doesn't match other factor type + */ + protected void checkFactor(List<Factor> factorsList, Factor factor) { + // basiquement, il doit être du même type que le + // premier element + if (factor.getDomain() == null) { + throw new IllegalArgumentException("Factor domain is null"); + } + + // on va dire, que si c'est le premier, il est du meme + // type que lui meme + if (!factorsList.isEmpty()) { + Factor first = factorsList.get(0); + + // les deux sont discret ou continue + if ((first.getDomain() instanceof DiscreteDomain && !(factor.getDomain() instanceof DiscreteDomain)) || + (first.getDomain() instanceof ContinuousDomain && !(factor.getDomain() instanceof ContinuousDomain))) { + throw new IllegalArgumentException( + "Factor type is not in same type as other factor in group"); + } + } + } + + /** + * Remove factors collection. + * + * @param allFactors factors to remove + */ + public void removeAll(Collection<Factor> allFactors) { + factors.removeAll(allFactors); + } + + /** + * Get groups factors. + * + * @return unmodifiable factors list + */ + public List<Factor> getFactors() { + return Collections.unmodifiableList(factors); + } + + /** + * Convenient method to access specific factor. + * + * @param index index + * @return factor at index + */ + public Factor get(int index) { + return factors.get(index); + } + + /** + * Get factor list size. + * + * @return factor list size + */ + public int size() { + return factors.size(); + } + + /** + * Returns the index of the first occurrence of the specified element in this + * group. + * @param o element to search for + * @return the index of the first occurrence of the specified element in this + * group, or -1 if this list does not contain the element + */ + public int indexOf(Object o) { + return factors.indexOf(o); + } + + /** + * Return {@code true} if factor group is mixed. + * + * @return {@code true} if factor group is mixed + */ + public boolean isMixed() { + return mixed; + } + + /** + * Return {@code true} if factor group has at least one factor + * and this factor is discrete. + * + * @return {@code true} if factor group is discrete + */ + public boolean isDiscrete() { + boolean result = false; + if (!factors.isEmpty()) { + Domain domain = factors.get(0).getDomain(); + result = domain instanceof DiscreteDomain; + } + return result; + } + + /** + * Return {@code true} if factor group has at least one factor + * and this factor is continuous. + * + * @return {@code true} if factor group is continuous + */ + public boolean isContinuous() { + boolean result = false; + if (!factors.isEmpty()) { + Domain domain = factors.get(0).getDomain(); + result = domain instanceof ContinuousDomain; + } + return result; + } + + @Override + public String toString() { + return "FactorGroup(" + name + ")"; + } +} Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/RuleDomain.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/RuleDomain.java 2011-03-22 14:39:17 UTC (rev 3188) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/simulator/sensitivity/domain/RuleDomain.java 2011-03-22 14:40:09 UTC (rev 3189) @@ -1,20 +1,27 @@ -/* *##% - * Copyright (C) 2010 Ifremer, Code Lutin, Chatellier Eric - * - * 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 2 - * of the License, or (at your option) any later version. - * +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric + * %% + * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ package fr.ifremer.isisfish.simulator.sensitivity.domain;