View Javadoc
1   /*
2    * Copyright (C) 2019 uwe
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.sw4j.sample.memory.heap;
18  
19  /**
20   * This class represents either a valid configuration or an error. If the method {@link #hasValues()} returns
21   * {@code true} a valid configuration is available and the error text is empty. If the method {@link #hasValues()}
22   * returns {@code false} then the error text is filled with a message that should be presented to the user and all
23   * values are set to {@code 0}.
24   *
25   * @author Uwe Plonus &lt;u.plonus@gmail.com&gt;
26   */
27  public class PossibleConfiguration {
28  
29      private final boolean hasValues;
30  
31      private final int blockSize;
32  
33      private final int create;
34  
35      private final int shortLifetime;
36  
37      private final int mediumLifetime;
38  
39      private final int longLifetime;
40  
41      private final double longProbability;
42  
43      private final double mediumProbability;
44  
45      private final String message;
46  
47      public PossibleConfiguration(int blockSize, int create, int shortLifetime, int mediumLifetime, int longLifetime,
48              double mediumProbability, double longProbability) {
49          this.hasValues = true;
50          this.blockSize = blockSize;
51          this.create = create;
52          this.shortLifetime = shortLifetime;
53          this.mediumLifetime = mediumLifetime;
54          this.longLifetime = longLifetime;
55          this.mediumProbability = mediumProbability;
56          this.longProbability = longProbability;
57          this.message = "";
58      }
59  
60      public PossibleConfiguration(String message) {
61          this.hasValues = false;
62          this.blockSize = 0;
63          this.create = 0;
64          this.shortLifetime = 0;
65          this.mediumLifetime = 0;
66          this.longLifetime = 0;
67          this.mediumProbability = 0.0;
68          this.longProbability = 0.0;
69          this.message = message;
70      }
71  
72      public boolean hasValues() {
73          return hasValues;
74      }
75  
76      public int getBlockSize() {
77          return blockSize;
78      }
79  
80      public int getCreate() {
81          return create;
82      }
83  
84      public int getShortLifetime() {
85          return shortLifetime;
86      }
87  
88      public int getMediumLifetime() {
89          return mediumLifetime;
90      }
91  
92      public int getLongLifetime() {
93          return longLifetime;
94      }
95  
96      public double getMediumProbability() {
97          return mediumProbability;
98      }
99  
100     public double getLongProbability() {
101         return longProbability;
102     }
103 
104     public String getMessage() {
105         return message;
106     }
107 
108 }