Source Code Cross Referenced for TupleT.java in  » Parser » Rats-Parser-Generators » xtc » type » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » Rats Parser Generators » xtc.type 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * xtc - The eXTensible Compiler
003:         * Copyright (C) 2007 Robert Grimm
004:         *
005:         * This program is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU General Public License
007:         * version 2 as published by the Free Software Foundation.
008:         *
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software
016:         * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017:         * USA.
018:         */
019:        package xtc.type;
020:
021:        import java.io.IOException;
022:
023:        import java.util.ArrayList;
024:        import java.util.Iterator;
025:        import java.util.List;
026:
027:        import xtc.util.Utilities;
028:
029:        /**
030:         * A tuple type.  Tuples may be either anonymous, without a name, or
031:         * named.  For named tuples, this class provides accessors to the full
032:         * name and the simple name, which is the full name without any
033:         * qualifier.
034:         *
035:         * @author Robert Grimm
036:         * @version $Revision: 1.7 $
037:         */
038:        public class TupleT extends DerivedT {
039:
040:            /** The qualified name. */
041:            final private String qname;
042:
043:            /** The simple name. */
044:            final private String sname;
045:
046:            /** The element types. */
047:            private List<Type> types;
048:
049:            /** Create a new incomplete and anonymous tuple type. */
050:            public TupleT() {
051:                this (null, null, null);
052:            }
053:
054:            /**
055:             * Create a new anonymous tuple type.
056:             *
057:             * @param types The types.
058:             */
059:            public TupleT(List<Type> types) {
060:                this (null, null, types);
061:            }
062:
063:            /**
064:             * Create a new incomplete tuple type.
065:             *
066:             * @param name The name.
067:             */
068:            public TupleT(String name) {
069:                this (null, name, null);
070:            }
071:
072:            /**
073:             * Create a new tuple type.
074:             *
075:             * @param name The name.
076:             * @param type The only element type.
077:             */
078:            public TupleT(String name, Type type) {
079:                this (null, name, new ArrayList<Type>(1));
080:                types.add(type);
081:            }
082:
083:            /**
084:             * Create a new tuple type.
085:             *
086:             * @param name The name.
087:             * @param types The element types.
088:             */
089:            public TupleT(String name, List<Type> types) {
090:                this (null, name, types);
091:            }
092:
093:            /**
094:             * Create a new tuple type.
095:             *
096:             * @param template The type whose annotations to copy.
097:             * @param name The name.
098:             * @param types The element types.
099:             */
100:            public TupleT(Type template, String name, List<Type> types) {
101:                super (template);
102:                this .qname = name;
103:                this .sname = (null == name) ? null : Utilities.unqualify(name);
104:                this .types = types;
105:            }
106:
107:            public Type seal() {
108:                if (!isSealed()) {
109:                    super .seal();
110:                    types = Type.seal(types);
111:                }
112:                return this ;
113:            }
114:
115:            public TupleT copy() {
116:                return new TupleT(this , qname, copy(types));
117:            }
118:
119:            public Type.Tag tag() {
120:                return Type.Tag.TUPLE;
121:            }
122:
123:            public boolean isTuple() {
124:                return true;
125:            }
126:
127:            public TupleT toTuple() {
128:                return this ;
129:            }
130:
131:            /**
132:             * Determine whether this tuple has a name.
133:             *
134:             * @return <code>true</code> if this tuple has a name.
135:             */
136:            public boolean hasName() {
137:                return null != qname;
138:            }
139:
140:            /**
141:             * Determine whether this tuple has the specified name.
142:             *
143:             * @param name The name.
144:             * @return <code>true</code> if this tuple has the name.
145:             */
146:            public boolean hasName(String name) {
147:                return name.equals(this .qname);
148:            }
149:
150:            /**
151:             * Determine whether this tuple has the specified simple name.
152:             *
153:             * @param name The simple name.
154:             * @return <code>true</code> if this tuple has the simple name.
155:             */
156:            public boolean hasSimpleName(String name) {
157:                return name.equals(this .sname);
158:            }
159:
160:            /**
161:             * Get this tuple's name.
162:             *
163:             * @return The name or <code>null</code> if this tuple is anonymous.
164:             */
165:            public String getName() {
166:                return qname;
167:            }
168:
169:            /**
170:             * Get this tuple's simple name.
171:             *
172:             * @return The simple name or <code>null</code> if this tuple is
173:             *   anonymous.
174:             */
175:            public String getSimpleName() {
176:                return sname;
177:            }
178:
179:            /**
180:             * Get the element types.
181:             *
182:             * @return The element types.
183:             */
184:            public List<Type> getTypes() {
185:                return types;
186:            }
187:
188:            /**
189:             * Set the element types.
190:             *
191:             * @param types The new element types.
192:             */
193:            public void setTypes(List<Type> types) {
194:                checkNotSealed();
195:                this .types = types;
196:            }
197:
198:            public int hashCode() {
199:                int hash = 0;
200:                if (null != qname)
201:                    hash = qname.hashCode();
202:                if (null != types)
203:                    hash = 7 * hash + types.hashCode();
204:                return hash;
205:            }
206:
207:            public boolean equals(Object o) {
208:                if (!(o instanceof  Type))
209:                    return false;
210:                Type t = resolve(o);
211:
212:                if (this  == t)
213:                    return true;
214:                if (!t.isTuple())
215:                    return false;
216:                TupleT other = t.toTuple();
217:
218:                if (null == qname) {
219:                    if (null != other.qname)
220:                        return false;
221:                } else {
222:                    if (!qname.equals(other.qname))
223:                        return false;
224:                }
225:                return null == types ? null == other.types : types
226:                        .equals(other.types);
227:            }
228:
229:            public void write(Appendable out) throws IOException {
230:                if (null == qname) {
231:                    out.append("<anonymous>");
232:                } else {
233:                    out.append(qname);
234:                }
235:                out.append('(');
236:                if (null == types) {
237:                    out.append("...");
238:                } else {
239:                    for (Iterator<Type> iter = types.iterator(); iter.hasNext();) {
240:                        iter.next().write(out);
241:                        if (iter.hasNext())
242:                            out.append(", ");
243:                    }
244:                }
245:                out.append(')');
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.