Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/DoubleJsonItems.cs @ 17477

Last change on this file since 17477 was 17477, checked in by dpiringe, 4 years ago

#3026:

  • refactored JsonTemplateInstantiator -> now returns a InstantiatorResult which contains the optimizer and an IEnumerable of IResultJsonItem
  • code cleanup in JCGenerator
  • relocated the serialization of json items into IJsonItem with method GenerateJObject (virtual base implementation in JsonItem)
    • this allows custom serialization for json items (example: ValueLookupJsonItem)
    • items of interface IIntervalRestrictedJsonItem have a custom implementation of GenerateJObject -> hides Minimum and Maximum if the values are the physically min/max of their type
  • code cleanup in BaseConverter
File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using Newtonsoft.Json.Linq;
7
8namespace HeuristicLab.JsonInterface {
9  public class DoubleJsonItem : IntervalRestrictedValueJsonItem<double> {
10    public override JObject GenerateJObject() {
11      var obj = base.GenerateJObject();
12
13      if (Minimum.CompareTo(double.MinValue) == 0)
14        obj.Property("Minimum").Remove();
15
16      if (Maximum.CompareTo(double.MaxValue) == 0)
17        obj.Property("Maximum").Remove();
18
19      return obj;
20    }
21
22    public override void SetJObject(JObject jObject) {
23      Minimum = double.MinValue;
24      Maximum = double.MaxValue;
25      base.SetJObject(jObject);
26    }
27  }
28  public class DoubleArrayJsonItem : IntervalRestrictedArrayJsonItem<double> {
29    public override JObject GenerateJObject() {
30      var obj = base.GenerateJObject();
31
32      if (Minimum.CompareTo(double.MinValue) == 0)
33        obj.Property("Minimum").Remove();
34
35      if (Maximum.CompareTo(double.MaxValue) == 0)
36        obj.Property("Maximum").Remove();
37
38      return obj;
39    }
40
41    public override void SetJObject(JObject jObject) {
42      Minimum = double.MinValue;
43      Maximum = double.MaxValue;
44      base.SetJObject(jObject);
45    }
46  }
47  public class DoubleRangeJsonItem : RangedJsonItem<double> {
48    public override JObject GenerateJObject() {
49      var obj = base.GenerateJObject();
50
51      if (Minimum.CompareTo(double.MinValue) == 0)
52        obj.Property("Minimum").Remove();
53
54      if (Maximum.CompareTo(double.MaxValue) == 0)
55        obj.Property("Maximum").Remove();
56
57      return obj;
58    }
59
60    public override void SetJObject(JObject jObject) {
61      Minimum = double.MinValue;
62      Maximum = double.MaxValue;
63      base.SetJObject(jObject);
64    }
65  }
66  public class DoubleMatrixJsonItem : IntervalRestrictedMatrixJsonItem<double> {
67    public override JObject GenerateJObject() {
68      var obj = base.GenerateJObject();
69
70      if (Minimum.CompareTo(double.MinValue) == 0)
71        obj.Property("Minimum").Remove();
72
73      if (Maximum.CompareTo(double.MaxValue) == 0)
74        obj.Property("Maximum").Remove();
75
76      return obj;
77    }
78
79    public override void SetJObject(JObject jObject) {
80      Minimum = double.MinValue;
81      Maximum = double.MaxValue;
82      base.SetJObject(jObject);
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.