LCOV - code coverage report
Current view: top level - lib/_classes/structure - summary_app_data.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 7 19 36.8 %
Date: 2024-10-04 11:09:33 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2023 The terCAD team. All rights reserved.
       2             : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3             : 
       4             : import 'dart:collection';
       5             : import 'dart:math';
       6             : 
       7             : class SummaryAppData {
       8             :   final _scope = SplayTreeMap<double, String>();
       9             :   final _actual = SplayTreeMap<double, String>();
      10             :   final _hash = HashMap<String, double>();
      11             :   double total;
      12             : 
      13           3 :   SummaryAppData({
      14             :     this.total = 0,
      15             :     List<String> list = const [],
      16             :   }) {
      17           3 :     this.list = list;
      18             :   }
      19             : 
      20           6 :   SplayTreeMap<double, String> get origin => _scope;
      21             : 
      22          18 :   List<String> get list => _scope.values.toList().reversed.toList();
      23             : 
      24           6 :   List<String> get listActual => _actual.values.toList().reversed.toList();
      25             : 
      26           3 :   set list(List<String> list) {
      27           6 :     for (int i = 0; i < list.length; i++) {
      28           0 :       add(list[i], id: i + 1);
      29             :     }
      30             :   }
      31             : 
      32           0 :   add(String value, {DateTime? updatedAt, int? id}) {
      33           0 :     if (_hash.containsKey(value)) {
      34           0 :       _scope.remove(_hash[value]);
      35           0 :       _actual.remove(_hash[value]);
      36           0 :       _hash.remove(value);
      37             :     }
      38           0 :     final current = DateTime.now();
      39             :     updatedAt ??= current;
      40           0 :     double key = (id ?? updatedAt.millisecondsSinceEpoch).toDouble() + Random().nextDouble();
      41           0 :     _scope[key] = value;
      42           0 :     _hash[value] = key;
      43           0 :     if (key >= DateTime(current.year, current.month).millisecondsSinceEpoch) {
      44           0 :       _actual[key] = value;
      45             :     }
      46             :   }
      47             : }

Generated by: LCOV version 1.14