Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10587 was 10587, checked in by mleitner, 10 years ago

Fix Comparision Filter

File size: 4.9 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;
28
29namespace HeuristicLab.DataPreprocessing.Filter
30{
31    [Item("ComparisonFilter", "Represents the comparison Filter.")]
32    public class ComparisonFilter : ComparisonConstraint, IFilter
33    {
34
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        protected override bool Check(object constrainedMember)
108        {
109            if (!Active)
110                return false;
111
112            for (int row = 0; row < ConstrainedValue.Rows; ++row)
113            {
114
115                object item = null;
116                if (ConstrainedValue.IsType<double>(constraintColumn))
117                {
118                    item = ConstrainedValue.GetCell<double>(ConstraintColumn, row);
119                }
120                else if (ConstrainedValue.IsType<DateTime>(constraintColumn))
121                {
122                    item = ConstrainedValue.GetCell<DateTime>(ConstraintColumn, row);
123                }
124                else
125                {
126                    item = ConstrainedValue.GetCell<string>(ConstraintColumn, row);
127                }
128
129                if (base.Check(item))
130                    return true;
131
132            }
133
134            return false;
135        }
136
137        protected override bool Check(object constrainedMember, out string errorMessage)
138        {
139            errorMessage = string.Empty;
140            return this.Check(constrainedMember);
141        }
142
143        public event EventHandler ConstraintColumnChanged;
144        protected virtual void OnConstraintColumnChanged()
145        {
146            EventHandler handler = ConstraintColumnChanged;
147            if (handler != null)
148                handler(this, EventArgs.Empty);
149        }
150    }
151}
Note: See TracBrowser for help on using the repository browser.