Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/14 16:01:49 (10 years ago)
Author:
mleitner
Message:

Setup ComparisionFilter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/Filter/ComparisonFilter.cs

    r10558 r10582  
    2323using HeuristicLab.Common.Resources;
    2424using HeuristicLab.Core;
     25using System;
     26using System.Collections;
     27using HeuristicLab.Common;
     28using HeuristicLab.Data;
    2529
    26 namespace HeuristicLab.DataPreprocessing.Filter {
    27   [Item("ComparisonFilter", "Represents the comparison Filter.")]
    28   public class ComparisonFilter : ComparisonConstraint, IFilter {
    29     public override string ItemName {
    30       get { return "ComparisonFilter"; }
     30namespace HeuristicLab.DataPreprocessing.Filter
     31{
     32    [Item("ComparisonFilter", "Represents the comparison Filter.")]
     33    public class ComparisonFilter : ComparisonConstraint, IFilter
     34    {
     35
     36
     37        protected ComparisonFilter(bool deserializing) : base(deserializing) { }
     38
     39        protected ComparisonFilter(ComparisonFilter original, Cloner cloner)
     40            : base(original, cloner)
     41        {
     42            constraintColumn = original.constraintColumn;
     43        }
     44        public override IDeepCloneable Clone(Cloner cloner)
     45        {
     46            return new ComparisonFilter(this, cloner);
     47        }
     48
     49        public ComparisonFilter() : base() { }
     50        public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData)
     51            : base(constrainedValue, constraintOperation, constraintData)
     52        {
     53        }
     54
     55        public ComparisonFilter(IPreprocessingData constrainedValue, ConstraintOperation constraintOperation, object constraintData, bool active)
     56            : base(constrainedValue, constraintOperation, constraintData, active)
     57        {
     58        }
     59
     60
     61        public override string ItemName
     62        {
     63            get { return "ComparisonFilter"; }
     64        }
     65
     66        public override Image ItemImage
     67        {
     68            get { return VSImageLibrary.Filter; }
     69        }
     70
     71        public new IPreprocessingData ConstrainedValue
     72        {
     73            get { return (IPreprocessingData)base.ConstrainedValue; }
     74            set { base.ConstrainedValue = value; }
     75        }
     76
     77        public new IStringConvertibleValue ConstraintData
     78        {
     79            get { return (IStringConvertibleValue)base.ConstraintData; }
     80            set
     81            {
     82                if (!(value is IComparable))
     83                    throw new ArgumentException("Only IComparables allowed for ConstraintData");
     84                base.ConstraintData = value;
     85            }
     86        }
     87
     88
     89        private int constraintColumn;
     90        public int ConstraintColumn
     91        {
     92            get { return constraintColumn; }
     93            set
     94            {
     95                if (ConstrainedValue.Columns < value)
     96                    throw new ArgumentException("Could not set ConstraintData to not existing column index.");
     97
     98                if (constraintColumn != value)
     99                {
     100                    constraintColumn = value;
     101                    this.OnConstraintColumnChanged();
     102                    this.OnToStringChanged();
     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        }
    31150    }
    32 
    33     public override Image ItemImage {
    34       get { return VSImageLibrary.Filter; }
    35     }
    36   }
    37151}
Note: See TracChangeset for help on using the changeset viewer.