Пример #1
0
        public void TestGet()
        {
            Assert.IsNull(hm.Get("T"), "Get returned non-null for non existent key");
            hm.Put("T", "HELLO");
            Assert.AreEqual("HELLO", hm.Get("T"), "Get returned incorrect value for existing key");

            HashMap <Object, Object> m = new HashMap <Object, Object>();

            m.Put(null, "test");
            Assert.AreEqual("test", m.Get(null), "Assert.Failed with null key");
            Assert.IsNull(m.Get(0), "Assert.Failed with missing key matching null hash");

            ReusableKey k = new ReusableKey();
            HashMap <Object, Object> map = new HashMap <Object, Object>();

            k.Key = 1;
            map.Put(k, "value1");

            k.Key = 18;
            Assert.IsNull(map.Get(k));

            k.Key = 17;
            Assert.IsNull(map.Get(k));
        }
Пример #2
0
 protected HashSet(HashMap <E, HashSet <E> > backingMap)
 {
     this.backingMap = backingMap;
 }
Пример #3
0
        public void TestPut2()
        {
            hm.Put("KEY", "VALUE");
            Assert.AreEqual("VALUE", hm.Get("KEY"), "Assert.Failed to install key/value pair");

            HashMap <Object, Object> m = new HashMap <Object, Object>();

            m.Put(0, "short");
            m.Put(null, "test");
            m.Put(0, "int");
            Assert.AreEqual("int", m.Get(0), "Assert.Failed adding to bucket containing null");
            Assert.AreEqual("int", m.Get(0), "Assert.Failed adding to bucket containing null2");

            // Check my actual key instance is returned
            HashMap <Object, String> map = new HashMap <Object, String>();

            for (int i = -32767; i < 32768; i++)
            {
                map.Put(i, "foobar");
            }
            Object myKey = 0;

            // Put a new value at the old key position
            map.Put(myKey, "myValue");
            Assert.IsTrue(map.ContainsKey(myKey));
            Assert.AreEqual("myValue", map.Get(myKey));
            bool found = false;

            for (Iterator <Object> itr = map.KeySet().Iterator(); itr.HasNext;)
            {
                Object key = itr.Next();
                if (found = key == myKey)
                {
                    break;
                }
            }

            Assert.IsFalse(found, "Should not find new key instance in hashmap");

            // Add a new key instance and check it is returned
            Assert.IsNotNull(map.Remove(myKey));
            map.Put(myKey, "myValue");
            Assert.IsTrue(map.ContainsKey(myKey));
            Assert.AreEqual(map.Get(myKey), "myValue");
            for (Iterator <Object> itr = map.KeySet().Iterator(); itr.HasNext;)
            {
                Object key = itr.Next();
                if (found = key == myKey)
                {
                    break;
                }
            }
            Assert.IsTrue(found, "Did not find new key instance in hashmap");

            // Ensure keys with identical hashcode are stored separately
            HashMap <Object, Object> objmap = new HashMap <Object, Object>();

            for (int i = 0; i < 32768; i++)
            {
                objmap.Put(i, "foobar");
            }
            // Put non-equal object with same hashcode
            MyKey aKey = new MyKey();

            Assert.IsNull(objmap.Put(aKey, "value"));
            Assert.IsNull(objmap.Remove(new MyKey()));
            Assert.AreEqual(objmap.Get(0), "foobar");
            Assert.AreEqual(objmap.Get(aKey), "value");
        }
Пример #4
0
 public ValuesCollection(HashMap <K, V> parent) : base()
 {
     this.parent = parent;
 }
Пример #5
0
 public KeySetCollection(HashMap <K, V> parent) : base()
 {
     this.parent = parent;
 }
Пример #6
0
 public HashMapEntrySet(HashMap <K, V> parent) : base()
 {
     associatedMap = parent;
 }
Пример #7
0
 public ValueIterator(HashMap <K, V> parent) : base(parent)
 {
 }
Пример #8
0
 public KeyIterator(HashMap <K, V> parent) : base(parent)
 {
 }
Пример #9
0
 public AbstractMapIterator(HashMap <K, V> parent)
 {
     associatedMap    = parent;
     expectedModCount = parent.modCount;
     futureEntry      = null;
 }