Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntervalRestrictedMatrixJsonItem.cs @ 17530

Last change on this file since 17530 was 17519, checked in by dpiringe, 5 years ago

#3026:

  • added error output for failed runner initialization
  • reorganised some final view models
  • TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
  • code cleanup
  • refactored RegressionProblemDataConverter
  • added lots of comments
  • added new view for StringArrayJsonItem
  • added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
File size: 1.2 KB
RevLine 
[17473]1using System;
2using System.Collections.Generic;
3using Newtonsoft.Json.Linq;
4
5namespace HeuristicLab.JsonInterface {
6  public abstract class IntervalRestrictedMatrixJsonItem<T> : MatrixJsonItem<T>, IIntervalRestrictedJsonItem<T>
7    where T : IComparable {
8    public T Minimum { get; set; }
9    public T Maximum { get; set; }
[17481]10
11    protected override ValidationResult Validate() {
12      IList<string> errors = new List<string>();
13      bool success = true;
[17473]14      foreach (var x in Value) {
[17481]15        foreach (var y in x) {
16          if (Minimum.CompareTo(y) > 0 || Maximum.CompareTo(y) < 0) {
17            success = false;
18            errors.Add($"[{Path}]: Value {y} is not between {Minimum} and {Maximum}.");
19          }
[17473]20        }
21      }
[17481]22      return new ValidationResult(success, errors);
[17473]23    }
[17481]24
[17477]25    public override void SetJObject(JObject jObject) {
26      base.SetJObject(jObject);
27
28      var minProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)];
29      if (minProp != null) Minimum = minProp.ToObject<T>();
30
31
32      var maxProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)];
33      if (maxProp != null) Maximum = maxProp.ToObject<T>();
[17473]34    }
35  }
36}
Note: See TracBrowser for help on using the repository browser.