Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/06/19 14:39:00 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • extended the BaseConverter class to set the type of the extracted value and removed the assignment of type in all other converters
  • fixed a bug in ConfigurableConverter -> now it correctly iterates through all items from an IEnumerable and calls the extract callback
  • MultiCheckedOperatorConverter:
    • deleted unnecessary code line
    • now adds operators to parameters (instead of operator list, because the operator list will get removed in a future commit)
    • does not set the path of its added items anymore
  • ParameterBaseConverter removed unnecessary code lines
  • deleted ParameterBaseConverter
  • reimplemented StorableConverter to test it again (still not really useable, because it bloats the template massively)
  • fixed a pathing bug in ValueParameterConverter (extended ValueRangeConverter, ValueTypeArrayConverter, ValueTypeMatrixConverter, ValueTypeValueConverter to archive this)
  • JCGenerator now only writes a single array with parameters (only FreeParameters) and saves a .hl File to test a new type of implementation of the whole JsonInterface
  • fixed a bug in JsonItem -> now it replaces the name in path of the item (not the whole path as it was before)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs

    r17371 r17374  
    11using System;
     2using System.Collections;
    23using System.Collections.Generic;
    34using System.IO;
     
    2425      get => name;
    2526      set {
    26         name = value;
    27         Path = Name;
    28         UpdatePath();
     27        if(Name != value) {
     28          string oldName = Name;
     29          name = value;
     30          if (Path != null) {
     31            var parts = Path.Split('.');
     32            for (int i = 0; i < parts.Length; ++i)
     33              if (parts[i] == oldName)
     34                parts[i] = Name;
     35
     36            Path = string.Join(".", parts);
     37          } else
     38            Path = Name;
     39         
     40          UpdatePath();
     41        }
    2942      }
    3043    }
     
    7588
    7689    #region Public Methods
     90    public void AddParameter(JsonItem item) {
     91      if (Parameters == null)
     92        Parameters = new List<JsonItem>();
     93      Parameters.Add(item);
     94      item.Path = $"{Path}.{item.Name}";
     95      item.UpdatePath();
     96    }
     97
    7798    public void UpdatePath() {
    7899      if (Parameters != null)
     
    103124    }
    104125
    105     private bool IsInRange() => IsInRangeList() ||
    106       (Value.GetType().IsArray && ((object[])Value).All(x => IsInNumericRange(x))) ||
    107       (!Value.GetType().IsArray && IsInNumericRange(Value));
    108 
    109     private bool IsInRangeList() {
     126    private bool IsInRange() {
     127      bool b1 = true, b2 = true;
     128      if (Value is IEnumerable && !(Value is string)) {
     129        foreach (var x in (IEnumerable)Value) {
     130          b1 = b1 ? IsInRangeList(x) : b1;
     131          b2 = b2 ? IsInNumericRange(x) : b2;
     132        }
     133      }
     134      else {
     135        b1 = IsInRangeList(Value);
     136        b2 = IsInNumericRange(Value);
     137      }
     138
     139      return b1 || b2;
     140    }
     141
     142    private bool IsInRangeList(object value) {
    110143      foreach (var x in Range)
    111         if (x.Equals(Value)) return true;
     144        if (x.Equals(value)) return true;
    112145      return false;
    113146    }
    114147
    115148    private bool IsInNumericRange(object value) =>
    116       IsInNumericRange<long>(value)
     149      IsInNumericRange<ulong>(value)
     150      || IsInNumericRange<uint>(value)
     151      || IsInNumericRange<ushort>(value)
     152      || IsInNumericRange<long>(value)
    117153      || IsInNumericRange<int>(value)
    118154      || IsInNumericRange<short>(value)
    119155      || IsInNumericRange<byte>(value)
    120156      || IsInNumericRange<float>(value)
    121       || IsInNumericRange<double>(value);
     157      || IsInNumericRange<double>(value)
     158      || (value is float && float.IsNaN((float)value))
     159      || (value is double && double.IsNaN((double)value));
    122160
    123161    private bool IsInNumericRange<T>(object value) where T : IComparable {
    124162      object min = Range.First(), max = Range.Last();
    125       return value != null && min != null && max != null && value is T && min is T && max is T &&
    126             (((T)min).CompareTo(value) == -1 || ((T)min).CompareTo(value) == 0) &&
    127             (((T)max).CompareTo(value) == 1 || ((T)max).CompareTo(value) == 0);
     163      return
     164        value != null && min != null && max != null && value is T && min is T && max is T &&
     165        (((T)min).CompareTo(value) == -1 || ((T)min).CompareTo(value) == 0) &&
     166        (((T)max).CompareTo(value) == 1 || ((T)max).CompareTo(value) == 0);
    128167    }
    129168
Note: See TracChangeset for help on using the changeset viewer.