Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItems/IntervalRestrictedValueJsonItem.cs @ 18055

Last change on this file since 18055 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.2 KB
Line 
1using System;
2using Newtonsoft.Json.Linq;
3using HEAL.Attic;
4
5namespace HeuristicLab.JsonInterface {
6  [StorableType("5BD32AD9-7CA2-4837-B1C3-D47D0CD83035")]
7  public abstract class IntervalRestrictedValueJsonItem<T> : ValueJsonItem<T>, IIntervalRestrictedJsonItem<T>
8      where T : IComparable {
9    public T Minimum { get; set; }
10    public T Maximum { get; set; }
11
12    protected override ValidationResult Validate() {
13      bool res = Minimum.CompareTo(Value) <= 0 && Maximum.CompareTo(Value) >= 0;
14      if (res) return ValidationResult.Successful();
15      else return ValidationResult.Faulty($"[{Path}]: Value {Value} is not between {Minimum} and {Maximum}.");
16    }
17
18    public override void SetJObject(JObject jObject) {
19      base.SetJObject(jObject);
20
21      var minProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Minimum)];
22      if (minProp != null) Minimum = minProp.ToObject<T>();
23
24      var maxProp = jObject[nameof(IIntervalRestrictedJsonItem<T>.Maximum)];
25      if (maxProp != null) Maximum = maxProp.ToObject<T>();
26    }
27
28    public IntervalRestrictedValueJsonItem() { }
29
30    [StorableConstructor]
31    protected IntervalRestrictedValueJsonItem(StorableConstructorFlag _) : base(_) { }
32  }
33}
Note: See TracBrowser for help on using the repository browser.