RuneHive-Game
Loading...
Searching...
No Matches
GenericParser.java
Go to the documentation of this file.
1package com.runehive.util.parser;
2
3import org.apache.logging.log4j.LogManager;
4import org.apache.logging.log4j.Logger;
5
6import java.nio.file.Path;
7import java.nio.file.Paths;
8
9/**
10 * Represents an abstract parser.
11 *
12 * @author Seven
13 */
14public abstract class GenericParser implements Runnable {
15
16 private static final Logger logger = LogManager.getLogger(GenericParser.class);
17
18 /**
19 * The path of the file to parse.
20 */
21 protected final Path path;
22
23 /**
24 * The index of the current line being parsed.
25 */
26 protected int index;
27
28 /**
29 * The file name extension to parse.
30 */
31 private final String extension;
32
33 private final boolean log;
34
35 /**
36 * Creates a new {@code GenericParser}.
37 *
38 * @param path
39 * The path of the file to parse.
40 *
41 * @param extension
42 * The file name extension.
43 *
44 * @param log
45 * The flag that denotes to log messages.
46 */
47 public GenericParser(String path, String extension , boolean log) {
48 this.path = Paths.get("./data/", path + extension);
49 this.extension = extension;
50 this.log = log;
51 }
52
53 /**
54 * The method that deserializes the file information.
55 */
56 public abstract void deserialize();
57
58 @Override
59 public void run() {
61 onRead();
62 if (log) {
63 logger.info(toString());
64 }
65 }
66
67 /**
68 * The method called after all the data has been parsed.
69 */
70 public void onRead() {
71
72 }
73
74 /**
75 * Gets the current index of the line being parsed.
76 *
77 * @return The index of this line.
78 */
79 public final int getIndex() {
80 return index;
81 }
82
83 @Override
84 public String toString() {
85 return String.format("Loaded: %d %s.", index, path.getFileName().toString().replace("_", " ").replace(extension, ""));
86 }
87
88}
Represents a single path in the path finding system.
Definition Path.java:13
int index
The index of the current line being parsed.
GenericParser(String path, String extension, boolean log)
Creates a new GenericParser.
final int getIndex()
Gets the current index of the line being parsed.
final String extension
The file name extension to parse.
final Path path
The path of the file to parse.
abstract void deserialize()
The method that deserializes the file information.
void onRead()
The method called after all the data has been parsed.