amfnengine 0.3.5

Amortization Functions (AmFn) Engine
Documentation
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
//! List of columns element.
// Copyright (c) 2021 ShiftLeft Software
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::cell::Cell;

use super::ElemColumn;
use crate::ListTrait;

pub struct ListColumn {
    /// The list of column elements.
    list_column: Vec<ElemColumn>,

    /// The index of the currently selected column element.
    list_index: Cell<usize>,
}

/// List of columns list implementation.

impl ListTrait for ListColumn {
    /// Clear all columns from the column list.

    fn clear(&mut self) {
        self.list_column.clear();
        self.list_index = Cell::new(usize::MAX);
    }

    /// Get the count of the columns.
    ///
    /// # Return
    ///
    /// * See description.

    fn count(&self) -> usize {
        self.list_column.len()
    }

    /// Get the index of the selected column (starting from 0).
    ///
    /// # Return
    ///
    /// * See description.

    fn index(&self) -> usize {
        self.list_index.get()
    }

    /// Select a column based upon an index value.
    ///
    /// # Arguments
    ///
    /// * `index_param` - The index value of the column to select (starting from 0).
    ///
    /// # Return
    ///
    /// * True if successful, otherwise false.

    fn get_element(&self, index_param: usize) -> bool {
        if index_param >= self.list_column.len() {
            return false;
        }

        self.set_index(index_param);

        true
    }

    /// Set the list index.
    ///
    /// # Arguments
    ///
    /// * `index_param` - See description.
    ///
    /// # Return
    ///
    /// * True if successful, otherwise false.

    fn set_index(&self, index_param: usize) -> bool {
        if index_param >= self.list_column.len() {
            return false;
        }

        self.list_index.set(index_param);

        true
    }
}

/// List of columns default implementation.

impl Default for ListColumn {
    /// Create and return a new list column element.
    ///
    /// # Return
    ///
    /// * See description.

    fn default() -> Self {
        ListColumn::new()
    }
}

/// List of columns implementation.

impl ListColumn {
    /// Create and return a new list column element.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn new() -> ListColumn {
        ListColumn {
            list_column: Vec::new(),
            list_index: Cell::new(usize::MAX),
        }
    }

    /// Add a new column into the column list.
    ///
    /// # Arguments
    ///
    /// * `col_name_param` - Column name.
    /// * `col_name_index_param` - Column index.
    /// * `col_header_param` - Column header.
    /// * `col_description_param` - Column description.
    /// * `group_param` - Group parameter.
    /// * `name_param` - Name parameter.
    /// * `col_type_param` - Column type.
    /// * `code_param` - Code parameter.
    /// * `column_empty_value_param` - Column empty value.
    /// * `format_param` - Column format.
    /// * `decimal_digits_param` - Decimal digits.
    /// * `column_width_param` - Column width.
    /// * `column_exclude_param` - Column exclude.
    ///
    /// # Return
    ///
    /// * True if successful, otherwise false.
    #[allow(clippy::too_many_arguments)]

    pub fn add_column(
        &mut self,
        col_name_param: &str,
        col_name_index_param: usize,
        col_header_param: &str,
        col_description_param: &str,
        group_param: &str,
        name_param: &str,
        col_type_param: &str,
        code_param: &str,
        format_param: crate::FormatType,
        decimal_digits_param: usize,
        column_width_param: usize,
        column_editable_param: bool,
    ) -> bool {
        let new_elem_column: ElemColumn = ElemColumn::new(
            col_name_param,
            col_name_index_param,
            col_header_param,
            col_description_param,
            group_param,
            name_param,
            col_type_param,
            code_param,
            format_param,
            decimal_digits_param,
            column_width_param,
            column_editable_param,
        );

        let new_index: usize = self.list_column.len();
        self.list_column.push(new_elem_column);
        self.list_index.set(new_index);
        true
    }

    /// Get the selected column.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn column(&self) -> &ElemColumn {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o,
        }
    }

    /// Get the name of the column.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn col_name(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.col_name(),
        }
    }

    /// Index of the column name.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn col_name_index(&self) -> usize {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.col_name_index(),
        }
    }

    /// Get the header text of the column.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn col_header(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.col_header(),
        }
    }

    /// Get the description of the column.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn col_description(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.col_description(),
        }
    }

    /// Get the group of the descriptor.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn group(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.group(),
        }
    }

    /// Get the name of the descriptor.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn name(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.name(),
        }
    }

    /// Get the type of the descriptor.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn col_type(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.col_type(),
        }
    }

    /// Get the code of the descriptor.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn code(&self) -> &str {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.code(),
        }
    }

    /// Get the format of the column.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn format(&self) -> crate::FormatType {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.format(),
        }
    }

    /// Get the number of significant decimal digits.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn decimal_digits(&self) -> usize {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.decimal_digits(),
        }
    }

    /// Get the width of the column.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn column_width(&self) -> usize {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.column_width(),
        }
    }

    /// Get the column editable.
    ///
    /// # Return
    ///
    /// * See description.

    pub fn column_editable(&self) -> bool {
        match self.list_column.get(self.list_index.get()) {
            None => {
                panic!("Column list index not set");
            }
            Some(o) => o.column_editable(),
        }
    }

    /// Select the column that matches a column name index.
    ///
    /// # Arguments
    ///
    /// * `col_name_index` - The column name index to select.
    ///
    /// # Return
    ///
    /// * True if successful, otherwise false.

    pub fn get_element_by_col_name_index(&self, col_name_index: usize) -> bool {
        for (index, elem_key) in self.list_column.iter().enumerate() {
            if elem_key.col_name_index() == col_name_index {
                self.set_index(index);
                return true;
            }
        }

        false
    }

    /// Remove the selected column from the column list.
    ///
    /// # Return
    ///
    /// * True if successful, otherwise false.

    pub fn remove(&mut self) -> bool {
        if self.list_index.get() >= self.list_column.len() {
            return false;
        }

        self.list_column.remove(self.list_index.get());
        if self.list_index.get() > 0 {
            self.list_index.set(self.list_index.get() - 1);
        }
        true
    }
}