~ubuntu-branches/ubuntu/trusty/drmips/trusty-backports

« back to all changes in this revision

Viewing changes to src/pc/DrMIPS/src/org/fife/ui/rsyntaxtextarea/templates/AbstractCodeTemplate.java

  • Committer: Package Import Robot
  • Author(s): Bruno Nova
  • Date: 2014-09-27 12:24:17 UTC
  • Revision ID: package-import@ubuntu.com-20140927122417-2gadkwt9k0u7j4zu
Tags: upstream-1.2.3
Import upstream version 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * 12/01/2008
 
3
 *
 
4
 * AbstractCodeTemplate.java - Base class for code templates.
 
5
 * 
 
6
 * This library is distributed under a modified BSD license.  See the included
 
7
 * RSyntaxTextArea.License.txt file for details.
 
8
 */
 
9
package org.fife.ui.rsyntaxtextarea.templates;
 
10
 
 
11
 
 
12
/**
 
13
 * A base class to build code templates on top of.
 
14
 *
 
15
 * @author Robert Futrell
 
16
 * @version 1.0
 
17
 */
 
18
public abstract class AbstractCodeTemplate implements CodeTemplate {
 
19
 
 
20
        /**
 
21
         * The ID of this template.
 
22
         */
 
23
        private String id;
 
24
 
 
25
 
 
26
        /**
 
27
         * This no-arg constructor is required for serialization purposes.
 
28
         */
 
29
        public AbstractCodeTemplate() {
 
30
        }
 
31
 
 
32
 
 
33
        /**
 
34
         * Creates a new template.
 
35
         *
 
36
         * @param id The ID for this template.
 
37
         * @throws IllegalArgumentException If <code>id</code> is <code>null</code>.
 
38
         */
 
39
        public AbstractCodeTemplate(String id) {
 
40
                setID(id);
 
41
        }
 
42
 
 
43
 
 
44
        /**
 
45
         * Creates a deep copy of this template.
 
46
         *
 
47
         * @return A deep copy of this template.
 
48
         */
 
49
        @Override
 
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.
 
53
                try {
 
54
                        return super.clone();
 
55
                } catch (CloneNotSupportedException e) {
 
56
                        throw new InternalError(
 
57
                                "CodeTemplate implementation not Cloneable: " +
 
58
                                                        getClass().getName());
 
59
                }
 
60
        }
 
61
 
 
62
 
 
63
 
 
64
        /**
 
65
         * Compares the <code>StaticCodeTemplate</code> to another.
 
66
         *
 
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
 
70
         *         object.
 
71
         * @throws ClassCastException If <code>o</code> is
 
72
         *         not an instance of <code>CodeTemplate</code>.
 
73
         */
 
74
        public int compareTo(CodeTemplate o) {
 
75
                if (o==null) {
 
76
                        return -1;
 
77
                }
 
78
                return getID().compareTo(o.getID());
 
79
        }
 
80
 
 
81
 
 
82
        /**
 
83
         * Overridden to return "<code>true</code>" iff
 
84
         * {@link #compareTo(CodeTemplate)} returns <code>0</code>.
 
85
         *
 
86
         * @return Whether this code template is equal to another.
 
87
         */
 
88
        @Override
 
89
        public boolean equals(Object obj) {
 
90
                if (obj instanceof CodeTemplate) {
 
91
                        return compareTo(((CodeTemplate)obj))==0;
 
92
                }
 
93
                return false;
 
94
        }
 
95
 
 
96
 
 
97
        /**
 
98
         * Returns the ID of this code template.
 
99
         *
 
100
         * @return The template's ID.
 
101
         * @see #setID(String)
 
102
         */
 
103
        public String getID() {
 
104
                return id;
 
105
        }
 
106
 
 
107
 
 
108
        /**
 
109
         * Returns the hash code for this template.
 
110
         *
 
111
         * @return The hash code for this template.
 
112
         */
 
113
        @Override
 
114
        public int hashCode() {
 
115
                return id.hashCode();
 
116
        }
 
117
 
 
118
 
 
119
        /**
 
120
         * Sets the ID for this template.
 
121
         *
 
122
         * @param id The ID for this template.
 
123
         * @throws IllegalArgumentException If <code>id</code> is <code>null</code>.
 
124
         * @see #getID()
 
125
         */
 
126
        public void setID(String id) {
 
127
                if (id==null) {
 
128
                        throw new IllegalArgumentException("id cannot be null");
 
129
                }
 
130
                this.id = id;
 
131
        }
 
132
 
 
133
 
 
134
}
 
 
b'\\ No newline at end of file'