Source Code Cross Referenced for LiteralImpl.java in  » RSS-RDF » sesame » org » openrdf » model » impl » 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 » RSS RDF » sesame » org.openrdf.model.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.model.impl;
007:
008:        import java.math.BigDecimal;
009:        import java.math.BigInteger;
010:
011:        import javax.xml.datatype.XMLGregorianCalendar;
012:
013:        import org.openrdf.model.Literal;
014:        import org.openrdf.model.URI;
015:        import org.openrdf.model.datatypes.XMLDatatypeUtil;
016:
017:        /**
018:         * An implementation of the {@link Literal} interface.
019:         * 
020:         * @author Arjohn Kampman
021:         * @author David Huynh
022:         */
023:        public class LiteralImpl implements  Literal {
024:
025:            private static final long serialVersionUID = -1649571784782592271L;
026:
027:            /*-----------*
028:             * Variables *
029:             *-----------*/
030:
031:            /**
032:             * The literal's label.
033:             */
034:            private final String label;
035:
036:            /**
037:             * The literal's language tag (null if not applicable).
038:             */
039:            private final String language;
040:
041:            /**
042:             * The literal's datatype (null if not applicable).
043:             */
044:            private final URI datatype;
045:
046:            /*--------------*
047:             * Constructors *
048:             *--------------*/
049:
050:            /**
051:             * Creates a new plain literal with the supplied label.
052:             * 
053:             * @param label
054:             *        The label for the literal, must not be <tt>null</tt>.
055:             */
056:            public LiteralImpl(String label) {
057:                this (label, null, null);
058:            }
059:
060:            /**
061:             * Creates a new plain literal with the supplied label and language tag.
062:             * 
063:             * @param label
064:             *        The label for the literal, must not be <tt>null</tt>.
065:             * @param language
066:             *        The language tag for the literal.
067:             */
068:            public LiteralImpl(String label, String language) {
069:                this (label, language, null);
070:            }
071:
072:            /**
073:             * Creates a new datyped literal with the supplied label and datatype.
074:             * 
075:             * @param label
076:             *        The label for the literal, must not be <tt>null</tt>.
077:             * @param datatype
078:             *        The datatype for the literal.
079:             */
080:            public LiteralImpl(String label, URI datatype) {
081:                this (label, null, datatype);
082:            }
083:
084:            /**
085:             * Creates a new Literal object, initializing the variables with the supplied
086:             * parameters.
087:             */
088:            private LiteralImpl(String label, String language, URI datatype) {
089:                assert label != null;
090:
091:                this .label = label;
092:                this .language = (language == null) ? null : language
093:                        .toLowerCase();
094:                this .datatype = datatype;
095:            }
096:
097:            /*---------*
098:             * Methods *
099:             *---------*/
100:
101:            public String getLabel() {
102:                return label;
103:            }
104:
105:            public String getLanguage() {
106:                return language;
107:            }
108:
109:            public URI getDatatype() {
110:                return datatype;
111:            }
112:
113:            // Overrides Object.equals(Object), implements Literal.equals(Object)
114:            @Override
115:            public boolean equals(Object o) {
116:                if (this  == o) {
117:                    return true;
118:                }
119:
120:                if (o instanceof  Literal) {
121:                    Literal other = (Literal) o;
122:
123:                    // Compare labels
124:                    if (!label.equals(other.getLabel())) {
125:                        return false;
126:                    }
127:
128:                    // Compare datatypes
129:                    if (datatype == null) {
130:                        if (other.getDatatype() != null) {
131:                            return false;
132:                        }
133:                    } else {
134:                        if (!datatype.equals(other.getDatatype())) {
135:                            return false;
136:                        }
137:                    }
138:
139:                    // Compare language tags
140:                    if (language == null) {
141:                        if (other.getLanguage() != null) {
142:                            return false;
143:                        }
144:                    } else {
145:                        if (!language.equals(other.getLanguage())) {
146:                            return false;
147:                        }
148:                    }
149:
150:                    return true;
151:                }
152:
153:                return false;
154:            }
155:
156:            // overrides Object.hashCode(), implements hashCode()
157:            @Override
158:            public int hashCode() {
159:                return label.hashCode();
160:            }
161:
162:            /**
163:             * Returns the label of the literal.
164:             */
165:            @Override
166:            public String toString() {
167:                StringBuilder sb = new StringBuilder(label.length() * 2);
168:
169:                sb.append('"');
170:                sb.append(label);
171:                sb.append('"');
172:
173:                if (language != null) {
174:                    sb.append('@');
175:                    sb.append(language);
176:                }
177:
178:                if (datatype != null) {
179:                    sb.append("^^");
180:                    sb.append(datatype.toString());
181:                }
182:
183:                return sb.toString();
184:            }
185:
186:            public String stringValue() {
187:                return label;
188:            }
189:
190:            public boolean booleanValue() {
191:                return XMLDatatypeUtil.parseBoolean(getLabel());
192:            }
193:
194:            public byte byteValue() {
195:                return XMLDatatypeUtil.parseByte(getLabel());
196:            }
197:
198:            public short shortValue() {
199:                return XMLDatatypeUtil.parseShort(getLabel());
200:            }
201:
202:            public int intValue() {
203:                return XMLDatatypeUtil.parseInt(getLabel());
204:            }
205:
206:            public long longValue() {
207:                return XMLDatatypeUtil.parseLong(getLabel());
208:            }
209:
210:            public float floatValue() {
211:                return XMLDatatypeUtil.parseFloat(getLabel());
212:            }
213:
214:            public double doubleValue() {
215:                return XMLDatatypeUtil.parseDouble(getLabel());
216:            }
217:
218:            public BigInteger integerValue() {
219:                return XMLDatatypeUtil.parseInteger(getLabel());
220:            }
221:
222:            public BigDecimal decimalValue() {
223:                return XMLDatatypeUtil.parseDecimal(getLabel());
224:            }
225:
226:            public XMLGregorianCalendar calendarValue() {
227:                return XMLDatatypeUtil.parseCalendar(getLabel());
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.