KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > Region


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 package org.eclipse.jface.text;
12
13
14 /**
15  * The default implementation of the {@link org.eclipse.jface.text.IRegion} interface.
16  */

17 public class Region implements IRegion {
18
19     /** The region offset */
20     private int fOffset;
21     /** The region length */
22     private int fLength;
23
24     /**
25      * Create a new region.
26      *
27      * @param offset the offset of the region
28      * @param length the length of the region
29      */

30     public Region(int offset, int length) {
31         fOffset= offset;
32         fLength= length;
33     }
34
35     /*
36      * @see org.eclipse.jface.text.IRegion#getLength()
37      */

38     public int getLength() {
39         return fLength;
40     }
41
42     /*
43      * @see org.eclipse.jface.text.IRegion#getOffset()
44      */

45     public int getOffset() {
46         return fOffset;
47     }
48
49     /*
50      * @see java.lang.Object#equals(java.lang.Object)
51      */

52     public boolean equals(Object JavaDoc o) {
53         if (o instanceof IRegion) {
54             IRegion r= (IRegion) o;
55             return r.getOffset() == fOffset && r.getLength() == fLength;
56         }
57         return false;
58     }
59
60     /*
61      * @see java.lang.Object#hashCode()
62      */

63     public int hashCode() {
64         return (fOffset << 24) | (fLength << 16);
65     }
66 }
67
Popular Tags