Last change
on this file since 18077 was
18077,
checked in by dpiringe, 2 years ago
|
#3026
- added the dockerhub readme file
- fixed a bug which caused changed values (changed by events) to be overwritten with wrong values
|
File size:
1.6 KB
|
Rev | Line | |
---|
[17519] | 1 | using System.Collections.Generic;
|
---|
[17473] | 2 | using System.Linq;
|
---|
[18055] | 3 | using HEAL.Attic;
|
---|
[18077] | 4 | using Newtonsoft.Json.Linq;
|
---|
[18055] | 5 |
|
---|
[17473] | 6 | namespace HeuristicLab.JsonInterface {
|
---|
[18055] | 7 | [StorableType("4333B6C0-26F7-41BA-A297-071AB50307F9")]
|
---|
[17473] | 8 | public abstract class ConcreteRestrictedArrayJsonItem<T> : ArrayJsonItem<T>, IConcreteRestrictedJsonItem<T> {
|
---|
| 9 | public IEnumerable<T> ConcreteRestrictedItems { get; set; }
|
---|
| 10 |
|
---|
[17481] | 11 | protected override ValidationResult Validate() {
|
---|
[17473] | 12 | bool res = true;
|
---|
[17481] | 13 | IList<string> errors = new List<string>();
|
---|
[17519] | 14 | if (ConcreteRestrictedItems == null) return ValidationResult.Successful();
|
---|
[18055] | 15 | foreach (var x in Value) {
|
---|
[17473] | 16 | bool tmp = false;
|
---|
[18055] | 17 | foreach (var restrictedItem in ConcreteRestrictedItems) {
|
---|
[17473] | 18 | tmp = tmp || x.Equals(restrictedItem); //if one tmp is true, it stays true (match found)
|
---|
| 19 | }
|
---|
[17481] | 20 | if (!tmp)
|
---|
| 21 | errors.Add($"[{Path}]: Value '{x}' is not one of the allowed values: " +
|
---|
| 22 | $"'{ string.Join(",", ConcreteRestrictedItems.Select(s => s.ToString()).ToArray()) }'.");
|
---|
[17473] | 23 | res = res && tmp; //if one tmp is false, res will set false
|
---|
| 24 | }
|
---|
[18055] | 25 | if (res)
|
---|
[17481] | 26 | return ValidationResult.Successful();
|
---|
[18055] | 27 | else
|
---|
[17481] | 28 | return ValidationResult.Faulty(errors);
|
---|
[17473] | 29 | }
|
---|
[18055] | 30 |
|
---|
[18077] | 31 | public override void SetJObject(JObject jObject) {
|
---|
| 32 | base.SetJObject(jObject);
|
---|
| 33 | ConcreteRestrictedItems =
|
---|
| 34 | (jObject[nameof(IConcreteRestrictedJsonItem<T>.ConcreteRestrictedItems)]?
|
---|
| 35 | .ToObject<IEnumerable<T>>());
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[18055] | 38 | public ConcreteRestrictedArrayJsonItem() { }
|
---|
| 39 |
|
---|
| 40 | [StorableConstructor]
|
---|
| 41 | protected ConcreteRestrictedArrayJsonItem(StorableConstructorFlag _) : base(_) { }
|
---|
[17473] | 42 | }
|
---|
| 43 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.