private void PrimeNext()
            {
                K1 k1 = null;

                if (next != null)
                {
                    k1 = next.GetFirstKey();
                }
                while (innerIterator == null || !innerIterator.MoveNext())
                {
                    if (!outerIterator.MoveNext())
                    {
                        next = null;
                        return;
                    }
                    KeyValuePair <K1, IDictionary <K2, V> > outerEntry = outerIterator.Current;
                    k1            = outerEntry.Key;
                    innerIterator = outerEntry.Value.GetEnumerator();
                }
                KeyValuePair <K2, V> innerEntry = innerIterator.Current;

                next = new TwoDimensionalMap.Entry <K1, K2, V>(k1, innerEntry.Key, innerEntry.Value);
            }
        public virtual void TestTreeMapIterator()
        {
            TwoDimensionalMap <string, string, string> map = new TwoDimensionalMap <string, string, string>(MapFactory.TreeMapFactory <string, IDictionary <string, string> >(), MapFactory.TreeMapFactory <string, string>());

            map.Put("A", "B", "C");
            map.Put("Z", "Y", "X");
            map.Put("Z", "B", "C");
            map.Put("A", "Y", "X");
            map.Put("D", "D", "D");
            map.Put("D", "F", "E");
            map.Put("K", "G", "B");
            map.Put("G", "F", "E");
            map.Put("D", "D", "E");
            // sneaky overwritten entry
            NUnit.Framework.Assert.AreEqual(8, map.Size());
            IEnumerator <TwoDimensionalMap.Entry <string, string, string> > mapIterator = map.GetEnumerator();

            TwoDimensionalMap.Entry <string, string, string> entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("A", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("B", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("C", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("A", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("Y", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("X", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("D", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("D", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("E", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("D", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("F", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("E", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("G", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("F", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("E", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("K", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("G", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("B", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("Z", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("B", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("C", entry.GetValue());
            entry = mapIterator.Current;
            NUnit.Framework.Assert.AreEqual("Z", entry.GetFirstKey());
            NUnit.Framework.Assert.AreEqual("Y", entry.GetSecondKey());
            NUnit.Framework.Assert.AreEqual("X", entry.GetValue());
            NUnit.Framework.Assert.IsFalse(mapIterator.MoveNext());
            IEnumerator <string> valueIterator = map.ValueIterator();

            NUnit.Framework.Assert.IsTrue(valueIterator.MoveNext());
            NUnit.Framework.Assert.AreEqual("C", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("X", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("E", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("E", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("E", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("B", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("C", valueIterator.Current);
            NUnit.Framework.Assert.AreEqual("X", valueIterator.Current);
            NUnit.Framework.Assert.IsFalse(valueIterator.MoveNext());
        }