Skip to content

Commit 1ba2f9f

Browse files
committed
Finish Import use case
1 parent f17f22d commit 1ba2f9f

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed
Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package org.hydev.mcpm.client.export;
22

3-
import org.hydev.mcpm.client.installer.InstallResult;
4-
5-
import java.util.EnumSet;
63
import java.util.Map;
74

5+
86
/**
9-
* Result for importing plugins
10-
*
11-
* @param installResults Result of each install
7+
* Class storing results of the
128
*/
13-
public record ImportResult(Map<String, InstallResult> installResults) {
9+
public class ImportResult {
10+
private State state;
11+
private Map<String, Boolean> installResults;
12+
13+
/**
14+
* Result for importing plugins
15+
*
16+
* @param installResults Result of each install
17+
*/
18+
public ImportResult(Map<String, Boolean> installResults) {
19+
this.installResults = installResults;
20+
}
21+
22+
1423
/**
1524
* State of a single import
1625
*/
@@ -27,16 +36,26 @@ public enum State {
2736
*/
2837
public State getState()
2938
{
39+
if (state != null)
40+
return state;
3041
boolean success = true;
3142
boolean fail = false;
3243

33-
/*
34-
EnumSet<InstallResult> = new RegularEnumSet<>();
35-
for (InstallResult x : installResults.values()) {
36-
success &= x.type();
37-
fail |= x.type();
44+
/* Code for when import returns ImportResult instead of boolean
45+
Set<Type> good = new HashSet<>();
46+
for (Type type : Type.values()) {
47+
if (type.name().contains("SUCCESS")) // definitely legit
48+
good.add(type);
3849
}
39-
*/
40-
return State.SUCCESS;
50+
*/
51+
52+
for (var x : installResults.values()) {
53+
success &= x;
54+
fail |= x;
55+
if (!success && fail) // not a full success nor full failure
56+
return state = State.PARTIAL_SUCCESS;
57+
}
58+
59+
return state = success ? State.SUCCESS : State.FAILURE;
4160
}
4261
}

0 commit comments

Comments
 (0)