示例#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;
  }
示例#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;
  }
示例#3
0
 /**
  * Devuelve un discriminante para la entry basada en el valor de sus componentes
  *
  * @param entry Entry a discriminar
  * @return Un valor que diferencia a esta entry
  * @see ar.com.fdvs.dgarcia.lang.identificators.Identificator#discriminator(Object)
  */
 public long discriminator(Entry<K, V> entry) {
   K key = null;
   if (entry != null) {
     key = entry.getKey();
   }
   return discriminadorKeys.discriminator(key);
 }
示例#4
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;
 }