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.sail.memory.model;
007:
008: import org.openrdf.model.URI;
009: import org.openrdf.model.vocabulary.XMLSchema;
010:
011: /**
012: * An extension of MemLiteral that stores a numeric value to avoid parsing.
013: *
014: * @author David Huynh
015: * @author Arjohn Kampman
016: */
017: public class NumericMemLiteral extends MemLiteral {
018:
019: /*-----------*
020: * Variables *
021: *-----------*/
022:
023: /**
024: *
025: */
026: private static final long serialVersionUID = -4077489124945558638L;
027:
028: private Number number;
029:
030: /*--------------*
031: * Constructors *
032: *--------------*/
033:
034: public NumericMemLiteral(Object creator, String label,
035: Number number, URI datatype) {
036: super (creator, label, datatype);
037: this .number = number;
038: }
039:
040: public NumericMemLiteral(Object creator, Number number, URI datatype) {
041: this (creator, number.toString(), number, datatype);
042: }
043:
044: public NumericMemLiteral(Object creator, byte number) {
045: this (creator, number, XMLSchema.BYTE);
046: }
047:
048: public NumericMemLiteral(Object creator, short number) {
049: this (creator, number, XMLSchema.SHORT);
050: }
051:
052: public NumericMemLiteral(Object creator, int number) {
053: this (creator, number, XMLSchema.INT);
054: }
055:
056: public NumericMemLiteral(Object creator, long n) {
057: this (creator, n, XMLSchema.LONG);
058: }
059:
060: public NumericMemLiteral(Object creator, float n) {
061: this (creator, n, XMLSchema.FLOAT);
062: }
063:
064: public NumericMemLiteral(Object creator, double n) {
065: this (creator, n, XMLSchema.DOUBLE);
066: }
067:
068: /*---------*
069: * Methods *
070: *---------*/
071:
072: @Override
073: public byte byteValue() {
074: return number.byteValue();
075: }
076:
077: @Override
078: public short shortValue() {
079: return number.shortValue();
080: }
081:
082: @Override
083: public int intValue() {
084: return number.intValue();
085: }
086:
087: @Override
088: public long longValue() {
089: return number.longValue();
090: }
091:
092: @Override
093: public float floatValue() {
094: return number.floatValue();
095: }
096:
097: @Override
098: public double doubleValue() {
099: return number.doubleValue();
100: }
101: }
|