001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.query.algebra;
007:
008: import org.openrdf.model.Value;
009:
010: /**
011: * A variable that can contain a Value.
012: */
013: public class Var extends QueryModelNodeBase implements ValueExpr {
014:
015: /*-----------*
016: * Variables *
017: *-----------*/
018:
019: private String name;
020:
021: private Value value;
022:
023: private boolean anonymous = false;
024:
025: /*--------------*
026: * Constructors *
027: *--------------*/
028:
029: public Var() {
030: }
031:
032: public Var(String name) {
033: setName(name);
034: }
035:
036: public Var(String name, Value value) {
037: this (name);
038: setValue(value);
039: }
040:
041: /*---------*
042: * Methods *
043: *---------*/
044:
045: public void setAnonymous(boolean anonymous) {
046: this .anonymous = anonymous;
047: }
048:
049: public boolean isAnonymous() {
050: return anonymous;
051: }
052:
053: public String getName() {
054: return name;
055: }
056:
057: public void setName(String name) {
058: this .name = name;
059: }
060:
061: public void setValue(Value value) {
062: this .value = value;
063: }
064:
065: public boolean hasValue() {
066: return value != null;
067: }
068:
069: public Value getValue() {
070: return value;
071: }
072:
073: public <X extends Exception> void visit(QueryModelVisitor<X> visitor)
074: throws X {
075: visitor.meet(this );
076: }
077:
078: @Override
079: public boolean equals(Object other) {
080: if (other instanceof Var) {
081: return name.equals(((Var) other).name);
082: }
083:
084: return false;
085: }
086:
087: @Override
088: public int hashCode() {
089: return name.hashCode();
090: }
091:
092: @Override
093: public String getSignature() {
094: StringBuilder sb = new StringBuilder(64);
095:
096: sb.append(super .getSignature());
097:
098: sb.append(" (name=").append(name);
099:
100: if (value != null) {
101: sb.append(", value=").append(value.toString());
102: }
103:
104: if (anonymous) {
105: sb.append(", anonymous");
106: }
107:
108: sb.append(")");
109:
110: return sb.toString();
111: }
112:
113: @Override
114: public Var clone() {
115: return (Var) super.clone();
116: }
117: }
|