Skip to content

Commit fe317b3

Browse files
committed
Finished implementing methods to remove keys from DatLocalisation
1 parent 1463e51 commit fe317b3

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/main/java/com/datdeveloper/datmoddingapi/localisation/DatLocalisation.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Collections;
1616
import java.util.HashMap;
1717
import java.util.Map;
18+
import java.util.function.Predicate;
1819
import java.util.regex.Pattern;
1920

2021
/**
@@ -145,4 +146,37 @@ public Map<String, String> getAllTranslations() {
145146
public String getLocalisation(final String key, final String fallback) {
146147
return translations.getOrDefault(key, fallback);
147148
}
149+
150+
/**
151+
* Clear all the translations
152+
* <br>
153+
* Warning, this clears <b>ALL</b> the translations, from all mods that have registered up until this point.
154+
* This method was mainly added for testing reasons, so don't go misusing it.
155+
* <br>
156+
* If you really need to clear some translations, you should probably use {@link DatLocalisation#removeTranslation(String)}
157+
* or {@link DatLocalisation#removeTranslations(Predicate)}
158+
* @see DatLocalisation#removeTranslation(String)
159+
* @see DatLocalisation#removeTranslations(Predicate)
160+
*/
161+
public void clearTranslations() {
162+
translations.clear();
163+
}
164+
165+
/**
166+
* Remove the translation with the matching key
167+
* @see DatLocalisation#removeTranslations(Predicate)
168+
* @param key The key of the translation to remove
169+
*/
170+
public void removeTranslation(final String key) {
171+
translations.remove(key);
172+
}
173+
174+
/**
175+
* Remove any translations that match the given predicate
176+
* @see DatLocalisation#removeTranslation(String)
177+
* @param predicate The predicate that determines if a key should be removed
178+
*/
179+
public void removeTranslations(final Predicate<String> predicate) {
180+
translations.keySet().removeIf(predicate);
181+
}
148182
}

src/test/java/com/datdeveloper/TestDatLocalisation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ void validateKeysFromFile(final String filePath) throws IOException {
4444

4545
@BeforeEach
4646
void clearTranslations() {
47-
47+
final DatLocalisation instance = DatLocalisation.getInstance();
48+
instance.clearTranslations();
4849
}
4950

5051
/**

0 commit comments

Comments
 (0)