Beispiel #1
0
        public Generator(int totalCount, int groupSize = -1)
        {
            this.generatorRange = new GeneratorRange
            {
                Min   = 0,
                Count = totalCount
            };

            this.totalCount = totalCount;
            this.groupSize  = groupSize;
            this.size       = totalCount.ToString().Length;
        }
Beispiel #2
0
        public GeneratorRange GroupStartsWith(string pattern)
        {
            var gRange = new GeneratorRange
            {
                Min   = 0,
                Count = this.totalCount
            };

            gRange = this.GetIdRange(pattern, gRange);

            gRange.Min   *= this.groupSize;
            gRange.Count *= this.groupSize;

            this.generatorRange.Intersect(gRange);

            return(this.generatorRange);
        }
Beispiel #3
0
        private GeneratorRange GetIdRange(string pattern, GeneratorRange gRange)
        {
            var lowerPattern = pattern.Substring(1).PadRight(this.size, '0');
            var upperPattern = pattern.Substring(1).PadRight(this.size, '9');

            if (int.TryParse(lowerPattern, out var minVal))
            {
                gRange.Min = Math.Max(gRange.Min, minVal);
            }

            if (int.TryParse(upperPattern, out var maxVal))
            {
                gRange.Count = Math.Min(gRange.Count, maxVal - gRange.Min + 1);
            }

            return(gRange);
        }
Beispiel #4
0
        public GeneratorRange Intersect(GeneratorRange generatorRange)
        {
            if (this.Min > generatorRange.Max)
            {
                this.Count = 0;
            }
            else if (this.Max < generatorRange.Min)
            {
                this.Count = 0;
            }
            else
            {
                var max = Math.Min(this.Max, generatorRange.Max);
                this.Min   = Math.Max(this.Min, generatorRange.Min);
                this.Count = max - this.Min + 1;
            }

            return(this);
        }