01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 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: * Default implementation of {@link org.eclipse.jface.text.ITypedRegion}. A
14: * <code>TypedRegion</code> is a value object.
15: */
16: public class TypedRegion extends Region implements ITypedRegion {
17:
18: /** The region's type */
19: private String fType;
20:
21: /**
22: * Creates a typed region based on the given specification.
23: *
24: * @param offset the region's offset
25: * @param length the region's length
26: * @param type the region's type
27: */
28: public TypedRegion(int offset, int length, String type) {
29: super (offset, length);
30: fType = type;
31: }
32:
33: /*
34: * @see org.eclipse.jface.text.ITypedRegion#getType()
35: */
36: public String getType() {
37: return fType;
38: }
39:
40: /*
41: * @see java.lang.Object#equals(java.lang.Object)
42: */
43: public boolean equals(Object o) {
44: if (o instanceof TypedRegion) {
45: TypedRegion r = (TypedRegion) o;
46: return super .equals(r)
47: && ((fType == null && r.getType() == null) || fType
48: .equals(r.getType()));
49: }
50: return false;
51: }
52:
53: /*
54: * @see java.lang.Object#hashCode()
55: */
56: public int hashCode() {
57: int type = fType == null ? 0 : fType.hashCode();
58: return super.hashCode() | type;
59: }
60: }
|