Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItems/IntervalRestrictedMatrixJsonItem.cs

Last change on this file was 18055, checked in by dpiringe, 3 years ago

#3026

  • added StorableTypeAttribute and StorableConstructorAttribute to all JsonItems
  • added a new JsonItem ListJsonItem + Interfaces IListJsonItem
  • renamed SymRegPythonProcessor to RunCollectionSRSolutionPythonFormatter
  • removed Interface IResultCollectionProcessor -> using the interface IRunCollectionModifier now (has aleady implementations)
  • renamed all related variables/fields/properties with a connection to ResultCollectionProcessor
  • added new implementations for IRunCollectionModifier
File size: 1.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using Newtonsoft.Json.Linq;
4using HEAL.Attic;
5
6namespace HeuristicLab.JsonInterface {
7  [StorableType("4FEDB1E0-B4B7-4EAD-8D5E-B2AA13C37F40")]
8  public abstract class IntervalRestrictedMatrixJsonItem<T> : MatrixJsonItem<T>, IIntervalRestrictedJsonItem<T>
9      where T : IComparable {
10    public T Minimum { get; set; }
11    public T Maximum { get; set; }
12
13    protected override ValidationResult Validate() {
14      IList<string> errors = new List<string>();
15      bool success = true;
16      foreach (var x in Value) {
17        foreach (var y in x) {
18          if (Minimum.CompareTo(y) > 0 || Maximum.CompareTo(y) < 0) {
19            success = false;
20            errors.Add($"[{Path}]: Value {y} is not between {Minimum} and {Maximum}.");
21          }
22        }
23      }
24      return new ValidationResult(success, errors);
25    }
26
27    public override void SetJObject(JObject jObject) {
28      base.SetJObject(jObject);
29
30      var minProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)];
31      if (minProp != null) Minimum = minProp.ToObject<T>();
32
33
34      var maxProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)];
35      if (maxProp != null) Maximum = maxProp.ToObject<T>();
36    }
37
38    public IntervalRestrictedMatrixJsonItem() { }
39
40    [StorableConstructor]
41    protected IntervalRestrictedMatrixJsonItem(StorableConstructorFlag _) : base(_) { }
42  }
43}
Note: See TracBrowser for help on using the repository browser.