2
2
3
3
import org .hydev .mcpm .client .models .Plugin ;
4
4
5
- import javax .xml .crypto .Data ;
6
- import java .io .File ;
7
5
import java .util .HashMap ;
8
6
import java .util .List ;
9
7
import java .util .Map ;
14
12
* @author Azalea (https://github.com/hykilpikonna)
15
13
* @since 2022-09-27
16
14
*/
17
- public class DatabaseLoader
15
+ public class DatabaseInteractor
18
16
{
19
17
/** Name index: map[lower-cased name] = Plugin of that name */
20
18
private final Map <String , Plugin > nameIndex ;
@@ -30,7 +28,7 @@ public class DatabaseLoader
30
28
*
31
29
* @param path Database file path
32
30
*/
33
- public DatabaseLoader (String path )
31
+ public DatabaseInteractor (String path )
34
32
{
35
33
this .nameIndex = new HashMap <>();
36
34
this .keywordIndex = new HashMap <>();
@@ -48,8 +46,12 @@ public DatabaseLoader(String path)
48
46
*/
49
47
public Plugin findByName (String name )
50
48
{
51
- // TODO: Implement this
52
- throw new UnsupportedOperationException ("TODO" );
49
+ if (nameIndex .containsKey (name )) {
50
+ return nameIndex .get (name );
51
+ }
52
+ return null ;
53
+
54
+ // throw new UnsupportedOperationException("TODO");
53
55
}
54
56
55
57
/**
@@ -67,8 +69,12 @@ public Plugin findByName(String name)
67
69
*/
68
70
public List <Plugin > searchByKeyword (String keyword )
69
71
{
70
- // TODO: Implement this
71
- throw new UnsupportedOperationException ("TODO" );
72
+ if (keywordIndex .containsKey (keyword )) {
73
+ return keywordIndex .get (keyword );
74
+ }
75
+ return List .of ();
76
+
77
+ // throw new UnsupportedOperationException("TODO");
72
78
}
73
79
74
80
/**
@@ -79,7 +85,11 @@ public List<Plugin> searchByKeyword(String keyword)
79
85
*/
80
86
public List <Plugin > searchByCommand (String command )
81
87
{
82
- // TODO: Implement this
83
- throw new UnsupportedOperationException ("TODO" );
88
+ if (commandIndex .containsKey (command )) {
89
+ return commandIndex .get (command );
90
+ }
91
+ return List .of ();
92
+
93
+ // throw new UnsupportedOperationException("TODO");
84
94
}
85
95
}
0 commit comments