@Test
 public void getMapEntry() {
   HazelcastClient hClient = getHazelcastClient();
   IMap map = hClient.getMap("getMapEntry");
   assertNull(map.put("a", "b"));
   map.get("a");
   map.get("a");
   MapEntry<String, String> entry = map.getMapEntry("a");
   assertEquals("a", entry.getKey());
   assertEquals("b", entry.getValue());
   assertEquals(2, entry.getHits());
   assertEquals("b", entry.getValue());
   assertEquals("b", entry.setValue("c"));
   assertEquals("c", map.get("a"));
   assertEquals("c", entry.getValue());
 }
コード例 #2
0
 public V put(K key, V value) {
   V oldValue = null;
   int index = Math.abs(key.hashCode()) % SIZE;
   if (buckets[index] == null) buckets[index] = new ArrayList<MapEntry<K, V>>();
   ArrayList<MapEntry<K, V>> bucket = buckets[index];
   MapEntry<K, V> pair = new MapEntry<K, V>(key, value);
   boolean found = false;
   ListIterator<MapEntry<K, V>> it = bucket.listIterator();
   // int probes=0;
   while (it.hasNext()) {
     //	probes++;
     MapEntry<K, V> iPair = it.next();
     //  if(!iPair.getKey().equals(key)) System.out.println("HashCode collision on put, have
     // key:"+key+" hascode:"+key.hashCode()+" found key:"+iPair.getKey()+" hashcode:"+
     // iPair.getKey().hashCode());
     if (iPair.getKey().equals(key)) {
       oldValue = iPair.getValue();
       it.set(pair); // Replace old with new
       found = true;
       break;
     }
   }
   // System.out.println("put() probes for key "+ key+" :"+probes);
   if (!found) buckets[index].add(pair);
   return oldValue;
 }
コード例 #3
0
  @Override
  public V remove(Object key) {

    int index = Math.abs(key.hashCode()) % SIZE;
    if (buckets[index] == null) return null;
    for (MapEntry<K, V> iPair : buckets[index]) {
      if (iPair.getKey().equals(key)) {
        buckets[index].remove(iPair);
        return iPair.getValue();
      }
    }
    return null;
  }
コード例 #4
0
 public V get(Object key) {
   int index = Math.abs(key.hashCode()) % SIZE;
   if (buckets[index] == null) return null;
   //  int probes=0;
   for (MapEntry<K, V> iPair : buckets[index]) {
     //      probes++;
     // 	if(!iPair.getKey().equals(key)) System.out.println("HashCode collision on put, have
     // key:"+key+" hascode:"+key.hashCode()+" foune key:"+iPair.getKey()+" hashcode:"+
     // iPair.getKey().hashCode());
     if (iPair.getKey().equals(key)) return iPair.getValue();
   }
   //  System.out.println("get() probes for key "+ key+" :"+probes);
   return null;
 }