Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2520_PersistenceReintegration/HeuristicLab.DataPreprocessing/3.4/Filter/ComparisonFilter.cs @ 16462

Last change on this file since 16462 was 16462, checked in by jkarder, 5 years ago

#2520: worked on reintegration of new persistence

  • added nuget references to HEAL.Fossil
  • added StorableType attributes to many classes
  • changed signature of StorableConstructors
  • removed some classes in old persistence
  • removed some unnecessary usings
File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 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.Drawing;
24using HEAL.Fossil;
25using HeuristicLab.Common;
26using HeuristicLab.Common.Resources;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29
30namespace HeuristicLab.DataPreprocessing.Filter {
31  [Item("ComparisonFilter", "A filter which compares the member of the preprocessing data with the constraint data.")]
32  public class ComparisonFilter : ComparisonConstraint, IFilter {
33    public override string ItemName {
34      get { return "ComparisonFilter"; }
35    }
36
37    public override Image ItemImage {
38      get { return VSImageLibrary.Filter; }
39    }
40
41    public new IPreprocessingData ConstrainedValue {
42      get { return (IPreprocessingData)base.ConstrainedValue; }
43      set { base.ConstrainedValue = value; }
44    }
45
46    public new IStringConvertibleValue ConstraintData {
47      get { return (IStringConvertibleValue)base.ConstraintData; }
48      set {
49        if (!(value is IComparable))
50          throw new ArgumentException("Only IComparables allowed for ConstraintData");
51        base.ConstraintData = value;
52      }
53    }
54
55    public ComparisonFilter() : base() { }
56    [StorableConstructor]
57    protected ComparisonFilter(StorableConstructorFlag _) : base(_) { }
58
59    public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData)
60      : base(constrainedValue, constraintOperation, constraintData) {
61    }
62
63    public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData, bool active)
64      : base(constrainedValue, constraintOperation, constraintData, active) {
65    }
66
67    protected ComparisonFilter(ComparisonFilter original, Cloner cloner)
68      : base(original, cloner) {
69      constraintColumn = original.constraintColumn;
70    }
71    public override IDeepCloneable Clone(Cloner cloner) {
72      return new ComparisonFilter(this, cloner);
73    }
74
75    private int constraintColumn;
76    public int ConstraintColumn {
77      get { return constraintColumn; }
78      set {
79        if (ConstrainedValue.Columns < value)
80          throw new ArgumentException("Could not set ConstraintData to not existing column index.");
81
82        if (constraintColumn != value) {
83          constraintColumn = value;
84          this.OnConstraintColumnChanged();
85          this.OnToStringChanged();
86        }
87      }
88    }
89
90    // return remaining rows
91    public new bool[] Check() {
92      bool[] result = new bool[ConstrainedValue.Rows];
93
94      if (!Active)
95        return result;
96
97      for (int row = 0; row < ConstrainedValue.Rows; ++row) {
98        object item = null;
99        if (ConstrainedValue.VariableHasType<double>(constraintColumn)) {
100          item = new HeuristicLab.Data.DoubleValue(ConstrainedValue.GetCell<double>(ConstraintColumn, row));
101        } else if (ConstrainedValue.VariableHasType<DateTime>(constraintColumn)) {
102          item = new HeuristicLab.Data.DateTimeValue(ConstrainedValue.GetCell<DateTime>(ConstraintColumn, row));
103        } else {
104          item = new StringValue(ConstrainedValue.GetCell<string>(ConstraintColumn, row));
105        }
106
107        result[row] = base.Check(item);
108      }
109
110      return result;
111    }
112
113    public new bool[] Check(out string errorMessage) {
114      errorMessage = string.Empty;
115      return this.Check();
116    }
117
118    public override string ToString() {
119      string s = string.Empty;
120      if (ConstrainedValue != null)
121        s += ConstrainedValue.GetVariableName(ConstraintColumn) + " ";
122
123      if (ConstraintOperation != null)
124        s += ConstraintOperation.ToString() + " ";
125
126      if (ConstraintData != null)
127        s += ConstraintData.ToString();
128      else
129        s += "null";
130
131      s += ".";
132      return s;
133    }
134
135    public event EventHandler ConstraintColumnChanged;
136    protected virtual void OnConstraintColumnChanged() {
137      EventHandler handler = ConstraintColumnChanged;
138      if (handler != null)
139        handler(this, EventArgs.Empty);
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.