-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRole.cs
More file actions
37 lines (30 loc) · 1.17 KB
/
Copy pathRole.cs
File metadata and controls
37 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
namespace JSONstat.Models;
/// <summary>
/// Optional object assigning special roles to dimensions.
/// Source: <c>../wiki/dataset-structure.md</c>.
/// </summary>
public sealed class Role
{
/// <summary>Dimension ids with the time role.</summary>
public string[]? Time { get; set; }
/// <summary>Dimension ids with the geo role.</summary>
public string[]? Geo { get; set; }
/// <summary>Dimension ids with the metric role.</summary>
public string[]? Metric { get; set; }
/// <summary>True when no role is assigned.</summary>
public bool IsEmpty =>
(Time is null || Time.Length == 0) &&
(Geo is null || Geo.Length == 0) &&
(Metric is null || Metric.Length == 0);
/// <summary>Resolves the role of a dimension id, or null when unroled.</summary>
internal DimensionRole? RoleOf(string id)
{
if (Contains(Time, id)) return DimensionRole.Time;
if (Contains(Geo, id)) return DimensionRole.Geo;
if (Contains(Metric, id)) return DimensionRole.Metric;
return null;
}
private static bool Contains(string[]? arr, string id) =>
arr != null && Array.IndexOf(arr, id) >= 0;
}