92 lines
2.0 KiB
Java
92 lines
2.0 KiB
Java
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
*/
|
|
package hashmapasdv_ant;
|
|
|
|
import java.util.Map.Entry;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
*
|
|
* @author caleb
|
|
*/
|
|
class EntryASDV<K, V> implements Entry<K, V>, Comparable<K>
|
|
{
|
|
|
|
K key;
|
|
V value;
|
|
|
|
public EntryASDV(K key, V value)
|
|
{
|
|
this.key = key;
|
|
this.value = value;
|
|
}
|
|
|
|
@Override
|
|
public K getKey()
|
|
{
|
|
return key;
|
|
}
|
|
|
|
@Override
|
|
public V getValue()
|
|
{
|
|
return value;
|
|
}
|
|
|
|
@Override
|
|
public V setValue(V value)
|
|
{
|
|
V oldValue = this.value;
|
|
this.value = value;
|
|
return oldValue;
|
|
}
|
|
|
|
@Override
|
|
public String toString()
|
|
{
|
|
return "EntryASDV{" + "key=" + key + ", value=" + value + '}';
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj)
|
|
{
|
|
if (this == obj)
|
|
{
|
|
return true;
|
|
}
|
|
if (obj == null)
|
|
{
|
|
return false;
|
|
}
|
|
if (getClass() != obj.getClass())
|
|
{
|
|
return false;
|
|
}
|
|
final EntryASDV<?, ?> other = (EntryASDV<?, ?>) obj;
|
|
if (!Objects.equals(this.key, other.key))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param o
|
|
* @return throws IllegalArgumentException if parameter class is not K
|
|
*/
|
|
@Override
|
|
public int compareTo(K o)
|
|
{
|
|
if (getClass() != o.getClass())
|
|
{
|
|
throw new IllegalArgumentException("ellegal parameter " + o);
|
|
}
|
|
return ((Comparable) key).compareTo(o);
|
|
}
|
|
|
|
}
|
|
|