Untypisierte java.util.Properties
Aufrufer lesen Strings und konvertieren Werte selbst oder über generische Getter.
Vollständiger Legacy-Modern-Vergleich aller Java-Klassen, Tests, Maven-POMs und relevanten Ressourcen dieses Moduls. Jede Datei ist genau einmal einer fachlich passenden Vergleichsgruppe zugeordnet.
Aufrufer lesen Strings und konvertieren Werte selbst oder über generische Getter.
ConfigFactory definiert Prioritäten und erzeugt ein validiertes ApplicationConfig-Record.
Die Ähnlichkeit ist eine technische Orientierung auf normalisiertem Quelltext. Sie ersetzt keine fachliche Bewertung.
| Vergleichsgruppe | Legacy-Dateien | Modern-Dateien | Legacy-Zeilen | Modern-Zeilen | Ähnlichkeit |
|---|---|---|---|---|---|
| Build-Konfiguration | 1 | 1 | 34 | 34 | 97% |
| Konfigurationsquelle und Mapping | 2 | 2 | 22 | 22 | 4% |
| Konfigurationstest | 1 | 1 | 13 | 14 | 36% |
Das Pair-POM bindet die Legacy- und Modern-Submodule zusammen und gehört deshalb ebenfalls zur vollständigen Codeabdeckung.
Maven-Properties und Compiler-/Testsetup werden verglichen.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| pom.xml | pom.xml | Direktvergleich Semantische Ähnlichkeit: 97% |
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>21mavenpropertiesconfig-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>config-properties-legacy</artifactId>
<packaging>jar</packaging>
<name>Properties Config Legacy</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.aydin.academy</groupId>
<artifactId>21mavenpropertiesconfig-pair</artifactId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>typed-config-modern</artifactId>
<packaging>jar</packaging>
<name>Typed Config Modern</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>Direktes Properties-Lesen wird in typisiertes Mapping und Factory getrennt.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| application.properties LegacyPropertiesConfig.java | ApplicationConfig.java ConfigFactory.java | Direktvergleich Semantische Ähnlichkeit: 4% |
server.port=8080
feature.enabled=truepackage at.aydin.lab.config.legacy;
// Design Pattern: Configuration Object – bündelt untypisierte Properties in einem Zugriffspunkt.
import java.io.*;
import java.util.*;
public final class LegacyPropertiesConfig {
private final Properties properties = new Properties();
public LegacyPropertiesConfig(InputStream in) throws IOException {
properties.load(in);
}
public String get(String key) {
return properties.getProperty(key);
}
public int getInt(String key) {
return Integer.parseInt(get(key));
}
}package at.aydin.lab.config.modern;
// Design Pattern: Configuration Object
// Zweck: Zusammengehörige Einstellungen werden typisiert und validiert gebündelt.
public record ApplicationConfig(int serverPort, boolean featureEnabled) {
public ApplicationConfig {
if (serverPort < 1 || serverPort > 65535) throw new IllegalArgumentException("serverPort");
}
}package at.aydin.lab.config.modern;
import java.util.*;
// Design Pattern: Factory
// Zweck: Zentralisiert Priorität, Parsing und Validierung verschiedener Konfigurationsquellen.
public final class ConfigFactory {
public ApplicationConfig from(Properties p, Map<String, String> env) {
int port = Integer.parseInt(env.getOrDefault("APP_PORT", p.getProperty("server.port", "8080")));
boolean enabled = Boolean.parseBoolean(env.getOrDefault("FEATURE_ENABLED", p.getProperty("feature.enabled", "false")));
return new ApplicationConfig(port, enabled);
}
}Tests prüfen dieselbe Konfigurationsabsicht mit unterschiedlicher Struktur.
| Legacy-Dateien | Modern-Dateien | Einordnung |
|---|---|---|
| LegacyPropertiesConfigTest.java | ConfigFactoryTest.java | Direktvergleich Semantische Ähnlichkeit: 36% |
package at.aydin.lab.config.legacy;
import org.junit.jupiter.api.Test;
import java.io.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
class LegacyPropertiesConfigTest {
@Test
void readsStringKeys() throws Exception {
var in = getClass().getResourceAsStream("/application.properties");
assertEquals(8080, new LegacyPropertiesConfig(in).getInt("server.port"));
}
}package at.aydin.lab.config.modern;
import org.junit.jupiter.api.Test;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
class ConfigFactoryTest {
@Test
void environmentOverridesProperties() {
Properties p = new Properties();
p.setProperty("server.port", "8080");
assertEquals(9090, new ConfigFactory().from(p, Map.of("APP_PORT", "9090")).serverPort());
}
}