summaryrefslogtreecommitdiff
path: root/docs/jacoco-ut/bjc.everge/Everge.java.html
blob: d4a06c140cc17fb1ebdd9aca40044b8e47cb691a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Everge.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">everge</a> &gt; <a href="index.source.html" class="el_package">bjc.everge</a> &gt; <span class="el_source">Everge.java</span></div><h1>Everge.java</h1><pre class="source lang-java linenums">package bjc.everge;

import java.io.*;
import java.nio.charset.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.locks.*;
import java.util.regex.*;

/**
 * Everge front-end application.
 *
 * @author Ben Culkin
 */
<span class="fc" id="L15">public class Everge {</span>
	/**
	 * Details how we handle our input.
	 */
<span class="fc" id="L19">	public static enum InputStatus {</span>
		/**
		 * Process the input as a single string.
		 */
<span class="fc" id="L23">		ALL,</span>
		/**
		 * Process the input line-by-line.
		 */
<span class="fc" id="L27">		LINE,</span>
		/**
		 * Process the input, splitting it around occurances of a regex.
		 */
<span class="fc" id="L31">		REGEX;</span>
	}

	// Options for doing repl-pairs
<span class="fc" id="L35">	private ReplOpts ropts = new ReplOpts();</span>

	// Pair repository
<span class="fc" id="L38">	private ReplSet replSet = new ReplSet();</span>

	// Input status
<span class="fc" id="L41">	private InputStatus inputStat = InputStatus.ALL;</span>

	// Are we processing CLI args? (haven't seen a -- yet)
<span class="fc" id="L44">	private boolean doingArgs = true;</span>

	// Should an NL be printed after each replace?
<span class="fc" id="L47">	private boolean printNL = true;</span>

	// Verbosity level
	private int verbosity;

	// The pattern to use for REGEX input mode
	private String pattern;

	// The queue of arguments to process
<span class="fc" id="L56">	private Deque&lt;String&gt; argQue = new LinkedList&lt;&gt;();</span>

	// Used to prevent inter-mixing argument alterations with input processing.
<span class="fc" id="L59">	private ReadWriteLock argLock = new ReentrantReadWriteLock();</span>

	// Input/output streams
	/**
	 * Stream to use for normal output.
	 */
<span class="fc" id="L65">	private PrintStream outStream = System.out;</span>
	/**
	 * Stream to use for error output.
	 */
<span class="fc" id="L69">	private LogStream errStream = new LogStream(System.err);</span>

	/**
	 * Set the output stream.
	 * 
	 * @param out
	 *            The output stream..
	 */
	public void setOutput(PrintStream out) {
<span class="nc" id="L78">		outStream = out;</span>
<span class="nc" id="L79">	}</span>

	/**
	 * Set the output stream.
	 * 
	 * @param out
	 *            The output stream..
	 */
	public void setOutput(OutputStream out) {
<span class="fc" id="L88">		outStream = new PrintStream(out);</span>
<span class="fc" id="L89">	}</span>

	/**
	 * Set the error stream.
	 * 
	 * @param err
	 *            The error stream.
	 */
	public void setError(PrintStream err) {
<span class="nc" id="L98">		errStream = new LogStream(err);</span>
<span class="nc" id="L99">	}</span>

	/**
	 * Set the error stream.
	 * 
	 * @param err
	 *            The error stream.
	 */
	public void setError(OutputStream err) {
<span class="fc" id="L108">		errStream = new LogStream(new PrintStream(err));</span>
<span class="fc" id="L109">	}</span>

	/**
	 * Main method for front end,
	 *
	 * @param args
	 *             The CLI arguments.
	 */
	public static void main(String[] args) {
<span class="nc" id="L118">		Everge evg = new Everge();</span>

<span class="nc" id="L120">		evg.processArgs(args);</span>
<span class="nc" id="L121">	}</span>

	/**
	 * Process one or more command line arguments.
	 *
	 * @param args
	 *             The arguments to process.
	 * @return Whether we processed succesfully or not.
	 */
	public boolean processArgs(String... args) {
<span class="fc" id="L131">		List&lt;String&gt; errs = new ArrayList&lt;&gt;();</span>

<span class="fc" id="L133">		boolean stat = processArgs(errs, args);</span>
<span class="pc bpc" id="L134" title="1 of 2 branches missed.">		if (verbosity &gt;= 2) {</span>
<span class="pc bpc" id="L135" title="1 of 2 branches missed.">			String argString = args.length &gt; 0 ? &quot;arguments&quot; : &quot;argument&quot;;</span>

<span class="fc" id="L137">			errStream.infof(&quot;[INFO] Processed %d %s\n&quot;, args.length, argString);</span>
<span class="fc" id="L138">			int argc = 0;</span>
<span class="pc bpc" id="L139" title="1 of 2 branches missed.">			if (verbosity &gt;= 3) {</span>
<span class="fc" id="L140">				String arg = args[argc++];</span>
<span class="fc" id="L141">				errStream.tracef(&quot;[TRACE]\tArg %d: '%s\n&quot;, argc, arg);</span>
			}
		}

<span class="pc bpc" id="L145" title="1 of 2 branches missed.">		if (!stat) {</span>
<span class="nc bnc" id="L146" title="All 2 branches missed.">			for (String err : errs) {</span>
<span class="nc" id="L147">				errStream.errorf(&quot;%s\n&quot;, err);</span>
<span class="nc" id="L148">			}</span>
		}

<span class="fc" id="L151">		return stat;</span>
	}

	/**
	 * Process one or more command line arguments.
	 *
	 * @param args
	 *             The arguments to process.
	 * @param errs
	 *             The list to stash errors in.
	 * @return Whether we processed succesfully or not.
	 */
	public boolean processArgs(List&lt;String&gt; errs, String... args) {
<span class="fc" id="L164">		argLock.writeLock().lock();</span>

<span class="fc" id="L166">		boolean retStat = true;</span>

		try {
<span class="fc" id="L169">			loadQueue(args);</span>

			// Process CLI args
<span class="fc bfc" id="L172" title="All 2 branches covered.">			while (argQue.size() &gt; 0) {</span>
<span class="fc" id="L173">				String arg = argQue.pop();</span>

<span class="fc" id="L175">				retStat = processArg(errs, retStat, arg);</span>
<span class="fc" id="L176">			}</span>
		} finally {
<span class="fc" id="L178">			argLock.writeLock().unlock();</span>
		}

<span class="fc" id="L181">		return retStat;</span>
	}

	private boolean processArg(List&lt;String&gt; errs, boolean retStat, String arg) {
<span class="fc" id="L185">		boolean newRet = retStat;</span>

<span class="pc bpc" id="L187" title="1 of 2 branches missed.">		if (arg.equals(&quot;--&quot;)) {</span>
<span class="nc" id="L188">			doingArgs = false;</span>
<span class="nc" id="L189">			return newRet;</span>
		}

		// Process an argument
<span class="pc bpc" id="L193" title="1 of 4 branches missed.">		if (doingArgs &amp;&amp; arg.startsWith(&quot;-&quot;)) {</span>
<span class="fc" id="L194">			String argName = arg;</span>
<span class="fc" id="L195">			String argBody = &quot;&quot;;</span>

			// Process arguments to arguments
<span class="fc" id="L198">			int idx = arg.indexOf(&quot;=&quot;);</span>
<span class="pc bpc" id="L199" title="1 of 2 branches missed.">			if (idx != -1) {</span>
<span class="nc" id="L200">				argName = arg.substring(0, idx);</span>
<span class="nc" id="L201">				argBody = arg.substring(idx + 1);</span>
			}

<span class="pc bpc" id="L204" title="11 of 15 branches missed.">			switch (argName) {</span>
			case &quot;-n&quot;:
			case &quot;--newline&quot;:
<span class="nc" id="L207">				printNL = true;</span>
<span class="nc" id="L208">				break;</span>
			case &quot;-N&quot;:
			case &quot;--no-newline&quot;:
<span class="nc" id="L211">				printNL = false;</span>
<span class="nc" id="L212">				break;</span>
			case &quot;-v&quot;:
			case &quot;--verbose&quot;:
<span class="fc" id="L215">				verbosity += 1;</span>
<span class="fc" id="L216">				errStream.louder();</span>
<span class="fc" id="L217">				System.err.printf(&quot;[TRACE] Incremented verbosity\n&quot;);</span>
<span class="fc" id="L218">				break;</span>
			case &quot;-q&quot;:
			case &quot;--quiet&quot;:
<span class="nc" id="L221">				verbosity -= 1;</span>
<span class="nc" id="L222">				errStream.quieter();</span>
<span class="nc" id="L223">				System.err.printf(&quot;[TRACE] Decremented verbosity\n&quot;);</span>
<span class="nc" id="L224">				break;</span>
			case &quot;--verbosity&quot;:
<span class="pc bpc" id="L226" title="1 of 2 branches missed.">				if (argQue.size() &lt; 1) {</span>
<span class="nc" id="L227">					errs.add(&quot;[ERROR] No parameter to --verbosity&quot;);</span>
<span class="nc" id="L228">					newRet = false;</span>
<span class="nc" id="L229">					break;</span>
				}
<span class="fc" id="L231">				argBody = argQue.pop();</span>
			case &quot;-V&quot;:
				try {
<span class="fc" id="L234">					verbosity = Integer.parseInt(argBody);</span>
<span class="fc" id="L235">					errStream.verbosity(verbosity);</span>
<span class="fc" id="L236">					System.err.printf(&quot;[TRACE] Set verbosity to %d\n&quot;, verbosity);</span>
<span class="nc" id="L237">				} catch (NumberFormatException nfex) {</span>
<span class="nc" id="L238">					String msg = String.format(</span>
							&quot;[ERROR] Invalid verbosity: '%s' is not an integer&quot;, argBody);
<span class="nc" id="L240">					errs.add(msg);</span>
<span class="nc" id="L241">					newRet = false;</span>
<span class="fc" id="L242">				}</span>
<span class="nc" id="L243">				break;</span>
			case &quot;--pattern&quot;:
<span class="nc bnc" id="L245" title="All 2 branches missed.">				if (argQue.size() &lt; 1) {</span>
<span class="nc" id="L246">					errs.add(&quot;[ERROR] No parameter to --pattern&quot;);</span>
<span class="nc" id="L247">					newRet = false;</span>
<span class="nc" id="L248">					break;</span>
				}
<span class="nc" id="L250">				argBody = argQue.pop();</span>
			case &quot;-p&quot;:
				try {
<span class="nc" id="L253">					pattern = argBody;</span>

<span class="nc" id="L255">					Pattern.compile(argBody);</span>
<span class="nc" id="L256">				} catch (PatternSyntaxException psex) {</span>
<span class="nc" id="L257">					String msg = String.format(&quot;[ERROR] Pattern '%s' is invalid: %s&quot;,</span>
<span class="nc" id="L258">							pattern, psex.getMessage());</span>
<span class="nc" id="L259">					errs.add(msg);</span>
<span class="nc" id="L260">					newRet = false;</span>
<span class="nc" id="L261">				}</span>
<span class="nc" id="L262">				break;</span>
			case &quot;--file&quot;:
<span class="pc bpc" id="L264" title="1 of 2 branches missed.">				if (argQue.size() &lt; 1) {</span>
<span class="nc" id="L265">					errs.add(&quot;[ERROR] No argument to --file&quot;);</span>
<span class="nc" id="L266">					newRet = false;</span>
<span class="nc" id="L267">					break;</span>
				}
<span class="fc" id="L269">				argBody = argQue.pop();</span>
			case &quot;-f&quot;:
<span class="fc" id="L271">				try (FileInputStream fis = new FileInputStream(argBody);</span>
<span class="fc" id="L272">						Scanner scn = new Scanner(fis)) {</span>
<span class="fc" id="L273">					List&lt;ReplError&gt; ferrs = new ArrayList&lt;&gt;();</span>

<span class="fc" id="L275">					List&lt;ReplPair&gt; lrp = new ArrayList&lt;&gt;();</span>
<span class="fc" id="L276">					lrp = ReplPair.readList(lrp, scn, ferrs, ropts);</span>

<span class="pc bpc" id="L278" title="1 of 2 branches missed.">					if (ferrs.size() &gt; 0) {</span>
<span class="nc" id="L279">						StringBuilder sb = new StringBuilder();</span>

<span class="nc" id="L281">						String errString = &quot;an error&quot;;</span>
<span class="nc bnc" id="L282" title="All 2 branches missed.">						if (ferrs.size() &gt; 1)</span>
<span class="nc" id="L283">							errString = String.format(&quot;%d errors&quot;, ferrs.size());</span>

						{
<span class="nc" id="L286">							String msg = String.format(</span>
									&quot;[ERROR] Encountered %s parsing data file'%s'\n&quot;,
									errString, argBody);
<span class="nc" id="L289">							sb.append(msg);</span>
						}

<span class="nc bnc" id="L292" title="All 2 branches missed.">						for (ReplError err : ferrs) {</span>
<span class="nc" id="L293">							sb.append(String.format(&quot;\t%s\n&quot;, err));</span>
<span class="nc" id="L294">						}</span>

<span class="nc" id="L296">						errs.add(sb.toString());</span>
<span class="nc" id="L297">						newRet = false;</span>
					}

<span class="fc" id="L300">					replSet.addPairs(lrp);</span>
<span class="nc" id="L301">				} catch (FileNotFoundException fnfex) {</span>
<span class="nc" id="L302">					String msg = String.format(</span>
							&quot;[ERROR] Could not open data file '%s' for input&quot;, argBody);
<span class="nc" id="L304">					errs.add(msg);</span>
<span class="nc" id="L305">					newRet = false;</span>
<span class="nc" id="L306">				} catch (IOException ioex) {</span>
<span class="nc" id="L307">					String msg = String.format(</span>
							&quot;[ERROR] Unknown I/O error reading data file '%s': %s&quot;,
<span class="nc" id="L309">							argBody, ioex.getMessage());</span>
<span class="nc" id="L310">					errs.add(msg);</span>
<span class="nc" id="L311">					newRet = false;</span>
<span class="pc" id="L312">				}</span>
<span class="nc" id="L313">				break;</span>
			case &quot;--arg-file&quot;:
<span class="nc bnc" id="L315" title="All 2 branches missed.">				if (argQue.size() &lt; 1) {</span>
<span class="nc" id="L316">					errs.add(&quot;[ERROR] No argument to --arg-file&quot;);</span>
<span class="nc" id="L317">					break;</span>
				}
<span class="nc" id="L319">				argBody = argQue.pop();</span>
			case &quot;-F&quot;:
<span class="nc" id="L321">				try (FileInputStream fis = new FileInputStream(argBody);</span>
<span class="nc" id="L322">						Scanner scn = new Scanner(fis)) {</span>
<span class="nc" id="L323">					List&lt;String&gt; sl = new ArrayList&lt;&gt;();</span>

<span class="nc bnc" id="L325" title="All 2 branches missed.">					while (scn.hasNextLine()) {</span>
<span class="nc" id="L326">						String ln = scn.nextLine().trim();</span>

<span class="nc bnc" id="L328" title="All 2 branches missed.">						if (ln.equals(&quot;&quot;))</span>
<span class="nc" id="L329">							continue;</span>
<span class="nc bnc" id="L330" title="All 2 branches missed.">						if (ln.startsWith(&quot;#&quot;))</span>
<span class="nc" id="L331">							continue;</span>

<span class="nc" id="L333">						sl.add(ln);</span>
<span class="nc" id="L334">					}</span>

<span class="nc" id="L336">					processArgs(sl.toArray(new String[0]));</span>
<span class="nc" id="L337">				} catch (FileNotFoundException fnfex) {</span>
<span class="nc" id="L338">					String msg = String.format(</span>
							&quot;[ERROR] Could not open argument file '%s' for input&quot;,
							argBody);
<span class="nc" id="L341">					errs.add(msg);</span>
<span class="nc" id="L342">					newRet = false;</span>
<span class="nc" id="L343">				} catch (IOException ioex) {</span>
<span class="nc" id="L344">					String msg = String.format(</span>
							&quot;[ERROR] Unknown I/O error reading input file '%s': %s&quot;,
<span class="nc" id="L346">							argBody, ioex.getMessage());</span>
<span class="nc" id="L347">					errs.add(msg);</span>
<span class="nc" id="L348">					newRet = false;</span>
<span class="nc" id="L349">				}</span>
<span class="nc" id="L350">				break;</span>
			case &quot;--input-status&quot;:
<span class="pc bpc" id="L352" title="1 of 2 branches missed.">				if (argQue.size() &lt; 1) {</span>
<span class="nc" id="L353">					errs.add(&quot;[ERROR] No argument to --input-status&quot;);</span>
<span class="nc" id="L354">					break;</span>
				}
<span class="fc" id="L356">				argBody = argQue.pop();</span>
			case &quot;-I&quot;:
				try {
<span class="fc" id="L359">					inputStat = InputStatus.valueOf(argBody.toUpperCase());</span>
<span class="nc" id="L360">				} catch (IllegalArgumentException iaex) {</span>
<span class="nc" id="L361">					String msg = String.format(&quot;[ERROR] '%s' is not a valid input status&quot;,</span>
							argBody);
<span class="nc" id="L363">					errs.add(msg);</span>
<span class="fc" id="L364">				}</span>
<span class="nc" id="L365">				break;</span>
			default: {
<span class="nc" id="L367">				String msg = String</span>
<span class="nc" id="L368">						.format(&quot;[ERROR] Unrecognised CLI argument name '%s'\n&quot;, argName);</span>
<span class="nc" id="L369">				errs.add(msg);</span>
<span class="nc" id="L370">				newRet = false;</span>
			}
			}
<span class="fc" id="L373">		} else {</span>
<span class="fc" id="L374">			String tmp = arg;</span>
			// Strip off an escaped initial dash
<span class="pc bpc" id="L376" title="1 of 2 branches missed.">			if (tmp.startsWith(&quot;\\-&quot;))</span>
<span class="nc" id="L377">				tmp = tmp.substring(1);</span>

<span class="fc" id="L379">			processInputFile(tmp);</span>
		}

<span class="fc" id="L382">		return newRet;</span>
	}

	/**
	 * Process a input file.
	 *
	 * @param fle
	 *            Input file to process.
	 * @return Whether we processed succesfully or not.
	 */
	public boolean processInputFile(String fle) {
<span class="fc" id="L393">		List&lt;String&gt; errs = new ArrayList&lt;&gt;();</span>

<span class="fc" id="L395">		boolean stat = processInputFile(errs, fle);</span>
<span class="pc bpc" id="L396" title="1 of 2 branches missed.">		if (!stat) {</span>
<span class="nc bnc" id="L397" title="All 2 branches missed.">			for (String err : errs) {</span>
<span class="nc" id="L398">				errStream.errorf(&quot;%s\n&quot;, err);</span>
<span class="nc" id="L399">			}</span>
		}

<span class="fc" id="L402">		return stat;</span>
	}

	/**
	 * Process a input file.
	 *
	 * @param fle
	 *             Input file to process.
	 * @param errs
	 *             List to accumulate errors in.
	 * @return Whether we processed succesfully or not.
	 */
	public boolean processInputFile(List&lt;String&gt; errs, String fle) {
<span class="fc" id="L415">		argLock.readLock().lock();</span>

		// Read in and do replacements on a file
		try {
<span class="pc bpc" id="L419" title="1 of 2 branches missed.">			if (verbosity &gt; 2) {</span>
<span class="fc" id="L420">				errStream.printf(&quot;[TRACE] Reading file (%s) in mode (%s)\n&quot;, fle,</span>
						inputStat);
			}

<span class="pc bpc" id="L424" title="1 of 2 branches missed.">			if (inputStat == InputStatus.ALL) {</span>
<span class="nc" id="L425">				Path pth = Paths.get(fle);</span>

<span class="nc bnc" id="L427" title="All 2 branches missed.">				if (!Files.isReadable(pth)) {</span>
<span class="nc" id="L428">					String msg</span>
<span class="nc" id="L429">							= String.format(&quot;[ERROR] File '%s' is not readable\n&quot;, fle);</span>
<span class="nc" id="L430">					errs.add(msg);</span>
<span class="nc" id="L431">					return false;</span>
				}

<span class="nc" id="L434">				byte[] inp = Files.readAllBytes(pth);</span>

<span class="nc" id="L436">				String strang = new String(inp, Charset.forName(&quot;UTF-8&quot;));</span>

<span class="nc" id="L438">				processString(strang);</span>
<span class="pc bpc" id="L439" title="1 of 2 branches missed.">			} else if (inputStat == InputStatus.LINE) {</span>
<span class="fc" id="L440">				try (FileInputStream fis = new FileInputStream(fle);</span>
<span class="fc" id="L441">						Scanner scn = new Scanner(fis)) {</span>
<span class="fc bfc" id="L442" title="All 2 branches covered.">					while (scn.hasNextLine()) {</span>
<span class="fc" id="L443">						processString(scn.nextLine());</span>
					}
<span class="fc" id="L445">				}</span>
<span class="nc bnc" id="L446" title="All 2 branches missed.">			} else if (inputStat == InputStatus.REGEX) {</span>
<span class="nc" id="L447">				try (FileInputStream fis = new FileInputStream(fle);</span>
<span class="nc" id="L448">						Scanner scn = new Scanner(fis)) {</span>
<span class="nc" id="L449">					scn.useDelimiter(pattern);</span>

<span class="nc bnc" id="L451" title="All 2 branches missed.">					while (scn.hasNext()) {</span>
<span class="nc" id="L452">						processString(scn.next());</span>
					}
<span class="nc" id="L454">				}</span>
			} else {
<span class="nc" id="L456">				String msg = String.format(</span>
						&quot;[INTERNAL-ERROR] Input status '%s' is not yet implemented\n&quot;,
						inputStat);
<span class="nc" id="L459">				errs.add(msg);</span>
<span class="nc" id="L460">				return false;</span>
			}
<span class="nc" id="L462">		} catch (IOException ioex) {</span>
<span class="nc" id="L463">			String msg = String.format(</span>
					&quot;[ERROR] Unknown I/O related error for file '%s'\n\tError was %s&quot;,
<span class="nc" id="L465">					fle, ioex.getMessage());</span>
<span class="nc" id="L466">			errs.add(msg);</span>
<span class="nc" id="L467">			return false;</span>
		} finally {
<span class="fc" id="L469">			argLock.readLock().unlock();</span>
		}

<span class="fc" id="L472">		return true;</span>
	}

	/**
	 * Process an input string.
	 *
	 * @param inp
	 *            The input string to process.
	 */
	public void processString(String inp) {
<span class="fc" id="L482">		argLock.readLock().lock();</span>

		try {
<span class="fc" id="L485">			String strang = inp;</span>

<span class="pc bpc" id="L487" title="1 of 2 branches missed.">			if (verbosity &gt;= 3) {</span>
<span class="fc" id="L488">				errStream.infof(</span>
						&quot;[INFO] Processing replacements for string '%s' in mode %s\n&quot;,
						strang, inputStat);
				
<span class="pc bpc" id="L492" title="1 of 2 branches missed.">				if (!inp.equals(inp.trim())) {</span>
<span class="nc" id="L493">					errStream.infof(&quot;[INFO] String '%s' has trailing spaces on it\n&quot;, inp);</span>
				}
			}

<span class="fc" id="L497">			strang = replSet.apply(inp);</span>

<span class="fc" id="L499">			outStream.print(strang);</span>
<span class="pc bpc" id="L500" title="1 of 2 branches missed.">			if (printNL)</span>
<span class="fc" id="L501">				outStream.println();</span>
		} finally {
<span class="fc" id="L503">			argLock.readLock().unlock();</span>
		}
<span class="fc" id="L505">	}</span>

	// Load arguments into the argument queue.
	private void loadQueue(String... args) {
<span class="fc" id="L509">		boolean doArgs = true;</span>
<span class="fc bfc" id="L510" title="All 2 branches covered.">		for (String arg : args) {</span>
<span class="pc bpc" id="L511" title="1 of 2 branches missed.">			if (arg.equals(&quot;--&quot;)) {</span>
<span class="nc" id="L512">				doArgs = false;</span>
			}

			// Handle things like -nNv correctly
<span class="pc bpc" id="L516" title="1 of 2 branches missed.">			if (doArgs) {</span>
<span class="fc bfc" id="L517" title="All 4 branches covered.">				if (arg.startsWith(&quot;-&quot;) &amp;&amp; !arg.startsWith(&quot;--&quot;)) {</span>
<span class="fc" id="L518">					char[] car = arg.substring(1).toCharArray();</span>

<span class="pc bpc" id="L520" title="1 of 2 branches missed.">					if (verbosity &gt;= 3) {</span>
<span class="nc" id="L521">						errStream.infof(&quot;[INFO] Adding stream of args: %s&quot;, car);</span>
					}

<span class="fc bfc" id="L524" title="All 2 branches covered.">					for (char c : car) {</span>
<span class="fc" id="L525">						String argstr = String.format(&quot;-%c&quot;, c);</span>
<span class="fc" id="L526">						argQue.add(argstr);</span>
					}
<span class="fc" id="L528">				} else {</span>
<span class="fc" id="L529">					argQue.add(arg);</span>
				}
			} else {
<span class="nc" id="L532">				argQue.add(arg);</span>
			}
		}
<span class="fc" id="L535">	}</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.2.201808211720</span></div></body></html>