001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.model.impl;
007:
008: import org.openrdf.model.URI;
009: import org.openrdf.model.vocabulary.XMLSchema;
010:
011: /**
012: * An extension of {@link LiteralImpl} that stores a numeric value to avoid
013: * parsing.
014: *
015: * @author David Huynh
016: */
017: public class NumericLiteralImpl extends LiteralImpl {
018:
019: private static final long serialVersionUID = 3004497457768807919L;
020:
021: private final Number number;
022:
023: /**
024: * Creates a literal with the specified value and datatype.
025: */
026: public NumericLiteralImpl(Number number, URI datatype) {
027: super (number.toString(), datatype);
028: this .number = number;
029: }
030:
031: /**
032: * Creates an xsd:byte typed litral with the specified value.
033: */
034: public NumericLiteralImpl(byte number) {
035: this (number, XMLSchema.BYTE);
036: }
037:
038: /**
039: * Creates an xsd:short typed litral with the specified value.
040: */
041: public NumericLiteralImpl(short number) {
042: this (number, XMLSchema.SHORT);
043: }
044:
045: /**
046: * Creates an xsd:int typed litral with the specified value.
047: */
048: public NumericLiteralImpl(int number) {
049: this (number, XMLSchema.INT);
050: }
051:
052: /**
053: * Creates an xsd:long typed litral with the specified value.
054: */
055: public NumericLiteralImpl(long n) {
056: this (n, XMLSchema.LONG);
057: }
058:
059: /**
060: * Creates an xsd:float typed litral with the specified value.
061: */
062: public NumericLiteralImpl(float n) {
063: this (n, XMLSchema.FLOAT);
064: }
065:
066: /**
067: * Creates an xsd:double typed litral with the specified value.
068: */
069: public NumericLiteralImpl(double n) {
070: this (n, XMLSchema.DOUBLE);
071: }
072:
073: @Override
074: public byte byteValue() {
075: return number.byteValue();
076: }
077:
078: @Override
079: public short shortValue() {
080: return number.shortValue();
081: }
082:
083: @Override
084: public int intValue() {
085: return number.intValue();
086: }
087:
088: @Override
089: public long longValue() {
090: return number.longValue();
091: }
092:
093: @Override
094: public float floatValue() {
095: return number.floatValue();
096: }
097:
098: @Override
099: public double doubleValue() {
100: return number.doubleValue();
101: }
102: }
|