Much saner implementation of 'overlaps' method.
This commit is contained in:
1 parent
5bbd72d44e
commit
af7743b385
3 files changed
+34
-43
No files matched your search
@@ -20,8 +20,9 @@ public class AddressDecoder {
|
||||
throws MemoryRangeException {
|
||||
// Make sure there's no memory overlap.
|
||||
for (MemoryRange memRange : ioMap.keySet()) {
|
||||
if (d.getMemoryRange().overlapsWith(memRange)) {
|
||||
throw new MemoryRangeException("The device being added overlaps with an existing device.");
|
||||
if (d.getMemoryRange().overlaps(memRange)) {
|
||||
throw new MemoryRangeException("The device being added overlaps " +
|
||||
"with an existing device.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ public class MemoryRange implements Comparable<MemoryRange> {
|
||||
throw new MemoryRangeException("Addresses cannot be less than 0.");
|
||||
}
|
||||
if (startAddress >= endAddress) {
|
||||
throw new MemoryRangeException("End address must be greater than start address.");
|
||||
throw new MemoryRangeException("End address must be greater " +
|
||||
"than start address.");
|
||||
}
|
||||
this.startAddress = startAddress;
|
||||
this.endAddress = endAddress;
|
||||
@@ -40,15 +41,9 @@ public class MemoryRange implements Comparable<MemoryRange> {
|
||||
*
|
||||
* @returns true if this range overlaps in any way with the other.
|
||||
*/
|
||||
public boolean overlapsWith(MemoryRange other) {
|
||||
return ((this.getEndAddress() >= other.getStartAddress() &&
|
||||
this.getEndAddress() <= other.getEndAddress()) ||
|
||||
(other.getEndAddress() >= this.getStartAddress() &&
|
||||
other.getEndAddress() <= this.getEndAddress()) ||
|
||||
(this.getStartAddress() <= other.getStartAddress() &&
|
||||
this.getEndAddress() >= other.getEndAddress()) ||
|
||||
(other.getStartAddress() <= this.getStartAddress() &&
|
||||
other.getEndAddress() >= this.getEndAddress()));
|
||||
public boolean overlaps(MemoryRange other) {
|
||||
return (this.includes(other.getStartAddress()) ||
|
||||
other.includes(this.getStartAddress()));
|
||||
}
|
||||
|
||||
// Implementation of Comparable interface
|
||||
|
||||
Reference in new issue
Block a user