Skip to content

Commit 3d958a4

Browse files
committed
Final Obsession
1 parent fbfb0e5 commit 3d958a4

8 files changed

Lines changed: 104 additions & 104 deletions

File tree

src/main/java/net/thenextlvl/i18n/ComponentBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public boolean isFilling() {
481481
* @return a new {@link ComponentBundle.Builder} instance
482482
*/
483483
@Contract(value = "_, _ -> new", pure = true)
484-
static ComponentBundle.Builder builder(Key name, Path path) {
484+
static ComponentBundle.Builder builder(final Key name, final Path path) {
485485
return new ComponentBundleImpl.Builder(name, path);
486486
}
487487
}

src/main/java/net/thenextlvl/i18n/ComponentBundleImpl.java

Lines changed: 67 additions & 67 deletions
Large diffs are not rendered by default.

src/main/java/net/thenextlvl/i18n/PropertiesFile.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PropertiesFile {
2525

2626
private boolean loaded;
2727

28-
public PropertiesFile(Path path, Charset charset, Properties root) {
28+
public PropertiesFile(final Path path, final Charset charset, final Properties root) {
2929
this.charset = charset;
3030
this.defaultRoot = root;
3131
this.path = path;
@@ -34,42 +34,42 @@ public PropertiesFile(Path path, Charset charset, Properties root) {
3434

3535
protected Properties load() {
3636
if (!Files.isRegularFile(getFile())) return (Properties) getRoot().clone();
37-
try (var reader = new InputStreamReader(Files.newInputStream(getFile(), READ), charset);
38-
var buffer = new BufferedReader(reader)) {
39-
var properties = new Properties();
37+
try (final var reader = new InputStreamReader(Files.newInputStream(getFile(), READ), charset);
38+
final var buffer = new BufferedReader(reader)) {
39+
final var properties = new Properties();
4040
properties.load(buffer);
4141
return properties;
42-
} catch (IOException e) {
42+
} catch (final IOException e) {
4343
throw new RuntimeException(e);
4444
}
4545
}
4646

47-
public PropertiesFile save(FileAttribute<?>... attributes) {
47+
public PropertiesFile save(final FileAttribute<?>... attributes) {
4848
try {
49-
var root = getRoot();
49+
final var root = getRoot();
5050
Files.createDirectories(getFile().toAbsolutePath().getParent(), attributes);
51-
try (var writer = new BufferedWriter(new OutputStreamWriter(
51+
try (final var writer = new BufferedWriter(new OutputStreamWriter(
5252
Files.newOutputStream(getFile(), WRITE, CREATE, TRUNCATE_EXISTING),
5353
charset
5454
))) {
5555
root.store(writer, null);
5656
return this;
5757
}
58-
} catch (IOException e) {
58+
} catch (final IOException e) {
5959
throw new RuntimeException(e);
6060
}
6161
}
6262

63-
public PropertiesFile validate(ComponentBundle.Scope scope) {
64-
var root = getRoot();
63+
public PropertiesFile validate(final ComponentBundle.Scope scope) {
64+
final var root = getRoot();
6565
if (root == defaultRoot) return this;
6666
if (scope.isFiltering()) root.entrySet().removeIf(entry ->
6767
!defaultRoot.containsKey(entry.getKey()));
6868
if (scope.isFilling()) merge(defaultRoot);
6969
return this;
7070
}
7171

72-
public PropertiesFile setRoot(Properties root) {
72+
public PropertiesFile setRoot(final Properties root) {
7373
this.loaded = true;
7474
this.root = root;
7575
return this;
@@ -85,8 +85,8 @@ public Path getFile() {
8585
return path;
8686
}
8787

88-
public PropertiesFile merge(Properties properties) {
89-
var root = getRoot();
88+
public PropertiesFile merge(final Properties properties) {
89+
final var root = getRoot();
9090
properties.forEach((key, value) -> {
9191
if (root.containsKey(key)) return;
9292
root.put(key, value);

src/main/java/net/thenextlvl/i18n/ResourceMigrationException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ResourceMigrationException extends RuntimeException {
88
*
99
* @param message the detail message providing additional context about the exception.
1010
*/
11-
public ResourceMigrationException(String message) {
11+
public ResourceMigrationException(final String message) {
1212
super(message);
1313
}
1414

@@ -20,7 +20,7 @@ public ResourceMigrationException(String message) {
2020
* @param message the detail message providing additional context about the exception.
2121
* @param cause the cause of the exception, which can be used to retrieve details about the root issue.
2222
*/
23-
public ResourceMigrationException(String message, Throwable cause) {
23+
public ResourceMigrationException(final String message, final Throwable cause) {
2424
super(message, cause);
2525
}
2626
}

src/main/java/net/thenextlvl/i18n/ResourceMigrator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface ResourceMigrator {
2929
*/
3030
@Nullable
3131
@CheckReturnValue
32-
default Migration migrate(Locale locale, String key, String message) {
32+
default Migration migrate(final Locale locale, final String key, final String message) {
3333
return null;
3434
}
3535

@@ -43,7 +43,7 @@ default Migration migrate(Locale locale, String key, String message) {
4343
* @return {@code true} if the migration should be performed, {@code false} otherwise
4444
*/
4545
@CheckReturnValue
46-
default boolean shouldMigrate(String resource, Properties properties) {
46+
default boolean shouldMigrate(final String resource, final Properties properties) {
4747
return true;
4848
}
4949

@@ -79,7 +79,7 @@ default boolean shouldMigrate(String resource, Properties properties) {
7979
*/
8080
@Nullable
8181
@CheckReturnValue
82-
default String getOldResourceName(Locale locale) {
82+
default String getOldResourceName(final Locale locale) {
8383
return null;
8484
}
8585

src/test/java/net/thenextlvl/i18n/test/BaseTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package net.thenextlvl.i18n.test;
22

3-
import net.thenextlvl.i18n.ComponentBundle;
43
import net.kyori.adventure.key.Keyed;
54
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
65
import net.kyori.adventure.translation.GlobalTranslator;
76
import net.kyori.adventure.translation.Translator;
7+
import net.thenextlvl.i18n.ComponentBundle;
88
import org.junit.jupiter.api.Assertions;
99
import org.junit.jupiter.api.DisplayName;
1010
import org.junit.jupiter.api.Test;
@@ -30,11 +30,11 @@ public abstract class BaseTest implements Keyed {
3030
.placeholder("prefix", "prefix")
3131
.build();
3232

33-
protected static void cleanup(String... files) {
33+
protected static void cleanup(final String... files) {
3434
Arrays.stream(files).map(OUTPUT::resolve).forEach(path -> {
3535
try {
3636
Files.deleteIfExists(path);
37-
} catch (IOException e) {
37+
} catch (final IOException e) {
3838
LOGGER.error("Failed to delete file {}", path, e);
3939
}
4040
});
@@ -45,8 +45,8 @@ protected static void cleanup(String... files) {
4545
public void testSources() {
4646
bundle.registerTranslations();
4747

48-
var translator = GlobalTranslator.translator();
49-
var translators = new HashSet<Translator>();
48+
final var translator = GlobalTranslator.translator();
49+
final var translators = new HashSet<Translator>();
5050
translator.sources().iterator().forEachRemaining(translators::add);
5151
Assertions.assertTrue(translators.contains(bundle.translator()), "Translation store not registered");
5252

src/test/java/net/thenextlvl/i18n/test/ContentTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ public static void setup() {
2626
@ParameterizedTest
2727
@MethodSource("prefixedContent")
2828
@DisplayName("Placeholders as expected")
29-
public void testPlaceholders(String expected, Locale locale) {
30-
var translation = bundle.translate("prefix_test", locale);
29+
public void testPlaceholders(final String expected, final Locale locale) {
30+
final var translation = bundle.translate("prefix_test", locale);
3131
Assertions.assertEquals(Component.text(expected), translation);
3232
}
3333

3434
@ParameterizedTest
3535
@MethodSource("content")
3636
@DisplayName("Content as expected")
37-
public void testContent(String expected, Locale locale) {
38-
var translation = bundle.translate("greetings", locale);
37+
public void testContent(final String expected, final Locale locale) {
38+
final var translation = bundle.translate("greetings", locale);
3939
Assertions.assertEquals(Component.text(expected), translation);
4040
}
4141

4242
@ParameterizedTest
4343
@MethodSource("resolvedContent")
4444
@DisplayName("Resolved content as expected")
45-
public void testResolvedContent(String expected, ComponentLike argument, Locale locale) {
46-
var translation = bundle.translate("resolved", locale, argument);
45+
public void testResolvedContent(final String expected, final ComponentLike argument, final Locale locale) {
46+
final var translation = bundle.translate("resolved", locale, argument);
4747
Assertions.assertEquals(Component.text(expected), translation);
4848
}
4949

src/test/java/net/thenextlvl/i18n/test/MigrationTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ public class MigrationTest extends BaseTest implements ResourceMigrator {
2525
@Test
2626
@DisplayName("Migrate old keys and messages")
2727
public void testStringMigration() {
28-
var oldResources = ComponentBundle.builder(key(), OUTPUT);
28+
final var oldResources = ComponentBundle.builder(key(), OUTPUT);
2929
oldFiles.forEach((locale, file) -> oldResources.resource(file, locale));
3030
oldResources.build();
3131

32-
var bundle = ComponentBundle.builder(key(), OUTPUT)
32+
final var bundle = ComponentBundle.builder(key(), OUTPUT)
3333
.resource("up_to_date.properties", Locale.US)
3434
.resource("up_to_date_german.properties", Locale.GERMANY)
3535
.migrator(this)
3636
.build();
3737

38-
var english = bundle.translator().translate(Component.translatable("success"), Locale.US);
38+
final var english = bundle.translator().translate(Component.translatable("success"), Locale.US);
3939
Assertions.assertEquals(Component.text("migrated"), english);
40-
var german = bundle.translator().translate(Component.translatable("success"), Locale.GERMANY);
40+
final var german = bundle.translator().translate(Component.translatable("success"), Locale.GERMANY);
4141
Assertions.assertEquals(Component.text("Migriert"), german);
4242
}
4343

@@ -47,12 +47,12 @@ public Key key() {
4747
}
4848

4949
@Override
50-
public @Nullable Migration migrate(Locale locale, String key, String message) {
50+
public @Nullable Migration migrate(final Locale locale, final String key, final String message) {
5151
return new Migration(keys.getOrDefault(key, key), null);
5252
}
5353

5454
@Override
55-
public @Nullable String getOldResourceName(Locale locale) {
55+
public @Nullable String getOldResourceName(final Locale locale) {
5656
return oldFiles.get(locale);
5757
}
5858

0 commit comments

Comments
 (0)