Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Name.java

00001 package edu.ksu.cis.bandera.jjjc.symboltable;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999, 2000   Robby (robby@cis.ksu.edu)              *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import edu.ksu.cis.bandera.jjjc.util.Util;
00036 import edu.ksu.cis.bandera.jjjc.exception.*;
00037 
00038 public class Name implements Comparable {
00039     public static String separator = ".";
00040     private String[] identifiers;
00041 /**
00042  * 
00043  * @param identifiers java.lang.String[]
00044  */
00045 protected Name(String[] identifiers) {
00046     this(identifiers, 0, identifiers.length - 1);
00047 }
00048 /**
00049  * 
00050  * @param identifiers java.lang.String[]
00051  * @param start int
00052  * @param end int
00053  */
00054 protected Name(String[] identifiers, int from, int to) {
00055     if ((identifiers == null) || (from > to)) {
00056         this.identifiers = new String[1];
00057         this.identifiers[0] = "";
00058     } else {
00059         if (from < 0) from = 0;
00060         if (to >= identifiers.length) to = identifiers.length - 1;
00061 
00062         this.identifiers = new String[to - from + 1];
00063 
00064         for (int i = 0; i < this.identifiers.length; i++) {
00065             this.identifiers[i] = identifiers[i + from];
00066         }
00067     }
00068 }
00069 /**
00070  * 
00071  * @param name1 edu.ksu.cis.bandera.jjjc.symboltable.Name
00072  * @param name2 edu.ksu.cis.bandera.jjjc.symboltable.Name
00073  */
00074 public Name(Name name1, Name name2) {
00075     int length1 = (name1 != null) ? name1.identifiers.length : 0;
00076     int length2 = (name2 != null) ? name2.identifiers.length : 0;
00077 
00078     identifiers = new String[length1 + length2];
00079 
00080     for (int i = 0; i < length1; i++) {
00081         this.identifiers[i] = name1.identifiers[i];
00082     }
00083     
00084     for (int i = 0; i < length2; i++) {
00085         this.identifiers[i + length1] = name2.identifiers[i];
00086     }
00087 }
00088 /**
00089  * 
00090  * @param name1 edu.ksu.cis.bandera.jjjc.symboltable.Name
00091  * @param s java.lang.String
00092  */
00093 public Name(Name name1, String name2) {
00094     this(name1, new Name(name2));
00095 }
00096 /**
00097  * 
00098  * @param s java.lang.String
00099  */
00100 public Name(String name) {
00101     identifiers = Util.splitString(name.trim(), separator + "\t []");
00102 }
00103 /**
00104  * 
00105  * @return int
00106  * @param object java.lang.Object
00107  */
00108 public int compareTo(Object object) {
00109     return toString().compareTo(object.toString());
00110 }
00111 /**
00112  * 
00113  * @return boolean
00114  * @param otherName edu.ksu.cis.bandera.jjjc.symboltable.Name
00115  */
00116 public boolean equals(Object obj) {
00117     if (obj == null) return false;
00118     else if (!(obj instanceof Name)) return false;
00119     else return this.toString().equals(obj.toString());
00120 }
00121 /**
00122  * 
00123  * @return java.lang.String
00124  */
00125 public String getFirstIdentifier() {
00126     return identifiers[0];
00127 }
00128 /**
00129  * 
00130  * @return java.lang.String
00131  */
00132 public String getLastIdentifier() {
00133     if (identifiers.length == 0)
00134         return "";
00135     else
00136         return identifiers[identifiers.length - 1];
00137 }
00138 /**
00139  * 
00140  * @return edu.ksu.cis.bandera.jjjc.symboltable.Name
00141  */
00142 public Name getSubName() {
00143     return new Name(identifiers, 1, identifiers.length - 1);
00144 }
00145 /**
00146  * 
00147  * @return edu.ksu.cis.bandera.jjjc.symboltable.Name
00148  */
00149 public Name getSuperName() {
00150     return new Name(identifiers, 0, identifiers.length - 2);
00151 }
00152 /**
00153  * 
00154  * @return int
00155  */
00156 public int hashCode() {
00157     return toString().hashCode();
00158 }
00159 /**
00160  * 
00161  * @return boolean
00162  */
00163 public boolean isSimpleName() {
00164     return (identifiers.length == 1);
00165 }
00166 /**
00167  * 
00168  * @return java.lang.String
00169  */
00170 public String toString() {
00171     return Util.combineStrings(identifiers, separator);
00172 }
00173 }

Generated at Thu Feb 7 06:50:34 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001