Skip to content

Commit 14b1992

Browse files
committed
Updated to use enum ListType
1 parent 3292ac7 commit 14b1992

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

src/main/java/org/hydev/mcpm/client/commands/controllers/ListController.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.hydev.mcpm.client.list.ListAllBoundary;
44
import org.hydev.mcpm.client.updater.CheckForUpdatesBoundary;
5+
import org.hydev.mcpm.client.list.ListType;
56

67
import java.util.List;
78
import java.util.function.Consumer;
@@ -34,7 +35,27 @@ public ListController(ListAllBoundary listAllBoundary, CheckForUpdatesBoundary c
3435
* @param log Logger
3536
*/
3637
public void listAll(String parameter, Consumer<String> log) {
37-
var list = listAllBoundary.listAll(parameter, checkForUpdatesBoundary);
38+
39+
ListType listType;
40+
switch (parameter) {
41+
case "all":
42+
listType = ListType.ALL;
43+
break;
44+
case "manual":
45+
listType = ListType.MANUAL;
46+
break;
47+
case "automatic":
48+
listType = ListType.AUTOMATIC;
49+
break;
50+
case "outdated":
51+
listType = ListType.OUTDATED;
52+
break;
53+
default:
54+
log.accept("Invalid parameter. Please use 'all', 'manual', 'automatic', or 'outdated'.");
55+
return;
56+
}
57+
58+
var list = listAllBoundary.listAll(listType, checkForUpdatesBoundary);
3859

3960
// Tabulate result
4061
var table = tabulate(

src/main/java/org/hydev/mcpm/client/list/ListAllBoundary.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ public interface ListAllBoundary {
2222
* a request to list all manually installed plugins that are
2323
* outdated.
2424
*/
25-
List<PluginYml> listAll(String parameter, CheckForUpdatesBoundary checkForUpdatesBoundary);
25+
26+
List<PluginYml> listAll(ListType parameter, CheckForUpdatesBoundary checkForUpdatesBoundary);
2627
}

src/main/java/org/hydev/mcpm/client/list/ListAllInteractor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ public record ListAllInteractor(SuperPluginTracker pluginTracker) implements Lis
2525
* a request to list all manually installed plugins that are
2626
* outdated.
2727
*/
28-
public List<PluginYml> listAll(String parameter, CheckForUpdatesBoundary checkForUpdatesBoundary) {
28+
public List<PluginYml> listAll(ListType parameter, CheckForUpdatesBoundary checkForUpdatesBoundary) {
2929
var installed = pluginTracker.listInstalled();
3030
switch (parameter) {
31-
case "all":
31+
case ALL:
3232
return installed;
3333

34-
case "manual":
34+
case MANUAL:
3535
var local = pluginTracker.listManuallyInstalled();
3636
return installed.stream().filter(it -> local.contains(it.name())).toList();
3737

38-
case "automatic":
38+
case AUTOMATIC:
3939
var manual = pluginTracker.listManuallyInstalled();
4040
return installed.stream().filter(it -> !manual.contains(it.name())).toList();
4141

42-
case "outdated":
42+
case OUTDATED:
4343
ListUpdateableBoundary listUpdateableBoundary = new ListUpdateableHelper();
4444
var outdated = listUpdateableBoundary.listUpdateable(pluginTracker, checkForUpdatesBoundary);
4545
return installed.stream().filter(it -> outdated.contains(it.name())).toList();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.hydev.mcpm.client.list;
2+
3+
/**
4+
* Enum representing different possible inputs
5+
*/
6+
public enum ListType {
7+
ALL, MANUAL, AUTOMATIC, OUTDATED
8+
}

src/main/java/org/hydev/mcpm/client/list/ListUpdateableHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class ListUpdateableHelper implements ListUpdateableBoundary {
2323

2424
/**
25-
* Returns a list of plugins that are outdated.
25+
* Returns a list of plugins names that belong to outdated plugins
2626
*
2727
* @param localPluginTracker The plugin tracker in question
2828
* @param checkForUpdatesBoundary The boundary to check for updates

0 commit comments

Comments
 (0)