View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.pppm;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  /**
23   * Specifies which sub-populations the population to be projected consists of.
24   * 
25   * Each sub-population may either be an additive element of the overall
26   * population, or a subtractive.
27   * 
28   * The default configuration corresponds to the (fixed) setup in previous
29   * versions.
30   * 
31   * @author Christina Bohk
32   * @author Roland Ewald
33   */
34  public class SubPopulationModel implements Serializable {
35  
36    /** The Constant serialVersionUID. */
37    private static final long serialVersionUID = 3963551700851569506L;
38  
39    /** The list of sub-populations. */
40    private List<SubPopulation> subPopulations = new ArrayList<>();
41  
42    /** Creates default configuration of sub-populations. */
43    public SubPopulationModel() {
44    }
45  
46    /**
47     * Instantiates a new sub-population model based on existing sub-populations.
48     * 
49     * @param subPopulations
50     *          the sub-populations that determine the model
51     */
52    public SubPopulationModel(List<SubPopulation> subPopulations) {
53      for (SubPopulation subPop : subPopulations)
54        this.subPopulations.add(subPop.newSubPopulation());
55    }
56  
57    /**
58     * Gets the sub-populations.
59     * 
60     * @return the sub populations
61     */
62    public List<SubPopulation> getSubPopulations() {
63      return subPopulations;
64    }
65  
66    /**
67     * Sets the sub-populations.
68     * 
69     * @param subPopulations
70     *          the new sub populations
71     */
72    public void setSubPopulations(List<SubPopulation> subPopulations) {
73      this.subPopulations = subPopulations;
74    }
75  
76    /**
77     * Gets the jump-off populations.
78     * 
79     * @return the jump off populations
80     */
81    public List<SubPopulation> getJumpOffPopulations() {
82      return filterSubPopulationsByProperty(true, null);
83    }
84  
85    /**
86     * Gets the in-flow populations.
87     * 
88     * @return the in flow populations
89     */
90    public List<SubPopulation> getInFlowPopulations() {
91      return filterSubPopulationsByProperty(false, null);
92    }
93  
94    /**
95     * Gets the jump-off populations.
96     * 
97     * @return the jump off populations
98     */
99    public List<SubPopulation> getPopulationsWithoutDescendants() {
100     return filterSubPopulationsByProperty(null, false);
101   }
102 
103   /**
104    * Gets the in-flow populations.
105    * 
106    * @return the in flow populations
107    */
108   public List<SubPopulation> getPopulationsWithDescendants() {
109     return filterSubPopulationsByProperty(null, true);
110   }
111 
112   /**
113    * Filters sub-populations by jump-off flag.
114    * 
115    * @param jumpOff
116    *          the desired state of the jump off flag (null if don't-care)
117    * @param descendants
118    *          the desired state of the descendants flag (null if don't-care)
119    * @return the list of corresponding sub-populations
120    */
121   private List<SubPopulation> filterSubPopulationsByProperty(Boolean jumpOff,
122       Boolean descendants) {
123     List<SubPopulation> subPops = new ArrayList<>();
124     for (SubPopulation subPopulation : subPopulations)
125       if ((jumpOff == null || (subPopulation.isJumpOffPopulation() == jumpOff))
126           && (descendants == null || (subPopulation
127               .isConsistingOfDescendantGenerations() == descendants)))
128         subPops.add(subPopulation);
129     return subPops;
130   }
131 
132 }