-
Notifications
You must be signed in to change notification settings - Fork 0
/
errprefixdtoatom.go
711 lines (559 loc) · 16.7 KB
/
errprefixdtoatom.go
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
package errpref
import (
"fmt"
"strings"
"sync"
)
type errPrefixDtoAtom struct {
lock *sync.Mutex
}
// addTwoDimensionalStringArray - Adds error prefix info contained
// in a 2-Dimensional string array.
func (ePrefixDtoAtom *errPrefixDtoAtom) addTwoDimensionalStringArray(
errPrefixDto *ErrPrefixDto,
twoDStrArray [][2]string,
errPrefStr string) error {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
errPrefStr = errPrefStr +
"\nerrPrefixDtoAtom." +
"addTwoDimensionalStringArray()"
if errPrefixDto == nil {
return fmt.Errorf("%v\n"+
"Error: Input parameter 'errPrefixDto' is invalid!\n"+
"'' is a 'nil' pointer.\n",
errPrefStr)
}
errPrefixDtoQuark{}.ptr().normalizeErrPrefixDto(errPrefixDto)
if twoDStrArray == nil {
return nil
}
lenTwoDStrAry := len(twoDStrArray)
if lenTwoDStrAry == 0 {
return nil
}
var ePrefInfo ErrorPrefixInfo
for i := 0; i < lenTwoDStrAry; i++ {
if len(twoDStrArray[i][0]) == 0 {
continue
}
ePrefInfo = ErrorPrefixInfo{
isFirstIdx: false,
isLastIdx: false,
isPopulated: true,
errorPrefixStr: twoDStrArray[i][0],
lenErrorPrefixStr: uint(len(twoDStrArray[i][0])),
errPrefixHasContextStr: len(twoDStrArray[i][1]) > 0,
errorContextStr: twoDStrArray[i][1],
lenErrorContextStr: uint(len(twoDStrArray[i][1])),
lock: nil,
}
errPrefixDto.ePrefCol =
append(errPrefixDto.ePrefCol,
ePrefInfo)
}
errPrefixDtoAtom{}.ptr().setFlagsErrorPrefixInfoArray(
errPrefixDto.ePrefCol)
return nil
}
// areEqualErrPrefDtos - Receives pointers to two ErrPrefixDto
// objects and proceeds to compare the internal data values.
// If the ErrPrefixDto objects contain data values which ARE EQUAL
// in all respects, this method returns 'true'.
//
// If the data values for the two ErrPrefixDto objects ARE NOT
// EQUAL, this method will return 'false'.
//
func (ePrefixDtoAtom *errPrefixDtoAtom) areEqualErrPrefDtos(
errPrefixDto1 *ErrPrefixDto,
errPrefixDto2 *ErrPrefixDto) bool {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
if errPrefixDto1 == nil ||
errPrefixDto2 == nil {
return false
}
errPrefDtoQuark := errPrefixDtoQuark{}
errPrefDtoQuark.normalizeErrPrefixDto(errPrefixDto1)
errPrefDtoQuark.normalizeErrPrefixDto(errPrefixDto2)
if errPrefixDto1.leftMarginLength !=
errPrefixDto2.leftMarginLength {
return false
}
if errPrefixDto1.leftMarginChar !=
errPrefixDto2.leftMarginChar {
return false
}
if errPrefixDto1.isLastLineTerminatedWithNewLine !=
errPrefixDto2.isLastLineTerminatedWithNewLine {
return false
}
if errPrefixDto1.turnOffTextDisplay !=
errPrefixDto2.turnOffTextDisplay {
return false
}
if !errPrefixDto1.inputStrDelimiters.Equal(
&errPrefixDto2.inputStrDelimiters) {
return false
}
if !errPrefixDto1.outputStrDelimiters.Equal(
&errPrefixDto2.outputStrDelimiters) {
return false
}
if errPrefixDto1.maxErrPrefixTextLineLength !=
errPrefixDto2.maxErrPrefixTextLineLength {
return false
}
if errPrefixDto1.leadingTextStr !=
errPrefixDto2.leadingTextStr {
return false
}
if errPrefixDto1.trailingTextStr !=
errPrefixDto2.trailingTextStr {
return false
}
if errPrefixDto1.ePrefCol == nil {
errPrefixDto1.ePrefCol =
make([]ErrorPrefixInfo, 0)
}
if errPrefixDto2.ePrefCol == nil {
errPrefixDto2.ePrefCol =
make([]ErrorPrefixInfo, 0)
}
lenIncomingEPrefCol01 :=
len(errPrefixDto1.ePrefCol)
lenIncomingEPrefCol02 :=
len(errPrefixDto2.ePrefCol)
if lenIncomingEPrefCol01 != lenIncomingEPrefCol02 {
return false
}
if lenIncomingEPrefCol01 == 0 {
return true
}
for i := 0; i < lenIncomingEPrefCol01; i++ {
if !errPrefixDto1.ePrefCol[i].Equal(&errPrefixDto2.ePrefCol[i]) {
return false
}
}
return true
}
// copyInErrPrefDto - Copies the data fields from an incoming
// instance of ErrPrefixDto ('inComingErrPrefixDto') to the data
// fields of the target ErrPrefixDto instance ('targetErrPrefixDto')
//
// All of the data fields in the 'targetErrPrefixDto' instance will
// be overwritten.
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// targetErrPrefixDto *ErrPrefixDto
// - A pointer to an instance of ErrPrefixDto. This method
// WILL CHANGE AND OVERWRITE all values of internal member
// variables encapsulated in this object to achieve the
// method's objectives.
//
// This ErrPrefixDto instance will receive all the data
// values contained from input parameter
// 'inComingErrPrefixDto'. When the copy operation is
// completed, the data values in 'targetErrPrefixDto' will be
// identical to those contained in input parameter,
// 'inComingErrPrefixDto'.
//
//
// inComingErrPrefixDto *ErrPrefixDto
// - A pointer to an instance of ErrPrefixDto. This method
// will NOT change the values of internal member variables
// contained in this instance.
//
// All data values in this ErrPrefixDto instance will be
// copied to input parameter 'targetErrPrefixDto'.
//
//
// eMsg string
// - This is an error prefix which is included in all returned
// error messages. Usually, it contains the names of the calling
// method or methods. Be sure to leave a space at the end of
// 'eMsg'.
//
//
// ------------------------------------------------------------------------
//
// Return Values
//
// err error
// - If this method completes successfully, the returned error Type
// is set to 'nil'. If errors are encountered during processing,
// the returned error Type will encapsulate an error message.
// Note that this error message will incorporate the method
// chain and text passed by input parameter, 'eMsg'.
//
func (ePrefixDtoAtom *errPrefixDtoAtom) copyInErrPrefDto(
targetErrPrefixDto *ErrPrefixDto,
inComingErrPrefixDto *ErrPrefixDto,
eMsg string) error {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
eMsg += "errPrefixDtoAtom.copyInErrPrefDto() "
if targetErrPrefixDto == nil {
return fmt.Errorf("%v\n"+
"\nInput parameter 'targetErrPrefixDto' is INVALID!\n"+
"'targetErrPrefixDto' is a nil pointer!\n",
eMsg)
}
if inComingErrPrefixDto == nil {
return fmt.Errorf("%v\n"+
"\nInput parameter 'inComingErrPrefixDto' is INVALID!\n"+
"'inComingErrPrefixDto' is a nil pointer.\n",
eMsg)
}
ePrefDtoQuark := errPrefixDtoQuark{}
ePrefDtoQuark.normalizeErrPrefixDto(inComingErrPrefixDto)
ePrefDtoQuark.normalizeErrPrefixDto(targetErrPrefixDto)
_,
err := ePrefDtoQuark.
testValidityOfErrPrefixDto(
inComingErrPrefixDto,
eMsg+"Testing validity of inComingErrPrefixDto ")
if err != nil {
return err
}
targetErrPrefixDto.isLastLineTerminatedWithNewLine =
inComingErrPrefixDto.isLastLineTerminatedWithNewLine
targetErrPrefixDto.turnOffTextDisplay =
inComingErrPrefixDto.turnOffTextDisplay
err = targetErrPrefixDto.inputStrDelimiters.CopyIn(
&inComingErrPrefixDto.inputStrDelimiters,
eMsg+
"inComingErrPrefixDto.inputStrDelimiters->"+
"targetErrPrefixDto.inputStrDelimiters ")
if err != nil {
return err
}
err = targetErrPrefixDto.outputStrDelimiters.CopyIn(
&inComingErrPrefixDto.outputStrDelimiters,
eMsg+
"inComingErrPrefixDto.outputStrDelimiters->"+
"targetErrPrefixDto.outputStrDelimiters ")
if err != nil {
return err
}
targetErrPrefixDto.maxErrPrefixTextLineLength =
inComingErrPrefixDto.maxErrPrefixTextLineLength
targetErrPrefixDto.leftMarginLength =
inComingErrPrefixDto.leftMarginLength
targetErrPrefixDto.leftMarginChar =
inComingErrPrefixDto.leftMarginChar
targetErrPrefixDto.leadingTextStr =
inComingErrPrefixDto.leadingTextStr
targetErrPrefixDto.trailingTextStr =
inComingErrPrefixDto.trailingTextStr
lenIncomingEPrefCol :=
len(inComingErrPrefixDto.ePrefCol)
if lenIncomingEPrefCol == 0 {
targetErrPrefixDto.ePrefCol = nil
return nil
}
targetErrPrefixDto.ePrefCol =
make(
[]ErrorPrefixInfo,
lenIncomingEPrefCol)
copy(
targetErrPrefixDto.ePrefCol,
inComingErrPrefixDto.ePrefCol)
return nil
}
// copyOutErrPrefDto - Creates a deep copy of the data fields contained in
// input parameter 'ePrefixDto' and returns that data as a new
// instance ErrPrefixDto.
//
//
// ------------------------------------------------------------------------
//
// Input Parameters
//
// ePrefixDto *ErrPrefixDto
// - A pointer to an instance of ErrPrefixDto. This method
// will NOT change the values of internal member variables
// contained in this object.
//
// If this ErrPrefixDto instance proves to be invalid, an
// error will be returned.
//
//
// eMsg string
// - This is an error prefix which is included in all returned
// error messages. Usually, it contains the names of the calling
// method or methods. Note: Be sure to leave a space at the end
// of 'eMsg'.
//
//
// ------------------------------------------------------------------------
//
// Return Values
//
// newEPrefixDto ErrPrefixDto
// - If this method completes successfully, a deep copy of
// input parameter 'ePrefixDto' will be returned in a new
// instance of ErrPrefixDto
//
//
// err error
// - If this method completes successfully, the returned error Type
// is set to 'nil'. If errors are encountered during processing,
// the returned error Type will encapsulate an error message.
// Note that this error message will incorporate the method
// chain and text passed by input parameter, 'eMsg'. The
// 'eMsg' text will be prefixed to the beginning of the returned
// error message.
//
func (ePrefixDtoAtom *errPrefixDtoAtom) copyOutErrPrefDto(
ePrefixDto *ErrPrefixDto,
eMsg string) (
newEPrefixDto ErrPrefixDto,
err error) {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
eMsg += "errPrefixDtoAtom.copyOutErrPrefDto() "
ePrefDtoQuark := errPrefixDtoQuark{}
newEPrefixDto = ePrefDtoQuark.
newZeroErrPrefixDto()
if ePrefixDto == nil {
err =
fmt.Errorf("%v\n"+
"\nInput parameter 'ePrefixDto' is INVALID!\n"+
"'ePrefixDto' is a nil pointer!\n",
eMsg)
return newEPrefixDto, err
}
ePrefDtoQuark.normalizeErrPrefixDto(ePrefixDto)
newEPrefixDto.isLastLineTerminatedWithNewLine =
ePrefixDto.isLastLineTerminatedWithNewLine
newEPrefixDto.turnOffTextDisplay =
ePrefixDto.turnOffTextDisplay
err =
newEPrefixDto.inputStrDelimiters.CopyIn(
&ePrefixDto.inputStrDelimiters,
eMsg+"ePrefixDto.inputStrDelimiters->"+
"newEPrefixDto.inputStrDelimiters ")
if err != nil {
return newEPrefixDto, err
}
err =
newEPrefixDto.outputStrDelimiters.CopyIn(
&ePrefixDto.outputStrDelimiters,
eMsg+"ePrefixDto.outputStrDelimiters->"+
"newEPrefixDto.outputStrDelimiters ")
if err != nil {
return newEPrefixDto, err
}
newEPrefixDto.maxErrPrefixTextLineLength =
ePrefixDto.maxErrPrefixTextLineLength
newEPrefixDto.leftMarginLength =
ePrefixDto.leftMarginLength
newEPrefixDto.leftMarginChar =
ePrefixDto.leftMarginChar
newEPrefixDto.leadingTextStr =
ePrefixDto.leadingTextStr
newEPrefixDto.trailingTextStr =
ePrefixDto.trailingTextStr
lenIncomingEPrefCol :=
len(ePrefixDto.ePrefCol)
if lenIncomingEPrefCol == 0 {
newEPrefixDto.ePrefCol = nil
return newEPrefixDto, err
}
newEPrefixDto.ePrefCol =
make(
[]ErrorPrefixInfo,
lenIncomingEPrefCol)
copy(
newEPrefixDto.ePrefCol,
ePrefixDto.ePrefCol)
return newEPrefixDto, err
}
// getEPrefContextArray - Receives a string containing a series of
// error prefix strings and error context strings. This method then
// proceeds to parse the error prefix and error context elements
// returning the results in an array of ErrorPrefixInfo objects
// passed as input parameter, 'prefixContextCol' .
//
// All error prefix elements parsed from the 'errPrefix' string
// will be appended to 'prefixContextCol'.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// errPrefix string
// - This string contains a series of error prefix and error
// context strings. Input parameter 'errPrefix' will be
// parsed into error prefix and error context components
// before being appended to array of ErrorPrefixInfo objects
// passed in input parameter, 'prefixContextCol'
//
// This string should consist of a series of error prefix
// strings. Error prefixes should be delimited by either a
// new line character ('\n') or the in-line delimiter string,
// " - ".
//
// If this string contains associated error context strings
// as well, they should be delimited with either a new line
// delimiter string, "\n : " or an in-line delimiter string,
// " : ".
//
//
// prefixContextCol *[]ErrorPrefixInfo
// - A pointer to an array of ErrorPrefixInfo objects. The
// error prefix and error context data elements parsed from
// input parameter, 'errPrefix', will be appended to this
// array.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// --- NONE ---
//
func (ePrefixDtoAtom *errPrefixDtoAtom) getEPrefContextArray(
errPrefix string,
delimiters ErrPrefixDelimiters,
prefixContextCol *[]ErrorPrefixInfo) {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
if *prefixContextCol == nil {
*prefixContextCol = make([]ErrorPrefixInfo, 0)
}
if len(errPrefix) == 0 {
return
}
ePrefElectron := errPrefElectron{}
var lenCleanPrefixStr int
errPrefix,
lenCleanPrefixStr = ePrefElectron.cleanErrorPrefixStr(errPrefix)
if lenCleanPrefixStr == 0 {
return
}
errPrefix = strings.ReplaceAll(
errPrefix,
delimiters.GetNewLineContextDelimiter(),
delimiters.GetInLineContextDelimiter())
errPrefix = strings.ReplaceAll(
errPrefix,
delimiters.GetInLinePrefixDelimiter(),
delimiters.GetNewLinePrefixDelimiter())
errPrefix += delimiters.GetNewLinePrefixDelimiter()
errPrefixContextCollection := strings.Split(
errPrefix,
delimiters.GetNewLinePrefixDelimiter())
lCollection := len(errPrefixContextCollection)
if lCollection == 0 {
return
}
var contextIdx int
var idxLenInLineContextDelimiter = int(delimiters.GetLengthInLineContextDelimiter() - 1)
var (
errPrefixStr,
errCtxStr string
)
ePrefNeutron := errPrefNeutron{}
for i := 0; i < lCollection; i++ {
s := errPrefixContextCollection[i]
contextIdx = strings.Index(s,
delimiters.GetInLineContextDelimiter())
if contextIdx == -1 {
element,
err := ePrefNeutron.createNewEPrefInfo(
s,
"",
"")
if err != nil {
continue
}
*prefixContextCol = append(*prefixContextCol, element)
} else {
errPrefixStr =
s[0:contextIdx]
errCtxStr = s[contextIdx+
idxLenInLineContextDelimiter:]
element,
err := ePrefNeutron.createNewEPrefInfo(
errPrefixStr,
errCtxStr,
"")
if err != nil {
continue
}
*prefixContextCol = append(*prefixContextCol, element)
}
}
return
}
// ptr() - Returns a pointer to a new instance of
// errPrefixDtoAtom.
//
func (ePrefixDtoAtom errPrefixDtoAtom) ptr() *errPrefixDtoAtom {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
return &errPrefixDtoAtom{}
}
// setFlagsErrorPrefixInfoArray - Sets internal flags in an array
// of ErrorPrefixInfo objects
//
func (ePrefixDtoAtom *errPrefixDtoAtom) setFlagsErrorPrefixInfoArray(
prefixContextCol []ErrorPrefixInfo) {
if ePrefixDtoAtom.lock == nil {
ePrefixDtoAtom.lock = new(sync.Mutex)
}
ePrefixDtoAtom.lock.Lock()
defer ePrefixDtoAtom.lock.Unlock()
if prefixContextCol == nil {
prefixContextCol = make([]ErrorPrefixInfo, 0)
}
lenCollection := len(prefixContextCol)
if lenCollection == 0 {
return
}
if lenCollection == 1 {
prefixContextCol[0].SetIsFirstIndex(true)
prefixContextCol[0].SetIsLastIndex(true)
return
}
lastIdx := lenCollection - 1
for i := 0; i < lenCollection; i++ {
_ = prefixContextCol[i].GetIsPopulated()
switch i {
case 0:
prefixContextCol[i].SetIsFirstIndex(true)
prefixContextCol[i].SetIsLastIndex(false)
case lastIdx:
prefixContextCol[i].SetIsFirstIndex(false)
prefixContextCol[i].SetIsLastIndex(true)
default:
prefixContextCol[i].SetIsFirstIndex(false)
prefixContextCol[i].SetIsLastIndex(false)
}
}
return
}