001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: Node_Variable.java,v 1.15 2008/01/02 12:06:55 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph;
008:
009: /**
010: "variable" nodes; these are outside the RDF2003 specification, but are
011: used internally for "placeholder" nodes where blank nodes would be
012: wrong, most specifically in Query.
013: @author kers
014: */
015:
016: public class Node_Variable extends Node_Fluid {
017: /**
018: Initialise this Node_Variable with a name object (which should be a
019: VariableName object).
020: */
021: protected Node_Variable(Object name) {
022: super (name);
023: }
024:
025: /**
026: Initialise this Node_Variable from a string <code>name</code>,
027: which becomes wrapped in a VariableName.
028: */
029: public Node_Variable(String name) {
030: super (new VariableName(name));
031: }
032:
033: public String getName() {
034: return ((VariableName) label).name;
035: }
036:
037: public Object visitWith(NodeVisitor v) {
038: return v.visitVariable(this , getName());
039: }
040:
041: public boolean isVariable() {
042: return true;
043: }
044:
045: public String toString() {
046: return label.toString();
047: }
048:
049: public boolean equals(Object other) {
050: return other instanceof Node_Variable
051: && label.equals(((Node_Variable) other).label);
052: }
053:
054: public static Object variable(String name) {
055: return new VariableName(name);
056: }
057:
058: public static class VariableName {
059: private String name;
060:
061: public VariableName(String name) {
062: this .name = name;
063: }
064:
065: public int hashCode() {
066: return name.hashCode();
067: }
068:
069: public boolean equals(Object other) {
070: return other instanceof VariableName
071: && name.equals(((VariableName) other).name);
072: }
073:
074: public String toString() {
075: return "?" + name;
076: }
077: }
078: }
079:
080: /*
081: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
082: All rights reserved.
083:
084: Redistribution and use in source and binary forms, with or without
085: modification, are permitted provided that the following conditions
086: are met:
087:
088: 1. Redistributions of source code must retain the above copyright
089: notice, this list of conditions and the following disclaimer.
090:
091: 2. Redistributions in binary form must reproduce the above copyright
092: notice, this list of conditions and the following disclaimer in the
093: documentation and/or other materials provided with the distribution.
094:
095: 3. The name of the author may not be used to endorse or promote products
096: derived from this software without specific prior written permission.
097:
098: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
099: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
100: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
101: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
102: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
103: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
104: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
105: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
106: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
107: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108: */
|