using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HeuristicLab.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace HeuristicLab.JsonInterface {
///
/// Main data class for json interface.
///
public class JsonItem {
public class JsonItemValidator {
private IDictionary Cache = new Dictionary();
private JsonItem Root { get; set; }
public JsonItemValidator(JsonItem root) {
Root = root;
}
public bool Validate(ref IList faultyItems) {
faultyItems = new List();
return ValidateHelper(Root, ref faultyItems);
}
private bool ValidateHelper(JsonItem item, ref IList faultyItems) {
int hash = item.GetHashCode();
if (Cache.TryGetValue(hash, out bool r))
return r;
bool res = true;
if (item.Value != null && item.Range != null)
res = item.IsInRange();
if (!res) faultyItems.Add(item);
Cache.Add(hash, res);
foreach (var child in item.Children)
res = res && ValidateHelper(child, ref faultyItems);
return res;
}
}
public virtual string Name { get; set; }
public virtual string Path {
get {
JsonItem tmp = Parent;
StringBuilder builder = new StringBuilder(this.Name);
while(tmp != null) {
builder.Insert(0, tmp.Name + ".");
tmp = tmp.Parent;
}
return builder.ToString();
}
}
[JsonIgnore]
public virtual IList Children { get; protected set; }
[JsonIgnore]
public virtual JsonItem Parent { get; set; }
public virtual object Value { get; set; }
public virtual IEnumerable