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.Generic;
|
---|
24 | using System.Globalization;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 | using HEAL.Attic;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.DataImporter.Data.Model {
|
---|
29 | [StorableType("7C0A4BD8-45A1-4710-AC42-1BCBB4DF03D5")]
|
---|
30 | public class DateTimeColumn : ColumnBase {
|
---|
31 | [Storable]
|
---|
32 | private List<DateTime?> values;
|
---|
33 |
|
---|
34 | [StorableConstructor]
|
---|
35 | protected DateTimeColumn(StorableConstructorFlag _) : base(_) { }
|
---|
36 |
|
---|
37 | public DateTimeColumn(string columnName)
|
---|
38 | : base(columnName) {
|
---|
39 | this.values = new List<DateTime?>();
|
---|
40 | }
|
---|
41 |
|
---|
42 | public DateTimeColumn(string columnName, int capacity)
|
---|
43 | : this(columnName) {
|
---|
44 | this.values.Capacity = capacity;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public override Type DataType {
|
---|
48 | get { return typeof(DateTime?); }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override string ToString() {
|
---|
52 | return base.ToString() + " <Date>";
|
---|
53 | }
|
---|
54 |
|
---|
55 | protected override System.Collections.IList Values {
|
---|
56 | get { return this.values; }
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override void AddValue(IComparable value) {
|
---|
60 | this.values.Add((DateTime?)value);
|
---|
61 | }
|
---|
62 |
|
---|
63 | public override void AddValueOrNull(IComparable value) {
|
---|
64 | this.values.Add(ConvertToDateTime(value));
|
---|
65 | }
|
---|
66 |
|
---|
67 | public override void ChangeValue(int position, IComparable value) {
|
---|
68 | this.values[position] = (DateTime?)value;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public override void ChangeValueOrNull(int position, IComparable value) {
|
---|
72 | this.values[position] = ConvertToDateTime(value);
|
---|
73 | }
|
---|
74 |
|
---|
75 | public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
|
---|
76 | if (value == null)
|
---|
77 | this.values[position] = null;
|
---|
78 | else {
|
---|
79 | DateTime? val = ConvertToDateTime(value);
|
---|
80 | if (val != null)
|
---|
81 | this.values[position] = val;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override void InsertValue(int position, IComparable value) {
|
---|
86 | this.values.Insert(position, (DateTime?)value);
|
---|
87 | }
|
---|
88 |
|
---|
89 | private DateTime? ConvertToDateTime(IComparable value) {
|
---|
90 | DateTime val;
|
---|
91 |
|
---|
92 | if (value == null)
|
---|
93 | return null;
|
---|
94 |
|
---|
95 | if (DateTime.TryParse(value.ToString(), out val))
|
---|
96 | return val;
|
---|
97 |
|
---|
98 | if (DateTime.TryParseExact(value.ToString(), "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out val))
|
---|
99 | return val;
|
---|
100 |
|
---|
101 | return null;
|
---|
102 | }
|
---|
103 |
|
---|
104 | public override ColumnBase CreateCopyOfColumnWithoutValues() {
|
---|
105 | return CreateCopyOfColumnWithoutValues(this.values.Capacity);
|
---|
106 | }
|
---|
107 |
|
---|
108 | public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
|
---|
109 | return new DateTimeColumn(this.Name, capacity);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|