001 /*
002 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.lang.model.element;
027
028 /**
029 * An immutable sequence of characters. When created by the same
030 * implementation, objects implementing this interface must obey the
031 * general {@linkplain Object#equals equals contract} when compared
032 * with each other. Therefore, {@code Name} objects from the same
033 * implementation are usable in collections while {@code Name}s from
034 * different implementations may not work properly in collections.
035 *
036 * <p>An empty {@code Name} has a length of zero.
037 *
038 * <p>In the context of {@linkplain
039 * javax.annotation.processing.ProcessingEnvironment annotation
040 * processing}, the guarantees for "the same" implementation must
041 * include contexts where the {@linkplain javax.annotation.processing
042 * API mediated} side effects of {@linkplain
043 * javax.annotation.processing.Processor processors} could be visible
044 * to each other, including successive annotation processing
045 * {@linkplain javax.annotation.processing.RoundEnvironment rounds}.
046 *
047 * @author Joseph D. Darcy
048 * @author Scott Seligman
049 * @author Peter von der Ahé
050 * @see javax.lang.model.util.Elements#getName
051 * @since 1.6
052 */
053 public interface Name extends CharSequence {
054 /**
055 * Returns {@code true} if the argument represents the same
056 * name as {@code this}, and {@code false} otherwise.
057 *
058 * <p>Note that the identity of a {@code Name} is a function both
059 * of its content in terms of a sequence of characters as well as
060 * the implementation which created it.
061 *
062 * @param obj the object to be compared with this element
063 * @return {@code true} if the specified object represents the same
064 * name as this
065 * @see Element#equals
066 */
067 boolean equals(Object obj);
068
069 /**
070 * Obeys the general contract of {@link Object#hashCode Object.hashCode}.
071 *
072 * @see #equals
073 */
074 int hashCode();
075
076 /**
077 * Compares this name to the specified {@code CharSequence}. The result
078 * is {@code true} if and only if this name represents the same sequence
079 * of {@code char} values as the specified sequence.
080 *
081 * @return {@code true} if this name represents the same sequence
082 * of {@code char} values as the specified sequence, {@code false}
083 * otherwise
084 *
085 * @param cs The sequence to compare this name against
086 * @see String#contentEquals(CharSequence)
087 */
088 boolean contentEquals(CharSequence cs);
089 }