Skip to content

Commit 724bb37

Browse files
committed
Add documentation for main branch
1 parent 33d00d7 commit 724bb37

File tree

7 files changed

+237
-13
lines changed

7 files changed

+237
-13
lines changed

src/main/java/org/hydev/mcpm/client/arguments/ControllerFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
import org.hydev.mcpm.client.commands.controllers.UpdateController;
1616
import org.hydev.mcpm.client.local.PageController;
1717

18+
/**
19+
* Handles the creation of default factory classes.
20+
* The required parameters to initialize these classes are acquired from the `boundary` object.
21+
*
22+
* @param boundary A provider to acquire the required interactors to initialize the controllers.
23+
*/
1824
public record ControllerFactory(InteractorFactoryBoundary boundary) implements ControllerFactoryBoundary {
1925
@Override
2026
public PageBoundary pageBoundary() {

src/main/java/org/hydev/mcpm/client/arguments/ControllerFactoryBoundary.java

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,105 @@
1414
import org.hydev.mcpm.client.commands.controllers.UnloadController;
1515
import org.hydev.mcpm.client.commands.controllers.UpdateController;
1616

17+
/**
18+
* Abstract factory for creating controller classes.
19+
* Classes can implement this in order to provide their own ways of initializing Controllers.
20+
* <p>
21+
* The methods of this class should be cached
22+
* (e.g. you should be able to invoke them many times and get the same object).
23+
*/
1724
public interface ControllerFactoryBoundary {
18-
// PageBoundary/PageController technically acts as a controller in this case.
19-
// And is used for instantiation of other Controller classes.
25+
/**
26+
* Creates a page boundary object that handles pagination and persisting of pages (for the `page` command).
27+
* <p>
28+
* PageBoundary/PageController technically acts as a controller in this case.
29+
* And is used for instantiation of other Controller classes.
30+
*
31+
* @return A PageBoundary object.
32+
*/
2033
PageBoundary pageBoundary();
34+
35+
/**
36+
* Creates an export controller that interfaces with ExportPluginsBoundary.
37+
*
38+
* @return A ExportPluginsController object.
39+
*/
2140
ExportPluginsController exportController();
41+
42+
/**
43+
* Creates a list controller that interfaces with ListAllBoundary.
44+
*
45+
* @return A ListController object.
46+
*/
2247
ListController listController();
48+
49+
/**
50+
* Creates a search controller that interfaces with SearchPackagesBoundary.
51+
*
52+
* @return A SearchPackagesController object.
53+
*/
2354
SearchPackagesController searchController();
55+
56+
/**
57+
* Creates a mirror controller that interfaces with MirrorSelectorBoundary.
58+
*
59+
* @return A MirrorController object.
60+
*/
2461
MirrorController mirrorController();
62+
63+
/**
64+
* Creates an info controller that presents the user installed plugin info.
65+
*
66+
* @return A InfoController object.
67+
*/
2568
InfoController infoController();
69+
70+
/**
71+
* Creates a mirror controller that interfaces with InstallBoundary.
72+
*
73+
* @return A InstallController object.
74+
*/
2675
InstallController installController();
76+
77+
/**
78+
* Creates an `uninstall` controller that interfaces with UninstallBoundary.
79+
*
80+
* @return A UninstallController object.
81+
*/
2782
UninstallController uninstallController();
83+
84+
/**
85+
* Creates an update controller that interfaces with UpdateBoundary.
86+
*
87+
* @return A UpdateController object.
88+
*/
2889
UpdateController updateController();
90+
91+
/**
92+
* Creates a refresh controller that fetches the database in case it gets out of date.
93+
*
94+
* @return A RefreshController object.
95+
*/
2996
RefreshController refreshController();
97+
98+
/**
99+
* Creates a load controller that interfaces with LoadBoundary.
100+
*
101+
* @return A LoadController object.
102+
*/
30103
LoadController loadController();
104+
105+
/**
106+
* Creates a reload controller that interfaces with ReloadBoundary.
107+
*
108+
* @return A ReloadController object.
109+
*/
31110
ReloadController reloadController();
111+
112+
/**
113+
* Creates an unload controller that interfaces with UnloadBoundary.
114+
*
115+
* @return A UnloadController object.
116+
*/
32117
UnloadController unloadController();
33118
}

src/main/java/org/hydev/mcpm/client/arguments/InteractorFactory.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
import java.util.Map;
4141
import java.util.function.Supplier;
4242

43+
/**
44+
* Default factory for interactor.
45+
* This handles caching the various objects used for interactors, and is on the highest level of CA.
46+
*/
4347
public class InteractorFactory implements InteractorFactoryBoundary {
4448
// Lazy solution, not going to store variables.
4549
private final Map<Class<?>, Object> localCache = new HashMap<>();
@@ -49,6 +53,15 @@ public InteractorFactory(boolean server) {
4953
this.server = server;
5054
}
5155

56+
/**
57+
* Returns an object of type `type` that it previously returned with an identical `type`.
58+
* Otherwise, it invokes `create` and returns the value of that.
59+
*
60+
* @param type The type of the object to cache.
61+
* @param create A creation method if this object is not already cached.
62+
* @param <T> The type of the cached object.
63+
* @return An object of type T.
64+
*/
5265
private <T> T cache(Class<T> type, Supplier<T> create) {
5366
var value = localCache.getOrDefault(type, null);
5467

src/main/java/org/hydev/mcpm/client/arguments/InteractorFactoryBoundary.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,133 @@
1818
import org.hydev.mcpm.client.updater.CheckForUpdatesBoundary;
1919
import org.hydev.mcpm.client.updater.UpdateBoundary;
2020

21+
/**
22+
* Abstract factory for creating interactor classes.
23+
* Classes can implement this in order to provide their implementations of these boundary classes.
24+
* <p>
25+
* The methods of this class should be cached
26+
* (e.g. you should be able to invoke them many times and get the same object).
27+
* <p>
28+
* This class has the ability of creating a bunch of different boundaries.
29+
*
30+
*/
2131
public interface InteractorFactoryBoundary {
32+
/**
33+
* Creates a mirror boundary for managing currently selected and available mirrors.
34+
*
35+
* @return A MirrorSelectBoundary object.
36+
*/
2237
MirrorSelectBoundary mirrorSelector();
38+
39+
/**
40+
* Creates a database fetcher for grabbing a list of all available plugins.
41+
*
42+
* @return A DatabaseFetcher object.
43+
*/
2344
DatabaseFetcher databaseFetcher();
45+
46+
/**
47+
* Creates a plugin tracker object for keeping track of currently installed plugins.
48+
*
49+
* @return A PluginTracker object.
50+
*/
2451
PluginTracker pluginTracker();
52+
53+
/**
54+
* Creates a load boundary object for hot loading new plugins.
55+
*
56+
* @return A LoadBoundary object.
57+
*/
2558
LoadBoundary loadBoundary();
59+
60+
/**
61+
* Creates a load boundary object for hot reloading already running plugins.
62+
*
63+
* @return A ReloadBoundary object.
64+
*/
2665
ReloadBoundary reloadBoundary();
66+
67+
/**
68+
* Creates an unload boundary object for hot unloading running plugins.
69+
*
70+
* @return A UnloadBoundary object.
71+
*/
2772
UnloadBoundary unloadBoundary();
73+
74+
/**
75+
* Creates a jar boundary object for looking up plugins by name.
76+
*
77+
* @return A LocalJarBoundary object.
78+
*/
2879
LocalJarBoundary jarBoundary();
80+
81+
/**
82+
* Creates a fetcher listener object for sending database fetching updates to the user.
83+
*
84+
* @return A DatabaseFetcherListener object.
85+
*/
2986
DatabaseFetcherListener fetcherListener();
87+
88+
/**
89+
* Creates a search boundary object for looking up plugins in the database.
90+
*
91+
* @return A SearchPackagesBoundary object.
92+
*/
3093
SearchPackagesBoundary searchBoundary();
94+
95+
/**
96+
* Creates a plugin downloader object for downloading plugins to the filesystem.
97+
*
98+
* @return A PluginDownloader object.
99+
*/
31100
PluginDownloader pluginDownloader();
101+
102+
/**
103+
* Creates an `install` boundary object for installing new plugins.
104+
*
105+
* @return A InstallBoundary object.
106+
*/
32107
InstallBoundary installBoundary();
108+
109+
/**
110+
* Creates an `match` boundary object for finding plugins by id.
111+
*
112+
* @return A MatchPluginsBoundary object.
113+
*/
33114
MatchPluginsBoundary matchBoundary();
115+
116+
/**
117+
* Creates an `check for updates` boundary object for checking if plugins have available updates.
118+
*
119+
* @return A CheckForUpdatesBoundary object.
120+
*/
34121
CheckForUpdatesBoundary checkForUpdatesBoundary();
122+
123+
/**
124+
* Creates an `update` boundary object for updating installed plugins.
125+
*
126+
* @return A UpdateBoundary object.
127+
*/
35128
UpdateBoundary updateBoundary();
129+
130+
/**
131+
* Creates an `export` boundary object for exporting a list of installed plugins.
132+
*
133+
* @return A ExportPluginsBoundary object.
134+
*/
36135
ExportPluginsBoundary exportBoundary();
136+
137+
/**
138+
* Creates an `list` boundary object for listing installed plugins.
139+
*
140+
* @return A ListAllBoundary object.
141+
*/
37142
ListAllBoundary listBoundary();
143+
144+
/**
145+
* Creates an `uninstall` boundary object for uninstalling plugins.
146+
*
147+
* @return A UninstallBoundary object.
148+
*/
38149
UninstallBoundary uninstallBoundary();
39150
}

src/main/java/org/hydev/mcpm/client/arguments/ParserFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import java.util.List;
1919
import java.util.stream.Stream;
2020

21+
/**
22+
* Handles the creation of CommandParser list.
23+
* This is a simple factory that just invokes the methods of ControllerFactoryBoundary and returns a list of parsers.
24+
*/
2125
public class ParserFactory {
2226
private ParserFactory() { }
2327

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public ExportPluginsController(ExportPluginsBoundary boundary) {
2424
/**
2525
* Call the boundary to perform an export.
2626
*
27-
* @param input Input specifying the export parameters
27+
* @param stream Input specifying the export parameters
28+
* @param cache Whether to use the cached version of the database.
2829
* @param log where to log the operation
2930
*/
3031
public void export(OutputStream stream, boolean cache, Consumer<String> log) {

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
/**
1010
* Implementation to the ListAll functionality
1111
*/
12-
public record ListAllInteractor(PluginTracker pluginTracker, CheckForUpdatesBoundary updates) implements ListAllBoundary {
12+
public record ListAllInteractor(
13+
PluginTracker pluginTracker,
14+
CheckForUpdatesBoundary updates
15+
) implements ListAllBoundary {
1316
/**
1417
* listAllInteractor interacts with the LocalPluginTracker to get the list of
1518
* plugins, according to a specified
@@ -25,24 +28,25 @@ public record ListAllInteractor(PluginTracker pluginTracker, CheckForUpdatesBoun
2528
public List<PluginYml> listAll(ListType parameter) {
2629
var installed = pluginTracker.listInstalled();
2730
switch (parameter) {
28-
case ALL:
31+
case ALL -> {
2932
return installed;
30-
31-
case MANUAL:
33+
}
34+
case MANUAL -> {
3235
var local = pluginTracker.listManuallyInstalled();
3336
return installed.stream().filter(it -> local.contains(it.name())).toList();
34-
35-
case AUTOMATIC:
37+
}
38+
case AUTOMATIC -> {
3639
var manual = pluginTracker.listManuallyInstalled();
3740
return installed.stream().filter(it -> !manual.contains(it.name())).toList();
38-
39-
case OUTDATED:
41+
}
42+
case OUTDATED -> {
4043
ListUpdateableBoundary listUpdateableBoundary = new ListUpdateableHelper();
4144
var outdated = listUpdateableBoundary.listUpdateable(pluginTracker, updates);
4245
return installed.stream().filter(it -> outdated.contains(it.name())).toList();
43-
44-
default:
46+
}
47+
default -> {
4548
return null;
49+
}
4650
}
4751
}
4852
}

0 commit comments

Comments
 (0)