4
* AbstractCodeTemplate.java - Base class for code templates.
6
* This library is distributed under a modified BSD license. See the included
7
* RSyntaxTextArea.License.txt file for details.
9
package org.fife.ui.rsyntaxtextarea.templates;
13
* A base class to build code templates on top of.
15
* @author Robert Futrell
18
public abstract class AbstractCodeTemplate implements CodeTemplate {
21
* The ID of this template.
27
* This no-arg constructor is required for serialization purposes.
29
public AbstractCodeTemplate() {
34
* Creates a new template.
36
* @param id The ID for this template.
37
* @throws IllegalArgumentException If <code>id</code> is <code>null</code>.
39
public AbstractCodeTemplate(String id) {
45
* Creates a deep copy of this template.
47
* @return A deep copy of this template.
50
public Object clone() {
51
// This method can't be abstract as compilers don't like concrete
52
// subclassses calling super.clone() on an abstract super.
55
} catch (CloneNotSupportedException e) {
56
throw new InternalError(
57
"CodeTemplate implementation not Cloneable: " +
58
getClass().getName());
65
* Compares the <code>StaticCodeTemplate</code> to another.
67
* @param o Another <code>StaticCodeTemplate</code> object.
68
* @return A negative integer, zero, or a positive integer as this
69
* object is less than, equal-to, or greater than the passed-in
71
* @throws ClassCastException If <code>o</code> is
72
* not an instance of <code>CodeTemplate</code>.
74
public int compareTo(CodeTemplate o) {
78
return getID().compareTo(o.getID());
83
* Overridden to return "<code>true</code>" iff
84
* {@link #compareTo(CodeTemplate)} returns <code>0</code>.
86
* @return Whether this code template is equal to another.
89
public boolean equals(Object obj) {
90
if (obj instanceof CodeTemplate) {
91
return compareTo(((CodeTemplate)obj))==0;
98
* Returns the ID of this code template.
100
* @return The template's ID.
101
* @see #setID(String)
103
public String getID() {
109
* Returns the hash code for this template.
111
* @return The hash code for this template.
114
public int hashCode() {
115
return id.hashCode();
120
* Sets the ID for this template.
122
* @param id The ID for this template.
123
* @throws IllegalArgumentException If <code>id</code> is <code>null</code>.
126
public void setID(String id) {
128
throw new IllegalArgumentException("id cannot be null");
b'\\ No newline at end of file'