KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
16  * Default implementation of {@link org.eclipse.jface.text.ITypedRegion}. A
17  * <code>TypedRegion</code> is a value object.
18  */

19 public class TypedRegion extends Region implements ITypedRegion {
20
21     /** The region's type */
22     private String JavaDoc fType;
23
24     /**
25      * Creates a typed region based on the given specification.
26      *
27      * @param offset the region's offset
28      * @param length the region's length
29      * @param type the region's type
30      */

31     public TypedRegion(int offset, int length, String JavaDoc type) {
32         super(offset, length);
33         fType= type;
34     }
35
36     /*
37      * @see org.eclipse.jface.text.ITypedRegion#getType()
38      */

39     public String JavaDoc getType() {
40         return fType;
41     }
42
43     /*
44      * @see java.lang.Object#equals(java.lang.Object)
45      */

46     public boolean equals(Object JavaDoc o) {
47         if (o instanceof TypedRegion) {
48             TypedRegion r= (TypedRegion) o;
49             return super.equals(r) && ((fType == null && r.getType() == null) || fType.equals(r.getType()));
50         }
51         return false;
52     }
53
54      /*
55      * @see java.lang.Object#hashCode()
56      */

57     public int hashCode() {
58         int type= fType == null ? 0 : fType.hashCode();
59         return super.hashCode() | type;
60      }
61 }
62
Popular Tags