HamBook – Rev 54

Subversion Repositories:
Rev:
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Configuration.Annotations;

namespace Configuration
{
    public class Definitions : INotifyPropertyChanged
    {
        private static readonly ConcurrentDictionary<int, Band> _metersToBand = new ConcurrentDictionary<int, Band>();

        private Band[] _bands =
        {
            new Band { Meters = 6, Min = 050000000, Max = 054000000 },
            new Band { Meters = 10, Min = 028000000, Max = 029700000 },
            new Band { Meters = 11, Min = 026965000, Max = 027405000 },
            new Band { Meters = 12, Min = 024920000, Max = 024990000 },
            new Band { Meters = 15, Min = 021000000, Max = 021450000 },
            new Band { Meters = 17, Min = 018068000, Max = 018168000 },
            new Band { Meters = 20, Min = 014000000, Max = 014350000 },
            new Band { Meters = 30, Min = 010100000, Max = 010150000 },
            new Band { Meters = 40, Min = 007000000, Max = 007300000 }
        };

        public Definitions()
        {
            if (_metersToBand.Count == 0)
                foreach (var band in _bands)
                    _metersToBand.TryAdd(band.Meters, band);
        }

        public Band[] Bands
        {
            get => _bands;
            set
            {
                if (value == _bands) return;

                _metersToBand.Clear();
                foreach (var band in value) _metersToBand.TryAdd(band.Meters, band);

                _bands = value;

                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        ///     Retrieve the minimum and maximum frequency from meters.
        /// </summary>
        /// <param name="meters">meters corresponding to a band</param>
        /// <param name="band">the band</param>
        /// <returns>true upon a band definition existing</returns>
        public bool TryGetBand(int meters, out Band band)
        {
            return _metersToBand.TryGetValue(meters, out band);
        }

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Generated by GNU Enscript 1.6.5.90.