01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * wharley@bea.com - initial API and implementation
10: *
11: *******************************************************************************/package org.eclipse.jdt.internal.compiler.apt.model;
12:
13: import javax.lang.model.element.Name;
14:
15: /**
16: * A String-based implementation of the type used to return strings in javax.lang.model.
17: */
18: public class NameImpl implements Name {
19:
20: private final String _name;
21:
22: /** nullary constructor is prohibited */
23: @SuppressWarnings("unused")
24: private NameImpl() {
25: _name = null;
26: }
27:
28: public NameImpl(CharSequence cs) {
29: _name = cs.toString();
30: }
31:
32: public NameImpl(char[] chars) {
33: _name = String.valueOf(chars);
34: }
35:
36: /* (non-Javadoc)
37: * @see javax.lang.model.element.Name#contentEquals(java.lang.CharSequence)
38: */
39: @Override
40: public boolean contentEquals(CharSequence cs) {
41: return _name.equals(cs.toString());
42: }
43:
44: /* (non-Javadoc)
45: * @see java.lang.CharSequence#charAt(int)
46: */
47: @Override
48: public char charAt(int index) {
49: return _name.charAt(index);
50: }
51:
52: /* (non-Javadoc)
53: * @see java.lang.CharSequence#length()
54: */
55: @Override
56: public int length() {
57: return _name.length();
58: }
59:
60: /* (non-Javadoc)
61: * @see java.lang.CharSequence#subSequence(int, int)
62: */
63: @Override
64: public CharSequence subSequence(int start, int end) {
65: return _name.subSequence(start, end);
66: }
67:
68: @Override
69: public String toString() {
70: return _name;
71: }
72:
73: @Override
74: public int hashCode() {
75: return _name.hashCode();
76: }
77:
78: @Override
79: public boolean equals(Object obj) {
80: if (this == obj)
81: return true;
82: if (obj == null)
83: return false;
84: if (getClass() != obj.getClass())
85: return false;
86: final NameImpl other = (NameImpl) obj;
87: return _name.equals(other._name);
88: }
89:
90: }
|