Ejemplo n.º 1
0
  /** @see java.util.AbstractMap#remove(java.lang.Object) */
  @SuppressWarnings("unchecked")
  public V remove(Object key) {
    K buscado;
    try {
      buscado = (K) key;
    } catch (ClassCastException e1) {
      return null;
    }
    Iterator<Entry<K, V>> i = entrySet().iterator();
    Entry<K, V> correctEntry = null;
    if (key == null) {
      while (correctEntry == null && i.hasNext()) {
        Entry<K, V> e = i.next();
        if (discriminadorKeys.areEquals(e.getKey(), null)) correctEntry = e;
      }
    } else {
      while (correctEntry == null && i.hasNext()) {
        Entry<K, V> e = i.next();
        if (discriminadorKeys.areEquals(buscado, e.getKey())) correctEntry = e;
      }
    }

    V oldValue = null;
    if (correctEntry != null) {
      oldValue = correctEntry.getValue();
      i.remove();
    }
    return oldValue;
  }
Ejemplo n.º 2
0
  /** @see java.util.AbstractMap#equals(java.lang.Object) */
  @SuppressWarnings("unchecked")
  public boolean equals(Object o) {
    if (o == this) return true;

    if (!(o instanceof Map)) return false;
    Map<K, V> t = (Map<K, V>) o;
    if (t.size() != size()) return false;

    try {
      Iterator<Entry<K, V>> i = entrySet().iterator();
      while (i.hasNext()) {
        Entry<K, V> e = i.next();
        K key = e.getKey();
        V value = e.getValue();
        if (value == null) {
          if (!(t.get(key) == null && t.containsKey(key))) return false;
        } else {
          if (!discriminadorValues.areEquals(value, t.get(key))) return false;
        }
      }
    } catch (ClassCastException unused) {
      return false;
    } catch (NullPointerException unused) {
      return false;
    }

    return true;
  }
Ejemplo n.º 3
0
 /** @see java.util.AbstractMap#get(java.lang.Object) */
 @SuppressWarnings("unchecked")
 public V get(Object key) {
   K buscado;
   try {
     buscado = (K) key;
   } catch (ClassCastException e1) {
     return null;
   }
   Iterator<Entry<K, V>> i = entrySet().iterator();
   if (key == null) {
     while (i.hasNext()) {
       Entry<K, V> e = i.next();
       if (discriminadorKeys.areEquals(e.getKey(), null)) return e.getValue();
     }
   } else {
     while (i.hasNext()) {
       Entry<K, V> e = i.next();
       if (discriminadorKeys.areEquals(buscado, e.getKey())) return e.getValue();
     }
   }
   return null;
 }