/// <summary> /// Validate and add number created using digits /// </summary> /// <param name="digits">digits to use to form number</param> /// <returns>true if success, false otherwise</returns> private bool ValidateAndAddLotteryNumber(char[] digits) { LotteryNumber num; var res = LotteryNumber.Create(out num, digits); if (!res) { return(false); } return(AddLotteryNumber(num)); }
/// <summary> /// Creates a lottery number /// </summary> /// <param name="num">out parameter with created object</param> /// <param name="digits">digits to use for creation</param> /// <returns>true if success</returns> public static bool Create(out LotteryNumber num, params char[] digits) { try { num = new LotteryNumber(digits); return(true); } catch (ArgumentException) { num = null; return(false); } }
/// <summary> /// Adds a lottery number to the _numbersSoFar list if it is unique /// </summary> /// <param name="num">number to add</param> /// <returns>true if unique, false otherwise</returns> private bool AddLotteryNumber(LotteryNumber num) { if (num == null) { throw new ArgumentNullException(nameof(num)); } //do unique check if (_numberListSoFar.Find(n => n.Equals(num)) != null) { return(false); } _numberListSoFar.Add(num); _parserState.NumbersSeen += 1; return(true); }
/// <summary> /// Matches a single digit, and moves token forwards if it is a digit /// </summary> /// <returns>true if next char is digit, else false</returns> private bool MatchDigit() { if (GetRemainingLength() == 0) { return(false); } char tok = GetNextToken(); if (!LotteryNumber.IsDigit(tok)) { return(false); } MoveNext(); return(true); }
/// <summary> /// Equality is based on decimal value so that 01 are 1 equal /// </summary> /// <param name="other"></param> /// <returns>true if equals</returns> public bool Equals(LotteryNumber other) { return(_number == other?._number); }