Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/10/20 17:17:37 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models
Files:
8 added
1 deleted
10 edited
2 moved

Legend:

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

    r17472 r17473  
    77
    88namespace HeuristicLab.JsonInterface {
    9   public class ArrayJsonItemBase<T> : JsonItem<T[], T>, IArrayJsonItem {
     9  public abstract class ArrayJsonItem<T> : ValueJsonItem<T[]>, IArrayJsonItem {
    1010    public virtual bool Resizable { get; set; }
    1111    public override void SetFromJObject(JObject jObject) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/BoolJsonItems.cs

    r17446 r17473  
    66
    77namespace HeuristicLab.JsonInterface {
    8   public class BoolJsonItem : JsonItem<bool> { }
     8  public class BoolJsonItem : ValueJsonItem<bool> {
     9    protected override bool Validate() => true;
     10  }
    911
    10   public class BoolArrayJsonItem : ArrayJsonItemBase<bool> { }
     12  public class BoolArrayJsonItem : ArrayJsonItem<bool> {
     13    protected override bool Validate() => true;
     14  }
    1115
    12   public class BoolMatrixJsonItem : MatrixJsonItemBase<bool> { }
     16  public class BoolMatrixJsonItem : MatrixJsonItem<bool> {
     17    protected override bool Validate() => true;
     18  }
    1319}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/DateTimeJsonItem.cs

    r17446 r17473  
    66
    77namespace HeuristicLab.JsonInterface {
    8   public class DateTimeJsonItem : JsonItem<DateTime> { }
     8  public class DateTimeJsonItem : IntervalRestrictedValueJsonItem<DateTime> {
     9    protected override bool Validate() => Minimum.CompareTo(Value) >= 0 && Maximum.CompareTo(Value) <= 0;
     10  }
    911}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/DoubleJsonItems.cs

    r17471 r17473  
    66
    77namespace HeuristicLab.JsonInterface {
    8   public class DoubleJsonItem : JsonItem<double> { }
    9   public class DoubleArrayJsonItem : ArrayJsonItemBase<double> { }
    10   public class DoubleRangeJsonItem : ArrayJsonItemBase<double> {
    11     public override bool Resizable { get => false; set { } }
    12   }
     8  public class DoubleJsonItem : IntervalRestrictedValueJsonItem<double> { }
     9  public class DoubleArrayJsonItem : IntervalRestrictedArrayJsonItem<double> { }
     10  public class DoubleRangeJsonItem : RangedJsonItem<double> { }
    1311
    14   public class DoubleMatrixJsonItem : MatrixJsonItemBase<double> {
     12  public class DoubleMatrixJsonItem : IntervalRestrictedMatrixJsonItem<double> {
     13    /*
    1514    protected override bool IsInRange() {
    1615      for (int c = 0; c < Value.Length; ++c) {
     
    2221      return true;
    2322    }
     23    */
    2424  }
    2525}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/IntJsonItems.cs

    r17471 r17473  
    66
    77namespace HeuristicLab.JsonInterface {
    8   public class IntJsonItem : JsonItem<int> {
    9     //public new IEnumerable<int> Range { get; }
     8  public class IntJsonItem : IntervalRestrictedValueJsonItem<int> { }
     9  public class IntArrayJsonItem : IntervalRestrictedArrayJsonItem<int> { }
     10  public class IntRangeJsonItem : RangedJsonItem<int> { }
     11  public class IntMatrixJsonItem : IntervalRestrictedMatrixJsonItem<int> {
    1012    /*
    11     public int MinValue { get; set; }
    12     public int MaxValue { get; set; }
    13     */
    14   }
    15   public class IntArrayJsonItem : ArrayJsonItemBase<int> { }
    16   public class IntRangeJsonItem : ArrayJsonItemBase<int> {
    17     public override bool Resizable { get => false; set { } }
    18   }
    19   public class IntMatrixJsonItem : MatrixJsonItemBase<int> {
    20 
    2113    protected override bool IsInRange() {
    2214      for (int c = 0; c < Value.Length; ++c) {
     
    2820      return true;
    2921    }
     22    */
    3023  }
    3124}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/JsonItem.cs

    r17471 r17473  
    1111  /// Main data class for json interface.
    1212  /// </summary>
    13   public class JsonItem : IJsonItem {
     13  public abstract class JsonItem : IJsonItem {
    1414
    1515    public class JsonItemValidator : IJsonItemValidator {
     
    2525      }
    2626
     27      // TODO: return ValidationResult ?
    2728      private bool ValidateHelper(JsonItem item, ref IList<IJsonItem> faultyItems) {
    2829        int hash = item.GetHashCode();
     
    3031          return r;
    3132
    32         bool res = true;
    33         if (item.Value != null && item.Range != null)
    34           res = item.IsInRange();
     33        bool res = item.Validate();
    3534        if (!res) faultyItems.Add(item);
    3635        Cache.Add(hash, res);
    37         if(item.Children != null)
     36        if(item.Children != null) {
    3837          foreach (var child in item.Children)
    39             res = res && ValidateHelper(child as JsonItem, ref faultyItems);
     38            if (!ValidateHelper(child as JsonItem, ref faultyItems))
     39              res = false && res;
     40        }
    4041        return res;
    4142      }
     
    6263    }
    6364
    64     public virtual object Value { get; set; }
     65    //public virtual object Value { get; set; }
    6566
    66     public virtual IEnumerable<object> Range { get; set; }
     67    //public virtual IEnumerable<object> Range { get; set; }
    6768   
    6869    // TODO jsonIgnore dataType?
     
    105106
    106107    public virtual void SetFromJObject(JObject jObject) {
    107       Value = jObject[nameof(IJsonItem.Value)]?.ToObject<object>();
    108       Range = jObject[nameof(IJsonItem.Range)]?.ToObject<object[]>();
     108      //Value = jObject[nameof(IJsonItem.Value)]?.ToObject<object>();
     109      //Range = jObject[nameof(IJsonItem.Range)]?.ToObject<object[]>();
    109110    }
    110111    #endregion
     
    114115     * TODO protected abstract bool Validate();
    115116     */
    116      
     117    protected abstract bool Validate();
     118    /*
    117119    protected virtual bool IsInRange() {
    118120      bool b1 = true, b2 = true;
     
    156158        (((T)max).CompareTo(value) == 1 || ((T)max).CompareTo(value) == 0);
    157159    }
     160    */
    158161    #endregion
    159162  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/LookupJsonItem.cs

    r17471 r17473  
    1414      ActualName = jObject[nameof(ILookupJsonItem.ActualName)]?.ToString();
    1515    }
     16
     17    protected override bool Validate() => true;
    1618  }
    1719}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/MatrixJsonItem.cs

    r17472 r17473  
    77
    88namespace HeuristicLab.JsonInterface {
    9   public class MatrixJsonItemBase<T> : JsonItem<T[][], T>, IMatrixJsonItem {
     9  public abstract class MatrixJsonItem<T> : ValueJsonItem<T[][]>, IMatrixJsonItem {
    1010    public virtual bool RowsResizable { get; set; }
    1111    public virtual bool ColumnsResizable { get; set; }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ResultJsonItem.cs

    r17471 r17473  
    77namespace HeuristicLab.JsonInterface {
    88  public class ResultJsonItem : JsonItem, IResultJsonItem {
    9 
     9    protected override bool Validate() => true;
    1010  }
    1111}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/StringJsonItem.cs

    r17451 r17473  
    66
    77namespace HeuristicLab.JsonInterface {
    8   public class StringJsonItem : JsonItem<string> { }
    9   public class StringArrayJsonItem : JsonItem<string[], string> { }
     8  public class StringJsonItem : ConcreteRestrictedValueJsonItem<string> { }
     9  public class StringArrayJsonItem : ConcreteRestrictedArrayJsonItem<string> { }
    1010}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/UnsupportedJsonItem.cs

    r17471 r17473  
    3434    }
    3535
    36     public override object Value {
    37       get => throw new NotSupportedException();
    38       set => throw new NotSupportedException();
    39     }
    40 
    41     public override IEnumerable<object> Range {
    42       get => throw new NotSupportedException();
    43       set => throw new NotSupportedException();
    44     }
     36    protected override bool Validate() => true;
    4537  }
    4638}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/ValueLookupJsonItem.cs

    r17471 r17473  
    1010    [JsonIgnore]
    1111    public IJsonItem JsonItemReference { get; set; }
     12
     13    protected override bool Validate() {
     14      if (JsonItemReference == null) return true;
     15      IList<IJsonItem> faultyItems = new List<IJsonItem>();
     16      return JsonItemReference.GetValidator().Validate(ref faultyItems);
     17    }
    1218  }
    1319}
Note: See TracChangeset for help on using the changeset viewer.