1 /*
2 * ModeShape (http://www.modeshape.org)
3 * See the COPYRIGHT.txt file distributed with this work for information
4 * regarding copyright ownership. Some portions may be licensed
5 * to Red Hat, Inc. under one or more contributor license agreements.
6 * See the AUTHORS.txt file in the distribution for a full listing of
7 * individual contributors.
8 *
9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape
10 * is licensed to you under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * ModeShape is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this software; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23 */
24 package org.modeshape.graph.query.model;
25
26 import java.io.Serializable;
27 import net.jcip.annotations.Immutable;
28 import org.modeshape.common.util.CheckArg;
29
30 /**
31 * A representation of a qualified or expanded name.
32 */
33 @Immutable
34 public class SelectorName implements Readable, Serializable {
35 private static final long serialVersionUID = 1L;
36
37 private final String name;
38
39 public SelectorName( String name ) {
40 CheckArg.isNotEmpty(name, "name");
41 this.name = name;
42 }
43
44 /**
45 * The raw name of the selector.
46 *
47 * @return the raw name; never null and never empty
48 */
49 public String getName() {
50 return name;
51 }
52
53 /**
54 * {@inheritDoc}
55 *
56 * @see org.modeshape.graph.query.model.Readable#getString()
57 */
58 public String getString() {
59 return name;
60 }
61
62 /**
63 * {@inheritDoc}
64 *
65 * @see java.lang.Object#toString()
66 */
67 @Override
68 public String toString() {
69 return name;
70 }
71
72 /**
73 * {@inheritDoc}
74 *
75 * @see java.lang.Object#hashCode()
76 */
77 @Override
78 public int hashCode() {
79 return this.name.hashCode();
80 }
81
82 /**
83 * {@inheritDoc}
84 *
85 * @see java.lang.Object#equals(java.lang.Object)
86 */
87 @Override
88 public boolean equals( Object obj ) {
89 if (obj == this) return true;
90 if (obj instanceof SelectorName) {
91 SelectorName that = (SelectorName)obj;
92 return this.name.equals(that.getName());
93 }
94 return false;
95 }
96 }