/**
* Adaptation de la librairie Sun TreeMap
* @author Florence Charreteur
*
*/
package related;
public final class EntryRBT {
public static final int BLACK=1;
public static final int RED=0;
public int key;
public int value;
public EntryRBT left;
public EntryRBT right;
public EntryRBT parent;
public int color;
/**
* Make a new cell with given key, value, and parent, and with
* <tt>null</tt> child links, and BLACK color.
*/
public EntryRBT() {}
public EntryRBT(int key, int value, EntryRBT parent) {
this.key = key;
this.value = value;
this.parent = parent;
}
/**
* Returns the key.
*
* @return the key
*/
public int getKey() {
return key;
}
/**
* Returns the value associated with the key.
*
* @return the value associated with the key
*/
public int getValue() {
return value;
}
/**
* Replaces the value currently associated with the key with the given
* value.
*
* @return the value associated with the key before this method was
* called
*/
public int setValue(int value) {
int oldValue = this.value;
this.value = value;
return oldValue;
}
public boolean equals(Object obj){
if (obj instanceof EntryRBT){
EntryRBT tree;
tree= (EntryRBT) obj;
if (this.color != tree.color || this.key != tree.key || this.value!=tree.value)
return false;
if (this.left == null && this.right == null && this.parent == null)
return tree.left==null && tree.right==null && tree.parent==null;
if (this.left == null && this.right == null && this.parent != null )
return tree.left== null && tree.right== null&& this.parent.equals(tree.parent);
if (this.left == null && this.right != null && this.parent == null)
return tree.left== null && this.right.equals(tree.right) && tree.parent== null ;
if (this.left == null && this.right != null && this.parent != null)
return tree.left== null && this.right.equals(tree.right) && this.parent.equals(tree.parent);
if (this.left != null && this.right == null && this.parent == null)
return this.left.equals(tree.left) && tree.right== null && tree.parent== null;
if (this.left != null && this.right == null && this.parent != null)
return this.left.equals(tree.left) && tree.right== null && this.parent.equals(tree.parent);
if (this.left != null && this.right != null && this.parent == null)
return this.left.equals(tree.left) && this.right.equals(tree.right) && tree.parent== null;
if (this.left != null && this.right != null && this.parent != null)
return this.left.equals(tree.left) && this.right.equals(tree.right) && this.parent.equals(tree.parent);
}
return false;
}
}
|