2using System.Collections.Generic;
 
    3using System.Globalization;
 
   11    internal abstract class ResourcePathBuilder
 
   13        protected abstract string base_path { 
get; }
 
   14        private readonly 
string _primaryKey;
 
   17        public string SubResource => $
"{base_path}{_primaryKey}";
 
   20        protected ResourcePathBuilder() { _primaryKey = 
""; }
 
   25        protected ResourcePathBuilder(
string primaryKey) => _primaryKey = $
"/{primaryKey}";
 
   27        protected ResourcePathBuilder(
double primaryKey) : this(FormatDouble(primaryKey)) { }
 
   29        protected ResourcePathBuilder(ProbabilityWindow primaryKey)
 
   30            : this($
"{FormatDouble(primaryKey.min_probability)}_{FormatDouble(primaryKey.max_probability)}") { }
 
   32        protected ResourcePathBuilder(
long primaryKey)
 
   33            : this(primaryKey.ToString(
"0", CultureInfo.InvariantCulture)) { }
 
   35        protected ResourcePathBuilder(IEnumerable<double> primaryKey)
 
   36            : this(String.Join(
",", primaryKey.Select(FormatDouble))) { }
 
   38        protected ResourcePathBuilder(IEnumerable<ProbabilityWindow> primaryKey)
 
   39            : this(String.Join(
",", primaryKey.Select(
 
   40                  k => $
"{FormatDouble(k.min_probability)}_{FormatDouble(k.max_probability)}"))) { }
 
   42        public override string ToString() => SubResource;
 
   44        public static implicit 
operator string(ResourcePathBuilder x) => x.ToString();
 
   46        private static string FormatDouble(
double d) => d.ToString(
"G17", CultureInfo.InvariantCulture);