aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/mapper/IMappingFormat.java
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-09-01 12:09:26 +0200
committer zaaarf <zaaarf@proton.me>2023-09-01 12:09:26 +0200
commitfa6c73faf0ebdaac59a309f7c4bc114a3df99a24 (patch)
tree2fa03aa5e2be18e44725057e8288ef4007621d8f /src/main/java/ftbsc/lll/mapper/IMappingFormat.java
parentea030e54b999aba4d8c3409c1507047f0a8aa8c5 (diff)
feat: rewrote the mapper api to make more sense
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/IMappingFormat.java')
-rw-r--r--src/main/java/ftbsc/lll/mapper/IMappingFormat.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/IMappingFormat.java b/src/main/java/ftbsc/lll/mapper/IMappingFormat.java
new file mode 100644
index 0000000..00b1e0d
--- /dev/null
+++ b/src/main/java/ftbsc/lll/mapper/IMappingFormat.java
@@ -0,0 +1,49 @@
+package ftbsc.lll.mapper;
+
+import ftbsc.lll.exceptions.MalformedMappingsException;
+import ftbsc.lll.mapper.tools.Mapper;
+
+import java.util.List;
+
+/**
+ * The shared interface between all mappers.
+ */
+public interface IMappingFormat {
+ /**
+ * Checks whether this mapper can process the given lines.
+ * @param lines the lines to read
+ * @return whether this type of mapper can process these lines
+ */
+ boolean claim(List<String> lines);
+
+ /**
+ * Defines a priority for this implementation: the higher the number,
+ * the higher the priority.
+ * This is used to resolve conflicts when multiple mappers attempt to
+ * {@link #claim(List) claim} a given mapping file.
+ * @return the priority
+ */
+ default int priority() {
+ return 0;
+ }
+
+ /**
+ * Creates a {@link Mapper} given the lines, ignoring errors depending on the given flag.
+ * @param lines the lines to read
+ * @param ignoreErrors try to ignore errors and keep going
+ * @return the {@link Mapper}
+ * @throws MalformedMappingsException if an error is encountered and ignoreErrors is false
+ */
+ Mapper getMapper(List<String> lines, boolean ignoreErrors) throws MalformedMappingsException;
+
+ /**
+ * Creates a {@link Mapper} given the lines, ignoring errors depending on the given flag, and
+ * returns its inverted form.
+ * @param lines the lines to read
+ * @param ignoreErrors try to ignore errors and keep going
+ * @throws MalformedMappingsException if an error is encountered and ignoreErrors is false
+ */
+ default Mapper getInvertedMapper(List<String> lines, boolean ignoreErrors) throws MalformedMappingsException {
+ return this.getMapper(lines, ignoreErrors).getInverted();
+ }
+}