-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDividerResults.java
109 lines (96 loc) · 2.86 KB
/
DividerResults.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package VoltageDiv;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Contains all results of the {@link Divider.findResistors} method.
*
* @author Berthold
* <p>
*
* Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA
* 4.0)
*
*/
public class DividerResults {
private boolean hasResult;
private double inputVoltage_V, outputVoltage_V;
private List<DividerResult> listOfResults;
private Long timeItTookIn_ms;
/**
* Contains any results found by the {@link Divider.findResistors} method.
*
* @param inutVoltage_V The input voltage for the divider in volts.
* @param outputVoltage_V The output voltage in volts.
* @param inputVoltage_V
*/
public DividerResults(double inputVoltage_V, double outputVoltage_V) {
listOfResults = new ArrayList<>();
hasResult = false;
this.inputVoltage_V = inputVoltage_V;
this.outputVoltage_V = outputVoltage_V;
}
/**
* Adds one result to this instance.
*
* @param dividerResult Instance of the {@link DivederResult} class.
*/
public void addResult(DividerResult dividerResult) {
this.listOfResults.add(dividerResult);
hasResult = true;
}
/**
* Gets the list of results.
*
* @return A {@link List} of results of a calculated voltage divider containing
* one or more instances of {@link DividerResult}.<br>
* The list is sorted by the error between calculated output voltage
* resulting from the chosen resistors and the output voltage wished.
* <p>
* R1 and R2 with smallest resulting error in output voltage is the
* first element in this list.
*
*/
public List<DividerResult> getListOfResults() {
Collections.sort(listOfResults);
return listOfResults;
}
/**
* Return the solution with the smallest error in output voltage. Since the list
* is in ascending order, the first element is returned.
*
* @return A instance of {@link DividerResult} with the smallest error in output
* voltage
*/
public DividerResult getSolutionWsmallestErrInOutputVoltage() {
return this.listOfResults.get(0);
}
/**
* Flag declaring if this instance contains at least one result.
*
*
* @return True if at least one instance of {@link DividerResult} was added to
* this instance. False if not.
*/
public boolean hasResult() {
return hasResult;
}
public double getInputVoltage_V() {
return inputVoltage_V;
}
public void setInputVoltage_V(double inputVoltage_V) {
this.inputVoltage_V = inputVoltage_V;
}
public double getOutputVoltage_V() {
return outputVoltage_V;
}
public void setOutputVoltage_V(double outputVoltage_V) {
this.outputVoltage_V = outputVoltage_V;
}
public Long getTimeItTookIn_ms() {
return timeItTookIn_ms;
}
public void setTimeItTookIn_ms(Long timeItTookIn_s) {
this.timeItTookIn_ms = timeItTookIn_s;
}
}