Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/NamedIntervals.cs @ 16588

Last change on this file since 16588 was 16588, checked in by chaider, 5 years ago

#2971 Changed variableIntervals from ObservableDictionary to Dictionary

File size: 2.2 KB
Line 
1using HeuristicLab.Collections;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
5using System;
6using System.Collections.Generic;
7using System.Drawing;
8using System.Linq;
9using System.Text;
10using System.Threading.Tasks;
11
12namespace HeuristicLab.Problems.DataAnalysis.Implementation {
13  [Item("NamedIntervals", "Represents variables with their interval ranges.")]
14  [StorableClass]
15  public class NamedIntervals : Item {   
16    Dictionary<string, Interval> variableIntervals = new Dictionary<string, Interval>();
17    public Dictionary<string, Interval> VariableIntervals => variableIntervals;
18
19    [Storable(Name = "StorableIntervalInformation")]
20    private IEnumerable<Tuple<string, double, double>> StorableIntervalInformation {
21      get {
22        foreach (var varInt in variableIntervals)
23          yield return Tuple.Create(varInt.Key, varInt.Value.LowerBound, varInt.Value.UpperBound);
24      }
25
26      set {
27        foreach (var varInt in value)
28          variableIntervals.Add(varInt.Item1,new Interval(varInt.Item2,varInt.Item3));
29      }
30    }
31
32    public NamedIntervals() : base(){}
33    protected NamedIntervals(bool deserializing) : base(deserializing) { }
34
35    protected NamedIntervals(NamedIntervals original, Cloner cloner) : base(original, cloner) {
36      foreach (var keyValuePair in original.VariableIntervals) {
37        variableIntervals.Add(keyValuePair.Key, keyValuePair.Value);
38      }
39    }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new NamedIntervals(this, cloner);
43    }
44
45    public bool ReadOnly { get; }
46
47    public bool InsertMany(IEnumerable<KeyValuePair<string, Interval>> entries) {
48      if (entries == null) throw new ArgumentNullException("The given dataset is null.");
49      if (entries.Count() != 0) {
50        foreach (var entry in entries) {
51          if (variableIntervals.ContainsKey(entry.Key))
52            variableIntervals[entry.Key] = entry.Value;
53          else
54            variableIntervals.Add(entry.Key, entry.Value);
55        }
56      }
57      return true;
58    }
59
60    public bool Add(string key, Interval value) {
61      variableIntervals[key] = value;
62      return true;
63    }
64   
65  }
66}
67
Note: See TracBrowser for help on using the repository browser.