Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/StringColumn.cs @ 7968

Last change on this file since 7968 was 7267, checked in by gkronber, 13 years ago

#1734 updated copyright year in all files of the DataImporter branch

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Generic;
24using System.Collections;
25using System.Linq;
26using System.Text;
27using System.Xml;
28using System.Globalization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.DataImporter.Data.Model {
32  [StorableClass]
33  public class StringColumn : ColumnBase {
34    [Storable]
35    private List<string> values;
36
37    private StringColumn() :base(string.Empty) {
38      this.DataType = typeof(string);
39    }
40
41    public StringColumn(string columnName)
42      : base(columnName) {
43      this.DataType = typeof(string);
44      this.values = new List<string>();
45    }
46
47    public StringColumn(string columnName, int capacity)
48      : this(columnName) {
49      this.values.Capacity = capacity;
50    }
51
52    public override string ToString() {
53      return base.ToString() + " <String>";
54    }
55
56    protected override IList Values {
57      get { return this.values; }
58    }
59
60    public override void AddValue(IComparable value) {
61      this.values.Add(CheckInput(value));
62    }
63
64    public override void AddValueOrNull(IComparable value) {
65      if (value == null)
66        this.values.Add(null);
67      else
68        this.values.Add(CheckInput(value.ToString()));
69    }
70
71    public override void InsertValue(int position, IComparable value) {
72      this.values.Insert(position, CheckInput(value));
73    }
74
75    public override void ChangeValue(int position, IComparable value) {
76      this.values[position] = CheckInput(value);
77    }
78
79    public override void ChangeValueOrNull(int position, IComparable value) {
80      this.values[position] = CheckInput(value);
81    }
82
83    public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
84      this.values[position] = CheckInput(value);
85    }
86
87    public override ColumnBase CreateCopyOfColumnWithoutValues() {
88      return CreateCopyOfColumnWithoutValues(this.values.Capacity);
89    }
90    public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
91      return new StringColumn(this.Name, capacity);
92    }
93
94    private string CheckInput(IComparable value) {
95      if (value == null)
96        return null;
97      string tmp = value.ToString().Trim();
98      if (string.IsNullOrEmpty(tmp))
99        tmp = null;
100      return tmp;
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.