diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-12-23 11:57:36 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-12-23 11:57:36 +0000 |
| commit | 31fc64bc31b43c5dcddbe263a38645d146fc4e5e (patch) | |
| tree | 43933d9aa74ce9a731e50c4bc876ba4fcb71e767 /src/main/java | |
| parent | de20ae24e555535cfca7af0a4f8a48eeed2528e8 (diff) | |
Add TomlTableWithSource.getLong()
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java b/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java index 4dab6e35..725d510a 100644 --- a/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java +++ b/src/main/java/org/shedlang/compiler/config/toml/TomlTableWithSource.java @@ -148,4 +148,27 @@ public record TomlTableWithSource( TomlSource.sourceAtTomlPosition(fullSource, valuePosition) ); } + + public long getLong(String key) { + var value = table.get(key); + var valuePosition = table.inputPositionOf(key); + + if (value == null) { + throw new ConfigError( + MessageFormat.format("{0} is missing {1}", path, key), + TomlSource.sourceAtTomlPosition(fullSource, position) + ); + } + + if (value instanceof Long valueLong) { + return valueLong; + } + + throw new UnexpectedTypeConfigError( + path.plusKey(key), + "a long", + value.getClass(), + TomlSource.sourceAtTomlPosition(fullSource, valuePosition) + ); + } } |
