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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using HEAL.Attic;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.DataImporter.Data.Model {
|
---|
28 | [StorableType("D07567B3-743A-4104-A443-BE048B37BBEB")]
|
---|
29 | public class StringColumn : ColumnBase {
|
---|
30 | [Storable]
|
---|
31 | private List<string> values;
|
---|
32 |
|
---|
33 | [StorableConstructor]
|
---|
34 | protected StringColumn(StorableConstructorFlag _) : base(_) { }
|
---|
35 |
|
---|
36 | public StringColumn(string columnName)
|
---|
37 | : base(columnName) {
|
---|
38 | this.values = new List<string>();
|
---|
39 | }
|
---|
40 |
|
---|
41 | public StringColumn(string columnName, int capacity)
|
---|
42 | : this(columnName) {
|
---|
43 | this.values.Capacity = capacity;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public override Type DataType {
|
---|
47 | get { return typeof(string); }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public override string ToString() {
|
---|
51 | return base.ToString() + " <String>";
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected override IList Values {
|
---|
55 | get { return this.values; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override void AddValue(IComparable value) {
|
---|
59 | this.values.Add(CheckInput(value));
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override void AddValueOrNull(IComparable value) {
|
---|
63 | if (value == null)
|
---|
64 | this.values.Add(null);
|
---|
65 | else
|
---|
66 | this.values.Add(CheckInput(value.ToString()));
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override void InsertValue(int position, IComparable value) {
|
---|
70 | this.values.Insert(position, CheckInput(value));
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override void ChangeValue(int position, IComparable value) {
|
---|
74 | this.values[position] = CheckInput(value);
|
---|
75 | }
|
---|
76 |
|
---|
77 | public override void ChangeValueOrNull(int position, IComparable value) {
|
---|
78 | this.values[position] = CheckInput(value);
|
---|
79 | }
|
---|
80 |
|
---|
81 | public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
|
---|
82 | this.values[position] = CheckInput(value);
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override ColumnBase CreateCopyOfColumnWithoutValues() {
|
---|
86 | return CreateCopyOfColumnWithoutValues(this.values.Capacity);
|
---|
87 | }
|
---|
88 | public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
|
---|
89 | return new StringColumn(this.Name, capacity);
|
---|
90 | }
|
---|
91 |
|
---|
92 | private string CheckInput(IComparable value) {
|
---|
93 | if (value == null)
|
---|
94 | return null;
|
---|
95 | string tmp = value.ToString().Trim();
|
---|
96 | if (string.IsNullOrEmpty(tmp))
|
---|
97 | tmp = null;
|
---|
98 | return tmp;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|