1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-05 14:43:36 +02:00

Fixed issues with intermixing Addr32 and Add64's.

This commit is contained in:
Ken Ryall 2009-10-30 20:56:12 +00:00
parent 1cfc169c04
commit 9678044b11
2 changed files with 14 additions and 21 deletions

View file

@ -93,23 +93,15 @@ public class Addr32 implements IAddress {
} }
public BigInteger distanceTo(IAddress other) { public BigInteger distanceTo(IAddress other) {
if (!(other instanceof Addr32)) { return other.getValue().subtract(getValue());
throw new IllegalArgumentException();
}
return BigInteger.valueOf(((Addr32)other).address - address);
} }
public int compareTo(Object other) { public int compareTo(Object other) {
if (!(other instanceof Addr32)) { if (!(other instanceof IAddress)) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
if (address > ((Addr32)other).address) {
return 1; return getValue().compareTo(((IAddress)other).getValue());
}
if (address < ((Addr32)other).address) {
return -1;
}
return 0;
} }
public boolean isMax() { public boolean isMax() {
@ -133,9 +125,9 @@ public class Addr32 implements IAddress {
public boolean equals(Object x) { public boolean equals(Object x) {
if (x == this) if (x == this)
return true; return true;
if (!(x instanceof Addr32)) if (!(x instanceof IAddress))
return false; return false;
return this.address == ((Addr32)x).address; return getValue().equals(((IAddress)x).getValue());
} }
@Override @Override

View file

@ -93,10 +93,7 @@ public class Addr64 implements IAddress {
} }
public BigInteger distanceTo(IAddress other) { public BigInteger distanceTo(IAddress other) {
if (! (other instanceof Addr64)) { return other.getValue().subtract(getValue());
throw new IllegalArgumentException();
}
return ((Addr64)other).address.add(address.negate());
} }
public boolean isMax() { public boolean isMax() {
@ -112,16 +109,20 @@ public class Addr64 implements IAddress {
} }
public int compareTo(Object other) { public int compareTo(Object other) {
return this.address.compareTo(((Addr64)other).address); if (!(other instanceof IAddress)) {
throw new IllegalArgumentException();
}
return getValue().compareTo(((IAddress)other).getValue());
} }
@Override @Override
public boolean equals(Object x) { public boolean equals(Object x) {
if (x == this) if (x == this)
return true; return true;
if (! (x instanceof Addr64)) if (!(x instanceof IAddress))
return false; return false;
return this.address.equals(((Addr64)x).address); return getValue().equals(((IAddress)x).getValue());
} }
@Override @Override