Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/StringColumn.cs @ 16567

Last change on this file since 16567 was 16567, checked in by gkronber, 5 years ago

#2520: changed StorableConstructors and added StorableType attributes in HeuristicLab.DataImporter addon

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections;
24using System.Collections.Generic;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HEAL.Attic;
27
28namespace HeuristicLab.DataImporter.Data.Model {
29  [StorableType("D07567B3-743A-4104-A443-BE048B37BBEB")]
30  public class StringColumn : ColumnBase {
31    [Storable]
32    private List<string> values;
33
34    [StorableConstructor]
35    protected StringColumn(StorableConstructorFlag _) : base(_) { }
36
37    public StringColumn(string columnName)
38      : base(columnName) {
39      this.values = new List<string>();
40    }
41
42    public StringColumn(string columnName, int capacity)
43      : this(columnName) {
44      this.values.Capacity = capacity;
45    }
46
47    public override Type DataType {
48      get { return typeof(string); }
49    }
50
51    public override string ToString() {
52      return base.ToString() + " <String>";
53    }
54
55    protected override IList Values {
56      get { return this.values; }
57    }
58
59    public override void AddValue(IComparable value) {
60      this.values.Add(CheckInput(value));
61    }
62
63    public override void AddValueOrNull(IComparable value) {
64      if (value == null)
65        this.values.Add(null);
66      else
67        this.values.Add(CheckInput(value.ToString()));
68    }
69
70    public override void InsertValue(int position, IComparable value) {
71      this.values.Insert(position, CheckInput(value));
72    }
73
74    public override void ChangeValue(int position, IComparable value) {
75      this.values[position] = CheckInput(value);
76    }
77
78    public override void ChangeValueOrNull(int position, IComparable value) {
79      this.values[position] = CheckInput(value);
80    }
81
82    public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
83      this.values[position] = CheckInput(value);
84    }
85
86    public override ColumnBase CreateCopyOfColumnWithoutValues() {
87      return CreateCopyOfColumnWithoutValues(this.values.Capacity);
88    }
89    public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
90      return new StringColumn(this.Name, capacity);
91    }
92
93    private string CheckInput(IComparable value) {
94      if (value == null)
95        return null;
96      string tmp = value.ToString().Trim();
97      if (string.IsNullOrEmpty(tmp))
98        tmp = null;
99      return tmp;
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.