Last change
on this file since 18031 was
18031,
checked in by dpiringe, 3 years ago
|
#3026
- fixed wrong inheritance for RangedJsonItem
- added VariableRanges automatic injection for RegressionProblemDataConverter
|
File size:
1.3 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using Newtonsoft.Json.Linq;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.JsonInterface {
|
---|
6 | public abstract class RangedJsonItem<T> : IntervalRestrictedValueJsonItem<T>, IRangedJsonItem<T>
|
---|
7 | where T : IComparable {
|
---|
8 | public T MinValue { get; set; }
|
---|
9 | public T MaxValue { get; set; }
|
---|
10 |
|
---|
11 | protected override ValidationResult Validate() {
|
---|
12 | IList<string> errors = new List<string>();
|
---|
13 | bool successMin = (Minimum.CompareTo(MinValue) <= 0 && Maximum.CompareTo(MinValue) >= 0);
|
---|
14 | bool successMax = (Minimum.CompareTo(MaxValue) <= 0 && Maximum.CompareTo(MaxValue) >= 0);
|
---|
15 | if (!successMin) errors.Add($"[{Path}]: Value {MinValue} is not between {Minimum} and {Maximum}.");
|
---|
16 | if (!successMax) errors.Add($"[{Path}]: Value {MaxValue} is not between {Minimum} and {Maximum}.");
|
---|
17 | return new ValidationResult((successMin && successMax), errors);
|
---|
18 |
|
---|
19 | }
|
---|
20 |
|
---|
21 | public override void SetJObject(JObject jObject) {
|
---|
22 | var minValueProp = jObject[nameof(IRangedJsonItem<T>.MinValue)];
|
---|
23 | if (minValueProp != null) MinValue = minValueProp.ToObject<T>();
|
---|
24 |
|
---|
25 | var maxValueProp = jObject[nameof(IRangedJsonItem<T>.MaxValue)];
|
---|
26 | if (maxValueProp != null) MaxValue = maxValueProp.ToObject<T>();
|
---|
27 |
|
---|
28 | base.SetJObject(jObject);
|
---|
29 | }
|
---|
30 |
|
---|
31 | }
|
---|
32 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.