1 11 12 package org.eclipse.debug.internal.ui.views.memory.renderings; 13 14 import java.math.BigInteger ; 15 import java.util.ArrayList ; 16 17 import org.eclipse.core.runtime.PlatformObject; 18 import org.eclipse.debug.core.model.MemoryByte; 19 20 public class MemorySegment extends PlatformObject { 21 22 private BigInteger fAddress; 23 private BigInteger fEndAddress; 24 private MemoryByte[] fBytes; 25 private int fNumAddressableUnits; 26 27 public MemorySegment(BigInteger address, MemoryByte[] bytes, int numAddressableUnits) 28 { 29 fAddress = address; 30 fBytes = bytes; 31 fNumAddressableUnits = numAddressableUnits; 32 } 33 34 public BigInteger getAddress() { 35 return fAddress; 36 } 37 38 public MemoryByte[] getBytes() { 39 return fBytes; 40 } 41 42 public int getNumAddressableUnits() { 43 return fNumAddressableUnits; 44 } 45 46 public boolean containsAddress(BigInteger address) 47 { 48 if (getAddress().compareTo(address) <= 0 && getEndAddress().compareTo(address) >= 0) 49 return true; 50 return false; 51 } 52 53 public BigInteger getEndAddress() 54 { 55 if (fEndAddress == null) 56 { 57 fEndAddress = fAddress.add(BigInteger.valueOf(fNumAddressableUnits).subtract(BigInteger.ONE)); 58 } 59 return fEndAddress; 60 } 61 62 67 public MemoryByte[] getBytes(int start, int length) 68 { 69 if (start < 0) 70 return new MemoryByte[0]; 71 72 if (start + length > fBytes.length) 73 return new MemoryByte[0]; 74 75 ArrayList ret = new ArrayList (); 76 77 for (int i=start; i< start+length; i++) 78 { 79 ret.add(fBytes[i]); 80 } 81 return (MemoryByte[]) ret.toArray(new MemoryByte[ret.size()]); 82 } 83 84 } 85 | Popular Tags |