Skip to content

Commit b59a379

Browse files
author
Daniel Purtov
committed
Update to documentation and refactoring
1 parent 470dac7 commit b59a379

13 files changed

Lines changed: 222 additions & 251 deletions

File tree

src/main/java/com/danielptv/simplex/entity/Phase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.danielptv.simplex.entity;
22

33
import com.danielptv.simplex.number.CalculableImpl;
4-
import com.danielptv.simplex.presentation.OutputUtils;
54
import lombok.NonNull;
65

76
import java.util.List;
87
import java.util.stream.IntStream;
98

109
import static com.danielptv.simplex.presentation.OutputUtils.FONT_GREEN;
1110
import static com.danielptv.simplex.presentation.OutputUtils.STYLE_RESET;
11+
import static com.danielptv.simplex.presentation.OutputUtils.accentuatePivot;
1212

1313
/**
1414
* Entity-Class representing a phase of the Two-Phase-Simplex Method.
@@ -25,7 +25,7 @@ public record Phase<T extends CalculableImpl<T>>(
2525
) {
2626

2727
/**
28-
* Method for getting the last table of the phase.
28+
* Get the last table of the phase.
2929
*
3030
* @return The last table.
3131
*/
@@ -36,7 +36,7 @@ public Table<T> getLastTable() {
3636
@Override
3737
public String toString() {
3838
IntStream.range(0, tables.size() - 1)
39-
.forEach(i -> OutputUtils.accentuatePivot(tables.get(i)));
39+
.forEach(i -> accentuatePivot(tables.get(i)));
4040

4141
final var sb = new StringBuilder();
4242
sb.append(" ");

src/main/java/com/danielptv/simplex/entity/Row.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public Row(@NonNull final Row<T> row) {
5757
}
5858

5959
/**
60-
* Method for inverting a Row.
60+
* Invert a row.
6161
*
62-
* @return The inverted Row.
62+
* @return The inverted row.
6363
*/
6464
public Row<T> invertRow() {
6565
return new Row<>(entries.stream()
@@ -68,11 +68,11 @@ public Row<T> invertRow() {
6868
}
6969

7070
/**
71-
* Method for multiplying a Row.
71+
* Multiply a row.
7272
*
7373
* @param row A row.
7474
* @param factor The factor.
75-
* @return The multiplied Row.
75+
* @return The multiplied row.
7676
*/
7777
public Row<T> multiplyRow(@NonNull final Row<T> row, @NonNull final T factor) {
7878
return new Row<>(row.entries.stream()
@@ -81,10 +81,10 @@ public Row<T> multiplyRow(@NonNull final Row<T> row, @NonNull final T factor) {
8181
}
8282

8383
/**
84-
* Method for dividing a Row.
84+
* Divide a row.
8585
*
8686
* @param divisor The divisor.
87-
* @return The divided Row.
87+
* @return The divided row.
8888
*/
8989
public Row<T> divideRow(@NonNull final T divisor) {
9090
return new Row<>(entries.stream()
@@ -98,10 +98,10 @@ public Row<T> divideRow(@NonNull final T divisor) {
9898
}
9999

100100
/**
101-
* Method for adding two Rows.
101+
* Add two rows.
102102
*
103-
* @param addends A Row.
104-
* @return The resulting Row.
103+
* @param addends A row.
104+
* @return The resulting row.
105105
*/
106106
public Row<T> addRow(@NonNull final Row<T> addends) {
107107
if (addends.entries.size() != entries.size()) {
@@ -114,7 +114,7 @@ public Row<T> addRow(@NonNull final Row<T> addends) {
114114
}
115115

116116
/**
117-
* Method for adding a value to a Row.
117+
* Add a value to a row.
118118
*
119119
* @param entry String representation of the value to be added.
120120
*/
@@ -123,7 +123,7 @@ public void addVal(@NonNull final String entry) {
123123
}
124124

125125
/**
126-
* Method for determining if all entries are positive.
126+
* Determine if all entries are positive.
127127
*
128128
* @return True if all entries are positive, else false.
129129
*/
@@ -132,7 +132,7 @@ public boolean isPositive() {
132132
}
133133

134134
/**
135-
* Method for getting the index of the smallest value.
135+
* Get the index of the smallest value.
136136
*
137137
* @return The index.
138138
*/
@@ -142,7 +142,7 @@ public Integer getMinIndex() {
142142
}
143143

144144
/**
145-
* Method for getting an entry by its index.
145+
* Get an entry by its index.
146146
*
147147
* @param index The index.
148148
* @return The entry.
@@ -172,7 +172,7 @@ public String toString() {
172172
}
173173

174174
/**
175-
* Method for setting the entry widths.
175+
* Set the entry widths.
176176
*/
177177
public void setEntryWidths() {
178178
entryWidths = new ArrayList<>(entries.stream().map(entry -> Math.max(entry.toString().length(), 2))

src/main/java/com/danielptv/simplex/entity/Table.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,68 @@
1212
* @param inst Instance of the number type to be calculated with.
1313
* @param title Title of the table.
1414
* @param lHS Left-hand side of the table.
15-
* @param extendedLHS Extended left-hand side of the table.
1615
* @param rHS Right-hand side of the table.
1716
* @param pivot Pivot element.
1817
* @param columnHeaders Column headers.
1918
* @param rowHeaders Row headers.
20-
* @param extensionSize Size of extended left-hand side.
19+
* @param rows Number of rows.
20+
* @param columns Total number of columns.
21+
* @param helperColumns Number of helper columns.
2122
* @param <T> Fraction or RoundedDecimal.
2223
*/
2324
@SuppressWarnings("RecordComponentNumber")
2425
public record Table<T extends CalculableImpl<T>>(
2526
@NonNull T inst,
2627
@NonNull String title,
2728
@NonNull List<Row<T>> lHS,
28-
List<Row<T>> extendedLHS,
2929
@NonNull List<T> rHS,
3030
@NonNull Pivot<T> pivot,
3131
@NonNull List<String> columnHeaders,
3232
@NonNull List<String> rowHeaders,
33-
int extensionSize
33+
int rows,
34+
int columns,
35+
int helperColumns
3436
) {
37+
/**
38+
* Constructor for a table.
39+
*
40+
* @param inst Instance of the number type to be calculated with.
41+
* @param title Title of the table.
42+
* @param lHS Left-hand side of the table.
43+
* @param rHS Right-hand side of the table.
44+
* @param pivot Pivot element.
45+
* @param columnHeaders Column headers.
46+
* @param rowHeaders Row headers.
47+
* @param helperColumns Number of helper columns.
48+
*/
49+
@SuppressWarnings("ParameterNumber")
50+
public Table(
51+
@NonNull final T inst,
52+
@NonNull final String title,
53+
@NonNull final List<Row<T>> lHS,
54+
@NonNull final List<T> rHS,
55+
@NonNull final Pivot<T> pivot,
56+
@NonNull final List<String> columnHeaders,
57+
@NonNull final List<String> rowHeaders,
58+
final int helperColumns
59+
) {
60+
this(
61+
inst,
62+
title,
63+
lHS,
64+
rHS,
65+
pivot,
66+
columnHeaders,
67+
rowHeaders,
68+
lHS.size(),
69+
lHS.get(0).getEntries().size(),
70+
helperColumns
71+
);
72+
73+
}
3574

3675
/**
37-
* Constructor for a Table.
76+
* Copy-Constructor for a Table.
3877
*
3978
* @param table A Table.
4079
* @param title The new table title.
@@ -44,12 +83,13 @@ public Table(@NonNull final Table<T> table, @NonNull final String title) {
4483
table.inst,
4584
title,
4685
table.lHS,
47-
table.extendedLHS,
4886
table.rHS,
4987
table.pivot,
5088
table.columnHeaders,
5189
table.rowHeaders,
52-
table.extensionSize
90+
table.rows,
91+
table.columns,
92+
table.helperColumns
5393
);
5494
}
5595

src/main/java/com/danielptv/simplex/number/CalculableImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,54 @@
99
*/
1010
public interface CalculableImpl<T extends CalculableImpl<T>> extends Comparable<T> {
1111
/**
12-
* Method for multiplication.
12+
* Multiply two values.
1313
*
1414
* @param c Fraction or RoundedDecimal.
1515
* @return Fraction or RoundedDecimal.
1616
*/
1717
T multiply(T c);
1818

1919
/**
20-
* Method for division.
20+
* Divide two values.
2121
*
2222
* @param c Fraction or RoundedDecimal.
2323
* @return Fraction or RoundedDecimal.
2424
*/
2525
T divide(T c);
2626

2727
/**
28-
* Method for addition.
28+
* Add two values.
2929
*
3030
* @param c Fraction or RoundedDecimal.
3131
* @return Fraction or RoundedDecimal.
3232
*/
3333
T add(T c);
3434

3535
/**
36-
* Method for creating new Fraction or RoundedDecimal from an existing one.
36+
* Create a new Fraction or RoundedDecimal from an existing one.
3737
*
3838
* @param s String representation of the number.
3939
* @return Fraction or RoundedDecimal.
4040
*/
4141
T create(String s);
4242

4343
/**
44-
* Method for getting the value as BigDecimal.
44+
* Get the value as BigDecimal.
4545
*
4646
* @return The value as BigDecimal.
4747
*/
4848
BigDecimal toDecimal();
4949

5050
/**
51-
* Method for setting the value of a number to infinity.
51+
* Set the value to infinity.
5252
*
5353
* @param infinityType Positive or negative infinity.
5454
* @return Infinity.
5555
*/
5656
T toInfinity(InfinityType infinityType);
5757

5858
/**
59-
* Method for determining whether a number is infinite.
59+
* Determine whether a value is infinite.
6060
*
6161
* @return True if infinite else false.
6262
*/

src/main/java/com/danielptv/simplex/number/Fraction.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private Fraction(@NonNull final InfinityType infinityType) {
9090
}
9191

9292
/**
93-
* Method for multiplying two Fractions.
93+
* Multiply two Fractions.
9494
*
9595
* @param f A Fraction.
9696
* @return The multiplied Fraction.
@@ -101,7 +101,7 @@ public Fraction multiply(@NonNull final Fraction f) {
101101
}
102102

103103
/**
104-
* Method for dividing two Fractions.
104+
* Divide two Fractions.
105105
*
106106
* @param f A Fraction.
107107
* @return The divided Fraction.
@@ -112,7 +112,7 @@ public Fraction divide(@NonNull final Fraction f) {
112112
}
113113

114114
/**
115-
* Method for adding two Fractions.
115+
* Add two Fractions.
116116
*
117117
* @param f A Fraction.
118118
* @return The added Fraction.
@@ -124,7 +124,7 @@ public Fraction add(@NonNull final Fraction f) {
124124
}
125125

126126
/**
127-
* Method for creating a new Fraction from an existing one.
127+
* Create a new Fraction from an existing one.
128128
*
129129
* @param s String representation of the number.
130130
* @return The new Fraction.
@@ -135,7 +135,7 @@ public Fraction create(@NonNull final String s) {
135135
}
136136

137137
/**
138-
* Method for getting the value as BigDecimal.
138+
* Get the value as BigDecimal.
139139
*
140140
* @return The value as BigDecimal rounded to 2 decimal places.
141141
*/
@@ -190,13 +190,6 @@ public String toString() {
190190
return numerator.abs() + "/" + denominator.abs();
191191
}
192192

193-
/**
194-
* Method for simplifying Fractions.
195-
*
196-
* @param num The numerator.
197-
* @param denom The denominator.
198-
* @return The simplified Fraction.
199-
*/
200193
private Pair<BigInteger, BigInteger> simplify(@NonNull final BigInteger num, @NonNull final BigInteger denom) {
201194

202195
if (num.equals(new BigInteger("0"))) {
@@ -215,13 +208,6 @@ private Pair<BigInteger, BigInteger> simplify(@NonNull final BigInteger num, @No
215208
return result;
216209
}
217210

218-
/**
219-
* Methode for determining the greatest common divider.
220-
*
221-
* @param num The numerator.
222-
* @param denom The denominator.
223-
* @return The greatest common divider.
224-
*/
225211
private BigInteger gcd(@NonNull final BigInteger num, @NonNull final BigInteger denom) {
226212

227213
var first = num.abs();

0 commit comments

Comments
 (0)