2 * (c) Copyright IBM Corp. 2000, 2001.
5 package net.sourceforge.phpdt.internal.corext.template;
8 * A template consiting of a name and a pattern.
10 public class Template {
12 /** The name of this template */
14 /** A description of this template */
15 private String fDescription;
16 /** The name of the context type of this template */
17 private String fContextTypeName;
18 /** The template pattern. */
19 private String fPattern;
20 /** A flag indicating if the template is active or not. */
21 private boolean fEnabled= true;
24 * Creates an empty template.
27 this("", "", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
31 * Creates a copy of a template.
33 public Template(Template template) {
34 this(template.getName(), template.getDescription(), template.getContextTypeName(), template.getPattern());
40 * @param name the name of the template.
41 * @param description the description of the template.
42 * @param contextTypeName the name of the context type in which the template can be applied.
43 * @param pattern the template pattern.
45 public Template(String name, String description, String contextTypeName, String pattern) {
47 fDescription= description;
48 fContextTypeName= contextTypeName;
53 * @see Object#equals(Object)
55 public boolean equals(Object object) {
56 if (!(object instanceof Template))
59 Template template= (Template) object;
65 template.fName.equals(fName) &&
66 template.fPattern.equals(fPattern) &&
67 template.fContextTypeName.equals(fContextTypeName);
71 * @see Object#hashCode()
73 public int hashCode() {
74 return fName.hashCode() ^ fPattern.hashCode() ^ fContextTypeName.hashCode();
78 * Sets the description of the template.
80 public void setDescription(String description) {
81 fDescription= description;
85 * Returns the description of the template.
87 public String getDescription() {
92 * Sets the name of the context type in which the template can be applied.
94 public void setContext(String contextTypeName) {
95 fContextTypeName= contextTypeName;
99 * Returns the name of the context type in which the template can be applied.
101 public String getContextTypeName() {
102 return fContextTypeName;
106 * Sets the name of the template.
108 public void setName(String name) {
113 * Returns the name of the template.
115 public String getName() {
123 * Sets the pattern of the template.
125 public void setPattern(String pattern) {
130 * Returns the template pattern.
132 public String getPattern() {
137 * Sets the enable state of the template.
139 public void setEnabled(boolean enable) {
144 * Returns <code>true</code> if template is enabled, <code>false</code> otherwise.
146 public boolean isEnabled() {
151 * Returns <code>true</code> if template matches the prefix and context,
152 * <code>false</code> otherwise.
154 public boolean matches(String prefix, String contextTypeName) {
157 fContextTypeName.equals(contextTypeName) &&
158 (prefix.length() != 0) &&
159 fName.toLowerCase().startsWith(prefix.toLowerCase());