KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > MemorySegment


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.views.memory.renderings;
13
14 import java.math.BigInteger JavaDoc;
15 import java.util.ArrayList JavaDoc;
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 JavaDoc fAddress;
23     private BigInteger JavaDoc fEndAddress;
24     private MemoryByte[] fBytes;
25     private int fNumAddressableUnits;
26     
27     public MemorySegment(BigInteger JavaDoc address, MemoryByte[] bytes, int numAddressableUnits)
28     {
29         fAddress = address;
30         fBytes = bytes;
31         fNumAddressableUnits = numAddressableUnits;
32     }
33     
34     public BigInteger JavaDoc 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 JavaDoc address)
47     {
48         if (getAddress().compareTo(address) <= 0 && getEndAddress().compareTo(address) >= 0)
49             return true;
50         return false;
51     }
52     
53     public BigInteger JavaDoc getEndAddress()
54     {
55         if (fEndAddress == null)
56         {
57             fEndAddress = fAddress.add(BigInteger.valueOf(fNumAddressableUnits).subtract(BigInteger.ONE));
58         }
59         return fEndAddress;
60     }
61     
62     /**
63      * @param start - zero-based start offset
64      * @param length - number of bytes to get
65      * @return the bytes from start offset to the end.
66      */

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 JavaDoc ret = new ArrayList JavaDoc();
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