Skip to content

Commit 7838be2

Browse files
authored
Merge pull request #14 from CSC207-2022F-UofT/feature-checkstyle-1
2 parents 75976a6 + 26aaa96 commit 7838be2

File tree

7 files changed

+80
-18
lines changed

7 files changed

+80
-18
lines changed

src/main/java/org/hydev/mcpm/Controller.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package org.hydev.mcpm;
22

33
import net.sourceforge.argparse4j.inf.ArgumentParserException;
4-
import org.hydev.mcpm.client.injector.*;
4+
import org.hydev.mcpm.client.injector.PluginNotFoundException;
5+
import org.hydev.mcpm.client.injector.PluginLoader;
6+
import org.hydev.mcpm.client.injector.LoadBoundary;
7+
import org.hydev.mcpm.client.injector.UnloadBoundary;
8+
import org.hydev.mcpm.client.injector.ReloadBoundary;
59

610
import java.util.function.Consumer;
711

812
import static java.lang.String.format;
9-
import static org.hydev.mcpm.utils.Sugar.sub;
1013
import static org.hydev.mcpm.utils.Sugar.subFrom;
1114

12-
1315
/**
1416
* Controller of the program
1517
*
@@ -22,6 +24,9 @@ public class Controller
2224
private final UnloadBoundary unloader;
2325
private final ReloadBoundary reloader;
2426

27+
/**
28+
* Creates default controller with a PluginLoader for all boundaries.
29+
*/
2530
public Controller()
2631
{
2732
var pl = new PluginLoader();
@@ -57,6 +62,7 @@ public void runCommand(String[] args, Consumer<String> log)
5762
case "load" -> loader.loadPlugin(name);
5863
case "unload" -> unloader.unloadPlugin(name);
5964
case "reload" -> reloader.reloadPlugin(name);
65+
default -> { }
6066
}
6167
log.accept(format("Plugin %s %sed", name, cmd));
6268
}

src/main/java/org/hydev/mcpm/SpigotEntry.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public void onDisable()
4747
}
4848

4949
@Override
50-
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args)
50+
public boolean onCommand(@NotNull CommandSender sender,
51+
@NotNull Command command,
52+
@NotNull String label,
53+
@NotNull String[] args)
5154
{
5255
controller.runCommand(args, sender::sendMessage);
5356
return true;

src/main/java/org/hydev/mcpm/client/database/DatabaseInteractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public PluginModel findByName(String name)
6767
*/
6868
public List<PluginModel> searchByKeyword(String keyword)
6969
{
70-
if (keywordIndex.containsKey(keyword)) {
70+
if (keywordIndex.containsKey(keyword)) {
7171
return keywordIndex.get(keyword);
7272
}
7373
return List.of();

src/main/java/org/hydev/mcpm/client/injector/PluginLoader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
import java.io.File;
1616
import java.io.IOException;
1717
import java.net.URLClassLoader;
18-
import java.util.*;
18+
import java.util.Arrays;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.Optional;
22+
import java.util.SortedSet;
1923

2024
import static org.hydev.mcpm.utils.ReflectionUtils.getPrivateField;
2125
import static org.hydev.mcpm.utils.ReflectionUtils.setPrivateField;

src/main/java/org/hydev/mcpm/client/interaction/ProgressBar.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import org.hydev.mcpm.utils.ConsoleUtils;
55

66
import java.io.PrintStream;
7-
import java.util.*;
7+
import java.util.ArrayList;
8+
import java.util.List;
89

910
import static java.lang.String.format;
1011
import static org.fusesource.jansi.internal.CLibrary.STDOUT_FILENO;
@@ -138,15 +139,27 @@ public List<ProgressRow> getActiveBars()
138139
return activeBars;
139140
}
140141

142+
/**
143+
* Displays a demo progress bar.
144+
*
145+
* @param args Arguments are ignored.
146+
*/
141147
public static void main(String[] args)
142148
{
143149
try (var b = new ProgressBar(ProgressBarTheme.ASCII_THEME))
144150
{
145151
var all = new ArrayList<ProgressRow>();
146152
for (int i = 0; i < 1300; i++)
147153
{
148-
if (i < 1000 && i % 100 == 0)
149-
all.add(b.appendBar(new ProgressRow(300).unit("MB").desc(format("File %s.tar.gz", all.size()))).descLen(30));
154+
if (i < 1000 && i % 100 == 0) {
155+
var row = new ProgressRow(300)
156+
.unit("MB")
157+
.desc(format("File %s.tar.gz", all.size()))
158+
.descLen(30);
159+
160+
all.add(b.appendBar(row));
161+
}
162+
150163
all.forEach(a -> a.increase(1));
151164
safeSleep(3);
152165
}

src/main/java/org/hydev/mcpm/client/interaction/ProgressRow.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class ProgressRow
2020

2121
private final long startTime;
2222

23+
/**
24+
* Creates a ProgressRow object with a maximum 100% value of total.
25+
*
26+
* @param total The value that completed has to take to display 100% in this row.
27+
*/
2328
public ProgressRow(long total)
2429
{
2530
this.total = total;
@@ -53,7 +58,8 @@ public String toString(ProgressBarTheme theme, int cols)
5358
// Calculate speed. TODO: Use a moving window to calculate speed
5459
double speed = completed / elapsed();
5560
double eta = total / speed;
56-
long etaS = (long) (eta % 60), etaM = (long) (eta / 60);
61+
long etaS = (long) (eta % 60);
62+
long etaM = (long) (eta / 60);
5763

5864
// Replace variables
5965
var p = format("%3.0f%%", 100d * completed / total);
@@ -71,8 +77,12 @@ public String toString(ProgressBarTheme theme, int cols)
7177
if (len < 0) return t.replace("{progbar}", "");
7278

7379
// Calculate progress length
74-
int pLen = (int) (1d * completed / total * len);
75-
var bar = theme.done().repeat(pLen / theme.doneLen()) + theme.ipr().repeat((len - pLen) / theme.iprLen());
80+
int progress = (int) (1d * completed / total * len);
81+
82+
var leading = theme.done().repeat(progress / theme.doneLen());
83+
var trailing = theme.ipr().repeat((len - progress) / theme.iprLen());
84+
85+
var bar = leading + trailing;
7686

7787
return t.replace("{progbar}", bar);
7888
}
@@ -83,7 +93,7 @@ public void setPb(ProgressBar pb)
8393
}
8494

8595
/**
86-
* Increase progress
96+
* Increase progress by incr.
8797
*
8898
* @param incr Increase amount
8999
*/
@@ -97,9 +107,9 @@ public void increase(long incr)
97107
}
98108

99109
/**
100-
* Set progress
110+
* Update the progress.
101111
*
102-
* @param completed Completed amount
112+
* @param completed Completed so far
103113
*/
104114
public void set(long completed)
105115
{
@@ -110,25 +120,51 @@ public void set(long completed)
110120
if (completed >= total) pb.finishBar(this);
111121
}
112122

123+
/**
124+
* Sets the description of this object.
125+
*
126+
* @param desc The description to set
127+
* @return This object for chaining.
128+
*/
113129
public ProgressRow desc(String desc)
114130
{
115131
this.desc = desc;
116132
return this;
117133
}
118134

135+
/**
136+
* Sets the maximum description length. This value is used for padding.
137+
*
138+
* @param descLen The description length.
139+
* @return This object for chaining.
140+
*/
119141
public ProgressRow descLen(int descLen)
120142
{
121143
this.descLen = descLen;
122144
return this;
123145
}
124146

147+
/**
148+
* Sets the unit indicator for the speed indicator.
149+
*
150+
* @param unit A unit string, beginning with an empty space.
151+
* @return This object for chaining.
152+
*/
125153
public ProgressRow unit(String unit)
126154
{
127155
// Add leading space
128156
this.unit = (!unit.isBlank() && !unit.startsWith(" ")) ? " " + unit : unit;
129157
return this;
130158
}
131159

160+
/**
161+
* Sets the overall format of the progress bar.
162+
* This is specified using indicators like {speed}, {desc}.
163+
* For a full list see class implementation.
164+
*
165+
* @param fmt The foramt string.
166+
* @return This object for chaining.
167+
*/
132168
public ProgressRow fmt(String fmt)
133169
{
134170
this.fmt = fmt;

src/main/java/org/hydev/mcpm/utils/Sugar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class Sugar
1313
/**
1414
* Subarray, behaves exactly like python's arr[start:end]
1515
*
16+
* @param <T> Type of the array
1617
* @param arr Array
1718
* @param start Start (inclusive, negative numbers means (len - n))
1819
* @param end End (non-inclusive, negative numbers means (len - n))
1920
* @return Subarray
20-
* @param <T> Type of the array
2121
*/
2222
public static <T> T[] sub(T[] arr, int start, int end)
2323
{
@@ -32,10 +32,10 @@ public static <T> T[] sub(T[] arr, int start, int end)
3232
/**
3333
* Subarray from start, behaves exactly like python's arr[start:]
3434
*
35+
* @param <T> Type of the array
3536
* @param arr Array
3637
* @param start Start (inclusive, negative numbers means (len - n))
3738
* @return Subarray
38-
* @param <T> Type of the array
3939
*/
4040
public static <T> T[] subFrom(T[] arr, int start)
4141
{
@@ -45,10 +45,10 @@ public static <T> T[] subFrom(T[] arr, int start)
4545
/**
4646
* Subarray to end, behaves exactly like python's arr[:end]
4747
*
48+
* @param <T> Type of the array
4849
* @param arr Array
4950
* @param end End (non-inclusive, negative numbers means (len - n))
5051
* @return Subarray
51-
* @param <T> Type of the array
5252
*/
5353
public static <T> T[] subTo(T[] arr, int end)
5454
{

0 commit comments

Comments
 (0)