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