/// <summary> /// Returns one of: /// 0 fragments /// 1 additive or subtractive fragment /// Both /// </summary> /// <param name="romanNumeral"></param> /// <param name="value"></param> /// <returns></returns> private static List<RomanNumeralFragment> GetFragmentsForRomanNumeral(RomanNumeral romanNumeral, int value) { var result = new List<RomanNumeralFragment>(); var count = GetFullNumeralCount(value, romanNumeral); var fragmentString = GetAdditiveFragmentString(count, romanNumeral); if (fragmentString.Length > 0) { var fragment = new RomanNumeralFragment(fragmentString); result.Add(fragment); value = value - fragment.Value; } var subtractiveFragment = GetSubtractiveFragment(romanNumeral, value); if (subtractiveFragment != null) { result.Add(subtractiveFragment); } return result; }
/// <summary> /// Returns a subtractive fragment using the specified roman numeral. Returns null if not needed /// </summary> /// <param name="currentRomanNumeral"></param> /// <param name="value"></param> /// <returns></returns> private static RomanNumeralFragment GetSubtractiveFragment(RomanNumeral currentRomanNumeral, int value) { RomanNumeralFragment fragment = null; // check if value if difference is greater than numeral minus C if ((value > (int)RomanNumeral.C) && (value >= ((int)currentRomanNumeral - (int)RomanNumeral.C))) { // if greater, we need to use a C subtractive fragment fragment = new RomanNumeralFragment(GetSubtractiveFragmentString(RomanNumeral.C, currentRomanNumeral)); } // if false, check for X and I using rules above else if ((value > (int)RomanNumeral.X) && (value >= ((int)currentRomanNumeral - (int)RomanNumeral.X))) { // if greater, we need to use a X subtractive fragment fragment = new RomanNumeralFragment(GetSubtractiveFragmentString(RomanNumeral.X, currentRomanNumeral)); } else if ((value > (int)RomanNumeral.I) && (value >= ((int)currentRomanNumeral - (int)RomanNumeral.I))) { // if greater, we need to use a I subtractive fragment fragment = new RomanNumeralFragment(GetSubtractiveFragmentString(RomanNumeral.I, currentRomanNumeral)); } return fragment; }