01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.model.impl;
07:
08: import org.openrdf.model.vocabulary.XMLSchema;
09:
10: /**
11: * An extension of {@link LiteralImpl} that stores a boolean value to avoid
12: * parsing.
13: *
14: * @author David Huynh
15: * @author Arjohn Kampman
16: */
17: public class BooleanLiteralImpl extends LiteralImpl {
18:
19: /*-----------*
20: * Constants *
21: *-----------*/
22:
23: private static final long serialVersionUID = -3610638093719366795L;
24:
25: public static final BooleanLiteralImpl TRUE = new BooleanLiteralImpl(
26: true);
27:
28: public static final BooleanLiteralImpl FALSE = new BooleanLiteralImpl(
29: false);
30:
31: /*-----------*
32: * Variables *
33: *-----------*/
34:
35: private boolean value;
36:
37: /*--------------*
38: * Constructors *
39: *--------------*/
40:
41: /**
42: * Creates an xsd:boolean typed literal with the specified value.
43: */
44: public BooleanLiteralImpl(boolean value) {
45: super (Boolean.toString(value), XMLSchema.BOOLEAN);
46: this .value = value;
47: }
48:
49: /*---------*
50: * Methods *
51: *---------*/
52:
53: @Override
54: public boolean booleanValue() {
55: return value;
56: }
57:
58: /**
59: * Returns a {@link BooleanLiteralImpl} for the specified value. This method
60: * uses the constants {@link #TRUE} and {@link #FALSE} as result values,
61: * preventing the often unnecessary creation of new
62: * {@link BooleanLiteralImpl} objects.
63: */
64: public static BooleanLiteralImpl valueOf(boolean value) {
65: return value ? TRUE : FALSE;
66: }
67: }
|