KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > compiler > apt > model > NameImpl


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 BEA Systems, Inc.
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  * wharley@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.compiler.apt.model;
14
15 import javax.lang.model.element.Name;
16
17 /**
18  * A String-based implementation of the type used to return strings in javax.lang.model.
19  */

20 public class NameImpl implements Name {
21     
22     private final String JavaDoc _name;
23     
24     /** nullary constructor is prohibited */
25     @SuppressWarnings JavaDoc("unused")
26     private NameImpl()
27     {
28         _name = null;
29     }
30     
31     public NameImpl(CharSequence JavaDoc cs)
32     {
33         _name = cs.toString();
34     }
35     
36     public NameImpl(char[] chars)
37     {
38         _name = String.valueOf(chars);
39     }
40
41     /* (non-Javadoc)
42      * @see javax.lang.model.element.Name#contentEquals(java.lang.CharSequence)
43      */

44     @Override JavaDoc
45     public boolean contentEquals(CharSequence JavaDoc cs) {
46         return _name.equals(cs.toString());
47     }
48
49     /* (non-Javadoc)
50      * @see java.lang.CharSequence#charAt(int)
51      */

52     @Override JavaDoc
53     public char charAt(int index) {
54         return _name.charAt(index);
55     }
56
57     /* (non-Javadoc)
58      * @see java.lang.CharSequence#length()
59      */

60     @Override JavaDoc
61     public int length() {
62         return _name.length();
63     }
64
65     /* (non-Javadoc)
66      * @see java.lang.CharSequence#subSequence(int, int)
67      */

68     @Override JavaDoc
69     public CharSequence JavaDoc subSequence(int start, int end) {
70         return _name.subSequence(start, end);
71     }
72
73     @Override JavaDoc
74     public String JavaDoc toString() {
75         return _name;
76     }
77
78     @Override JavaDoc
79     public int hashCode() {
80         return _name.hashCode();
81     }
82
83     @Override JavaDoc
84     public boolean equals(Object JavaDoc obj) {
85         if (this == obj)
86             return true;
87         if (obj == null)
88             return false;
89         if (getClass() != obj.getClass())
90             return false;
91         final NameImpl other = (NameImpl) obj;
92         return _name.equals(other._name);
93     }
94
95 }
96
Popular Tags