Debian Codegraph @

current/shared/LineParser.java

raw symbols SCIP
1 package shared;
2
3 import java.util.ArrayList;
4
5 import structures.ByteBuilder;
6
7 /**
8 * Interface for classes that parse delimited byte[] lines.
9 *
10 * @author Brian Bushnell
11 * @date May 24, 2023
12 *
13 */
14 public interface LineParser {
15
16 /**
17 * Designate the line of text to be parsed.
18 * @param line Line to parse.
19 * @return this
20 */
21 public LineParser set(byte[] line);
22
23 /**
24 * Designate the line of text to be parsed.
25 * @param line Line to parse.
26 * @param maxTerm Stop parsing after this term.
27 * @return this
28 */
29 public LineParser set(byte[] line, int maxTerm);
30
31 /**
32 * Clear all internal state.
33 * @return this
34 */
35 public LineParser clear();
36
37 /**
38 * Reset state to the start of the current line.
39 * @return this
40 */
41 public LineParser reset();
42
43 /**
44 * Parse the designated field as an int.
45 * @param term Field to parse.
46 * @return int value.
47 */
48 public int parseInt(int term);
49
50 /**
51 * Parse the current field as an int.
52 * @return int value.
53 */
54 public int parseIntFromCurrentField();
55
56 /**
57 * Parse the designated field as a long.
58 * @param term Field to parse.
59 * @return long value.
60 */
61 public long parseLong(int term);
62
63 /**
64 * Parse the designated field as a float.
65 * @param term Field to parse.
66 * @return float value.
67 */
68 public float parseFloat(int term);
69
70 /**
71 * Parse the designated field as a double.
72 * @param term Field to parse.
73 * @return double value.
74 */
75 public double parseDouble(int term);
76
77 /**
78 * Parse a byte from the designated field.
79 * @param term Field to parse.
80 * @param offset Position in the field to read.
81 * @return byte value.
82 */
83 public byte parseByte(int term, int offset);
84
85 /**
86 * Parse the designated field as a byte[].
87 * @param term Field to parse.
88 * @return A byte[].
89 */
90 public byte[] parseByteArray(int term);
91
92 /**
93 * Parse the designated field as a String.
94 * @param term Field to parse.
95 * @return A String.
96 */
97 public String parseString(int term);
98
99 /**
100 * USE CAUTION WITH THIS METHOD.
101 * Parse the current field as a String.
102 * @return A String.
103 */
104 public String parseStringFromCurrentField();
105
106 /**
107 * USE CAUTION WITH THIS METHOD.
108 * Parse the current field as a byte[].
109 * @return A byte[].
110 */
111 public byte[] parseByteArrayFromCurrentField();
112
113 /** Append the raw term to bb without parsing, and without delimiters */
114 public ByteBuilder appendTerm(ByteBuilder bb, int term);
115
116 /** Convenience method; determines whether the line starts with this term.
117 * Implemented in Tools. */
118 public boolean startsWith(String s);
119
120 /** Convenience method; determines whether the line starts with this character.
121 * Implemented in Tools. */
122 public boolean startsWith(char c);
123
124 /** Convenience method; determines whether the line starts with this character.
125 * Implemented in Tools. */
126 public boolean startsWith(byte c);
127
128 /** True if the term starts with s */
129 public boolean termStartsWith(String s, int term);
130
131 /** True if the term equals s */
132 public boolean termEquals(String s, int term);
133
134 /** True if the term equals c */
135 public boolean termEquals(char c, int term);
136
137 /** True if the term equals c */
138 public boolean termEquals(byte c, int term);
139
140 /** Length of this field. */
141 public int length(int term);
142
143 /** Length of current field. */
144 public int currentFieldLength();
145
146 /** Not recommended. Secret method. */
147 public int incrementA(int amt);
148
149 /** Not recommended. Secret method. */
150 public int incrementB(int amt);
151
152 /** True if there is a subsequent term */
153 public boolean hasMore();
154
155 /** Length of the line being parsed */
156 public int lineLength();
157
158 /** LP1 and LP2 both can use this, but LP2 will fail if it's advancing backwards. */
159 int setBounds(int term);
160
161 /** Line being parsed */
162 public Object line();
163
164 /** Position of left pointer (first character of current term) */
165 public int a();
166
167 /** Position of right pointer (just after end of current term) */
168 public int b();
169
170 @Override
171 public String toString();
172
173 /**
174 * Format the line as a list of Strings, one per field.
175 * @return A List.
176 */
177 public ArrayList<String> toList();
178
179 }