-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3381ab0
commit 3165947
Showing
4 changed files
with
60 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
autograder-api/src/main/java/de/firemage/autograder/api/FluentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.firemage.autograder.api; | ||
|
||
import fluent.bundle.FluentResource; | ||
import fluent.syntax.parser.FTLParser; | ||
import fluent.syntax.parser.FTLStream; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Helper for building FluentResources from strings. | ||
*/ | ||
public class FluentBuilder { | ||
private final List<String> lines = new ArrayList<>(); | ||
|
||
public static FluentResource ofSingle(String id, String value) { | ||
return build(id + " = " + value); | ||
} | ||
|
||
public FluentBuilder message(String id, String value) { | ||
lines.add(id + " = " + value); | ||
return this; | ||
} | ||
|
||
public FluentResource build() { | ||
return build(String.join("\n", lines)); | ||
} | ||
|
||
private static FluentResource build(String content) { | ||
if (content.isBlank()) { | ||
return new FluentResource(List.of(), List.of(), List.of()); | ||
} | ||
|
||
var bundle = FTLParser.parse(FTLStream.of(content)); | ||
if (bundle.hasErrors()) { | ||
throw new IllegalStateException("Could not parse the fluent resource: " + bundle.errors().toString()); | ||
} | ||
return bundle; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters