@Test public void testAdd() { Assert.assertEquals(addr(0, 8), space.add(addr(0, 5), 3)); Assert.assertEquals(addr(10, 1), space.add(addr(10, 5), -4)); Assert.assertEquals(addr(0xffff, 0xffff), space.add(addr(0, 0), 0x10FFEF)); try { space.add(addr(0, 1), 0x10FFEF); Assert.fail(); } catch (AddressOutOfBoundsException e) { } try { Assert.assertEquals(addr(2, 8), space.addNoWrap(addr(2, 5), 3)); Assert.assertEquals(addr(0, 1), space.addNoWrap(addr(0, 5), -4)); } catch (AddressOverflowException e) { Assert.fail(e.getMessage()); } try { space.addNoWrap(addr(0xffff, 5), 0x10000); Assert.fail("Should not have gotten a value!"); } catch (AddressOverflowException e) { } }
@Override public Address add(Address addr, long displacement) { if (displacement < 0) { return subtract(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } long off = addr.getOffset() + displacement; if (off >= 0 && off <= maxOffset) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address add(Address addr, long displacement) { if (displacement < 0) { return subtract(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } long off = addr.getOffset() + displacement; if (off >= 0 && off <= maxOffset) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address add(Address addr, long displacement) { if (displacement < 0) { return subtract(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } long off = addr.getOffset() + displacement; if (off >= 0 && off <= maxOffset) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } SegmentedAddressSpace(String name, int unique); }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address add(Address addr, long displacement) { if (displacement < 0) { return subtract(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } long off = addr.getOffset() + displacement; if (off >= 0 && off <= maxOffset) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } SegmentedAddressSpace(String name, int unique); @Override Address getAddress(String addrString); @Override Address getAddress(String addrString, boolean caseSensitive); @Override Address subtract(Address addr, long displacement); @Override Address add(Address addr, long displacement); @Override SegmentedAddress getAddress(long byteOffset); @Override SegmentedAddress getAddressInThisSpaceOnly(long byteOffset); SegmentedAddress getAddress(int segment, int segmentOffset); @Override SegmentedAddressSpace getPhysicalSpace(); @Override int getPointerSize(); }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address add(Address addr, long displacement) { if (displacement < 0) { return subtract(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } long off = addr.getOffset() + displacement; if (off >= 0 && off <= maxOffset) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in add: " + addr + " + " + displacement); } SegmentedAddressSpace(String name, int unique); @Override Address getAddress(String addrString); @Override Address getAddress(String addrString, boolean caseSensitive); @Override Address subtract(Address addr, long displacement); @Override Address add(Address addr, long displacement); @Override SegmentedAddress getAddress(long byteOffset); @Override SegmentedAddress getAddressInThisSpaceOnly(long byteOffset); SegmentedAddress getAddress(int segment, int segmentOffset); @Override SegmentedAddressSpace getPhysicalSpace(); @Override int getPointerSize();  }