-
Notifications
You must be signed in to change notification settings - Fork 0
/
errprefixdtoquark.go
321 lines (235 loc) · 7.31 KB
/
errprefixdtoquark.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
package errpref
import (
"fmt"
"sync"
)
type errPrefixDtoQuark struct {
lock *sync.Mutex
}
// deleteLastErrPrefixInfo - Deletes the last Error Prefix
// Information object in the collection maintained by the input
// parameter 'ePrefixDto', an instance of ErrPrefixDto.
//
// After the deletion operation is completed, this method returns a
// boolean value indicating whether the remaining collection of
// Error Prefix Information objects is empty.
//
// Note: After completing the deletion operation, this method will
// set the appropriate flags on the last Error Prefix Information
// object in the modified collection.
//
func (ePrefDtoQuark *errPrefixDtoQuark) deleteLastErrPrefixInfo(
ePrefixDto *ErrPrefixDto,
errPrefStr string) (
isEmpty bool,
err error) {
if ePrefDtoQuark.lock == nil {
ePrefDtoQuark.lock = new(sync.Mutex)
}
ePrefDtoQuark.lock.Lock()
defer ePrefDtoQuark.lock.Unlock()
errPrefStr = errPrefStr +
"\nerrPrefixDtoQuark.deleteLastErrPrefixInfo()"
isEmpty = false
if ePrefixDto == nil {
err = fmt.Errorf("%v\n"+
"Error: Input parameter 'ePrefixDto' is invalid!\n"+
"'ePrefixDto' is a 'nil' pointer.\n",
errPrefStr)
return isEmpty, err
}
lenEPrefCol := len(ePrefixDto.ePrefCol)
if lenEPrefCol == 0 {
ePrefixDto.ePrefCol = nil
isEmpty = true
return isEmpty, err
}
if lenEPrefCol == 1 {
ePrefixDto.ePrefCol[0].Empty()
ePrefixDto.ePrefCol = nil
isEmpty = true
return isEmpty, err
}
ePrefixDto.ePrefCol[lenEPrefCol-1].Empty()
lenEPrefCol--
tempCol := make([]ErrorPrefixInfo, lenEPrefCol)
copy(tempCol, ePrefixDto.ePrefCol[:lenEPrefCol])
ePrefixDto.ePrefCol = make([]ErrorPrefixInfo, lenEPrefCol)
copy(ePrefixDto.ePrefCol, tempCol)
ePrefixDto.ePrefCol[lenEPrefCol-1].SetIsLastIndex(true)
isEmpty = false
return isEmpty, err
}
// emptyEPrefCollection - Receives a pointer to an ErrPrefixDto
// object an proceeds to delete all of the existing error prefix
// and error context information. When completed, the ErrPrefixDto
// object's collection of ErrorPrefixInfo elements will be set to
// 'nil'.
//
func (ePrefDtoQuark *errPrefixDtoQuark) emptyErrPrefInfoCollection(
ePrefixDto *ErrPrefixDto,
errPrefStr string) error {
if ePrefDtoQuark.lock == nil {
ePrefDtoQuark.lock = new(sync.Mutex)
}
ePrefDtoQuark.lock.Lock()
defer ePrefDtoQuark.lock.Unlock()
errPrefStr = errPrefStr +
"\nerrPrefixDtoQuark.emptyErrPrefInfoCollection()"
if ePrefixDto == nil {
return fmt.Errorf("%v\n"+
"Error: Input parameter 'ePrefixDto' is invalid!\n"+
"'ePrefixDto' is a 'nil' pointer.\n",
errPrefStr)
}
lenEPrefCol := len(ePrefixDto.ePrefCol)
if lenEPrefCol == 0 {
return nil
}
for i := 0; i < lenEPrefCol; i++ {
ePrefixDto.ePrefCol[i].Empty()
}
ePrefixDto.ePrefCol = nil
return nil
}
// newZeroErrPrefixDto - Returns a new instance of ErrPrefixDto
// with all internal member variables set to their initial or zero
// values.
//
func (ePrefDtoQuark *errPrefixDtoQuark) newZeroErrPrefixDto() ErrPrefixDto {
if ePrefDtoQuark.lock == nil {
ePrefDtoQuark.lock = new(sync.Mutex)
}
ePrefDtoQuark.lock.Lock()
defer ePrefDtoQuark.lock.Unlock()
newErrPrefixDto := ErrPrefixDto{}
newErrPrefixDto.lock = new(sync.Mutex)
newErrPrefixDto.ePrefCol = nil
newErrPrefixDto.leadingTextStr = ""
newErrPrefixDto.trailingTextStr = ""
newErrPrefixDto.maxErrPrefixTextLineLength =
errPrefPreon{}.ptr().getDefaultErrPrefLineLength()
newErrPrefixDto.inputStrDelimiters.SetToDefault()
newErrPrefixDto.outputStrDelimiters.SetToDefault()
return newErrPrefixDto
}
// normalizeErrPrefixDto - Receives a pointer to an instance of
// ErrPrefixDto and proceeds to set any uninitialized member variables
// to their zero values.
//
func (ePrefDtoQuark *errPrefixDtoQuark) normalizeErrPrefixDto(
ePrefixDto *ErrPrefixDto) {
if ePrefDtoQuark.lock == nil {
ePrefDtoQuark.lock = new(sync.Mutex)
}
ePrefDtoQuark.lock.Lock()
defer ePrefDtoQuark.lock.Unlock()
if ePrefixDto == nil {
return
}
ePrefixDto.inputStrDelimiters.SetToDefaultIfEmpty()
ePrefixDto.outputStrDelimiters.SetToDefaultIfEmpty()
ePrefPreon := errPrefPreon{}
minimumTextLineLen := ePrefPreon.getMinErrPrefLineLength()
if ePrefixDto.maxErrPrefixTextLineLength < minimumTextLineLen {
ePrefixDto.maxErrPrefixTextLineLength =
ePrefPreon.getDefaultErrPrefLineLength()
}
return
}
// ptr - Returns a pointer to a new instance of errPrefixDtoQuark.
//
func (ePrefDtoQuark errPrefixDtoQuark) ptr() *errPrefixDtoQuark {
if ePrefDtoQuark.lock == nil {
ePrefDtoQuark.lock = new(sync.Mutex)
}
ePrefDtoQuark.lock.Lock()
defer ePrefDtoQuark.lock.Unlock()
return &errPrefixDtoQuark{
lock: new(sync.Mutex),
}
}
// testValidityOfErrorPrefixInfo - Performs a diagnostic review of
// the input parameter 'ePrefixDto', an instance of ErrPrefixDto.
// The purpose of this diagnostic review is to determine whether
// this ErrPrefixDto instance is valid in all respects.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// ePrefixDto *ErrPrefixDto
// - A pointer to an instance of ErrPrefixDto. This object
// will be evaluated to determine whether or not it is a
// valid instance.
//
//
// ePrefix 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 'ePrefix'.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// isValid bool
// - This returned boolean value will signal whether the input
// parameter, 'ePrefixDto', is valid, or not. If the
// 'errPrefixDto' object contains valid data, this method
// returns 'true'. If the data is invalid, this method will
// return 'false'.
//
// err error
// - If the input parameter object, 'errPrefixDto', contains
// invalid data, a detailed error message will be returned
// identifying the invalid data item.
//
// If the input parameter object, 'errPrefixDto', is valid,
// this error parameter will be set to 'nil'.
//
func (ePrefDtoQuark *errPrefixDtoQuark) testValidityOfErrPrefixDto(
ePrefixDto *ErrPrefixDto,
errPrefStr string) (
isValid bool,
err error) {
if ePrefDtoQuark.lock == nil {
ePrefDtoQuark.lock = new(sync.Mutex)
}
ePrefDtoQuark.lock.Lock()
defer ePrefDtoQuark.lock.Unlock()
errPrefStr = errPrefStr +
"\nerrPrefixDtoQuark.testValidityOfErrPrefixDto()"
isValid = false
if ePrefixDto == nil {
err = fmt.Errorf("%v\n"+
"Error: Input parameter 'ePrefixDto' is invalid!\n"+
"'ePrefixDto' is a 'nil' pointer.\n",
errPrefStr)
return isValid, err
}
// Minimum length is 10-characters
if ePrefixDto.maxErrPrefixTextLineLength < 10 {
err = fmt.Errorf("%v\n"+
"Error: Maximum Text Line Length is less than 10-Characters!\n"+
"Maximum Text Line Length='%v'\n",
errPrefStr,
ePrefixDto.maxErrPrefixTextLineLength)
return isValid, err
}
err = ePrefixDto.inputStrDelimiters.
IsValidInstanceError(errPrefStr + " inputStrDelimiters ")
if err != nil {
return isValid, err
}
err = ePrefixDto.outputStrDelimiters.
IsValidInstanceError(errPrefStr + " outputStrDelimiters ")
if err != nil {
return isValid, err
}
isValid = true
return isValid, err
}