source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/Filter/ComparisonFilter.cs @ 10785

Last change on this file since 10785 was 10785, checked in by psteiner, 8 years ago

filter or combination
filter control: checkedlistview

File size: 5.5 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.Drawing;
23using HeuristicLab.Common.Resources;
24using HeuristicLab.Core;
25using System;
26using System.Collections;
27using HeuristicLab.Common;
28using HeuristicLab.Data;
29using System.Collections.Generic;
30
31namespace HeuristicLab.DataPreprocessing.Filter
32{
33    [Item("ComparisonFilter", "A filter which compares the member of the preprocessing data with the constraint data.")]
34    public class ComparisonFilter : ComparisonConstraint, IFilter
35    {
36        protected ComparisonFilter(bool deserializing) : base(deserializing) { }
37
38        protected ComparisonFilter(ComparisonFilter original, Cloner cloner)
39            : base(original, cloner)
40        {
41            constraintColumn = original.constraintColumn;
42        }
43        public override IDeepCloneable Clone(Cloner cloner)
44        {
45            return new ComparisonFilter(this, cloner);
46        }
47
48        public ComparisonFilter() : base() { }
49        public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData)
50            : base(constrainedValue, constraintOperation, constraintData)
51        {
52        }
53
54        public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData, bool active)
55            : base(constrainedValue, constraintOperation, constraintData, active)
56        {
57        }
58
59
60        public override string ItemName
61        {
62            get { return "ComparisonFilter"; }
63        }
64
65        public override Image ItemImage
66        {
67            get { return VSImageLibrary.Filter; }
68        }
69
70        public new IPreprocessingData ConstrainedValue
71        {
72            get { return (IPreprocessingData)base.ConstrainedValue; }
73            set { base.ConstrainedValue = value; }
74        }
75
76        public new IStringConvertibleValue ConstraintData
77        {
78            get { return (IStringConvertibleValue)base.ConstraintData; }
79            set
80            {
81                if (!(value is IComparable))
82                    throw new ArgumentException("Only IComparables allowed for ConstraintData");
83                base.ConstraintData = value;
84            }
85        }
86
87
88        private int constraintColumn;
89        public int ConstraintColumn
90        {
91            get { return constraintColumn; }
92            set
93            {
94                if (ConstrainedValue.Columns < value)
95                    throw new ArgumentException("Could not set ConstraintData to not existing column index.");
96
97                if (constraintColumn != value)
98                {
99                    constraintColumn = value;
100                    this.OnConstraintColumnChanged();
101                    this.OnToStringChanged();
102                }
103            }
104        }
105
106
107        public new bool[] Check()
108        {
109            bool[] result = new bool[ConstrainedValue.Rows];
110
111            if (!Active)
112                return result;
113
114            for (int row = 0; row < ConstrainedValue.Rows; ++row)
115            {
116                object item = null;
117                if (ConstrainedValue.IsType<double>(constraintColumn))
118                {
119                  item = new StringValue(ConstrainedValue.GetCell<double>(ConstraintColumn, row).ToString());
120                }
121                else if (ConstrainedValue.IsType<DateTime>(constraintColumn))
122                {
123                  item = new StringValue(ConstrainedValue.GetCell<DateTime>(ConstraintColumn, row).ToString());
124                }
125                else
126                {
127                  item = new StringValue(ConstrainedValue.GetCell<string>(ConstraintColumn, row));
128                }
129
130                result[row] = !base.Check(item);
131            }
132
133            return result;
134        }
135
136        public new bool[] Check(out string errorMessage)
137        {
138            errorMessage = string.Empty;
139            return this.Check();
140        }
141
142        public event EventHandler ConstraintColumnChanged;
143        protected virtual void OnConstraintColumnChanged()
144        {
145            EventHandler handler = ConstraintColumnChanged;
146            if (handler != null)
147                handler(this, EventArgs.Empty);
148        }
149
150        public override string ToString()
151        {
152          string s = string.Empty;
153          if (ConstrainedValue != null)
154            s += ConstrainedValue.GetVariableName(ConstraintColumn) + " ";
155
156          if (ConstraintOperation != null)
157            s += ConstraintOperation.ToString() + " ";
158
159          if (ConstraintData != null)
160            s += ConstraintData.ToString();
161          else
162            s += "null";
163
164          s += ".";
165          return s;
166        }
167    }
168}
Note: See TracBrowser for help on using the repository browser.