01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.text;
11:
12: /**
13: * The default implementation of the {@link org.eclipse.jface.text.IRegion} interface.
14: */
15: public class Region implements IRegion {
16:
17: /** The region offset */
18: private int fOffset;
19: /** The region length */
20: private int fLength;
21:
22: /**
23: * Create a new region.
24: *
25: * @param offset the offset of the region
26: * @param length the length of the region
27: */
28: public Region(int offset, int length) {
29: fOffset = offset;
30: fLength = length;
31: }
32:
33: /*
34: * @see org.eclipse.jface.text.IRegion#getLength()
35: */
36: public int getLength() {
37: return fLength;
38: }
39:
40: /*
41: * @see org.eclipse.jface.text.IRegion#getOffset()
42: */
43: public int getOffset() {
44: return fOffset;
45: }
46:
47: /*
48: * @see java.lang.Object#equals(java.lang.Object)
49: */
50: public boolean equals(Object o) {
51: if (o instanceof IRegion) {
52: IRegion r = (IRegion) o;
53: return r.getOffset() == fOffset && r.getLength() == fLength;
54: }
55: return false;
56: }
57:
58: /*
59: * @see java.lang.Object#hashCode()
60: */
61: public int hashCode() {
62: return (fOffset << 24) | (fLength << 16);
63: }
64:
65: /*
66: * @see java.lang.Object#toString()
67: */
68: public String toString() {
69: return "[" + fOffset + '+' + fLength + ']'; //$NON-NLS-1$
70: }
71: }
|