-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeLoader.java
More file actions
87 lines (79 loc) · 2.97 KB
/
ThemeLoader.java
File metadata and controls
87 lines (79 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.houarizegai.calculator.theme;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.houarizegai.calculator.theme.properties.Theme;
import com.houarizegai.calculator.theme.properties.ThemeList;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
public class ThemeLoader {
private ThemeLoader() {
throw new AssertionError("Constructor is not allowed");
}
/**
* Loads themes from the application.yaml file and returns them as a map.
*
* @return A map containing the loaded themes.
* @throws IOException if an I/O error occurs while reading the application.yaml file.
*
* Example:
* <pre>{@code
* Map<String, Theme> themes = loadThemes();
* }</pre>
*/
public static Map<String, Theme> loadThemes() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.findAndRegisterModules();
try {
ThemeList themeList = mapper.readValue(new File("src/main/resources/application.yaml"), ThemeList.class);
return themeList.getThemesAsMap();
} catch (IOException e) {
return Collections.emptyMap();
}
}
/**
* Loads themes from the specified YAML file and returns a map of theme names to Theme objects.
*
* @param theme the name of the theme to load
* @return a map of theme names to Theme objects
* @throws IOException if an error occurs while reading the YAML file
*
* Example:
* <pre>{@code
* Map<String, Theme> themes = loadThemes("default");
* }</pre>
*/
public static Map<String, Theme> loadThemes(String theme) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.findAndRegisterModules();
try {
ThemeList themeList = mapper.readValue(new File("src/main/resources/application.yaml"), ThemeList.class);
return themeList.getThemesAsMap();
} catch (IOException e) {
return Collections.emptyMap();
}
}
/**
* Loads themes from the specified YAML file and returns a map of theme names to Theme objects.
*
* @param theme the theme to load
* @param dType the type of the theme
* @return a map of theme names to Theme objects
* @throws IOException if an I/O error occurs while reading the YAML file
*
* Example:
*
* Map<String, Theme> themes = loadThemes("default", "dark");
*/
public static Map<String, Theme> loadThemes(String theme, String dType) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
mapper.findAndRegisterModules();
try {
ThemeList themeList = mapper.readValue(new File("src/main/resources/application.yaml"), ThemeList.class);
return themeList.getThemesAsMap();
} catch (IOException e) {
return Collections.emptyMap();
}
}
}