129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.TypedPosition;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18 /**
|
|
19 * Convenience class for positions that have a type, similar to
|
|
20 * {@link dwtx.jface.text.ITypedRegion}.
|
|
21 * <p>
|
|
22 * As {@link dwtx.jface.text.Position},<code>TypedPosition</code> can
|
|
23 * not be used as key in hash tables as it overrides <code>equals</code> and
|
|
24 * <code>hashCode</code> as it would be a value object.
|
|
25 */
|
|
26 public class TypedPosition : Position {
|
|
27
|
|
28 /** The type of the region described by this position */
|
|
29 private String fType;
|
|
30
|
|
31 /**
|
|
32 * Creates a position along the given specification.
|
|
33 *
|
|
34 * @param offset the offset of this position
|
|
35 * @param length the length of this position
|
|
36 * @param type the content type of this position
|
|
37 */
|
|
38 public TypedPosition(int offset, int length, String type) {
|
|
39 super(offset, length);
|
|
40 fType= type;
|
|
41 }
|
|
42
|
|
43 /**
|
|
44 * Creates a position based on the typed region.
|
|
45 *
|
|
46 * @param region the typed region
|
|
47 */
|
|
48 public TypedPosition(ITypedRegion region) {
|
|
49 super(region.getOffset(), region.getLength());
|
|
50 fType= region.getType();
|
|
51 }
|
|
52
|
|
53 /**
|
|
54 * Returns the content type of the region.
|
|
55 *
|
|
56 * @return the content type of the region
|
|
57 */
|
|
58 public String getType() {
|
|
59 return fType;
|
|
60 }
|
|
61
|
|
62 /*
|
|
63 * @see java.lang.Object#equals(java.lang.Object)
|
|
64 */
|
|
65 public bool equals(Object o) {
|
|
66 if (o instanceof TypedPosition) {
|
|
67 if (super.equals(o)) {
|
|
68 TypedPosition p= (TypedPosition) o;
|
|
69 return (fType is null && p.getType() is null) || fType.equals(p.getType());
|
|
70 }
|
|
71 }
|
|
72 return false;
|
|
73 }
|
|
74
|
|
75 /*
|
|
76 * @see java.lang.Object#hashCode()
|
|
77 */
|
|
78 public int hashCode() {
|
|
79 int type= fType is null ? 0 : fType.hashCode();
|
|
80 return super.hashCode() | type;
|
|
81 }
|
|
82 }
|