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.query.impl;
007:
008: import java.util.Collections;
009: import java.util.Iterator;
010: import java.util.NoSuchElementException;
011: import java.util.Set;
012:
013: import org.openrdf.model.Value;
014: import org.openrdf.query.Binding;
015: import org.openrdf.query.BindingSet;
016:
017: /**
018: * An immutable empty BindingSet.
019: *
020: * @author Arjohn Kampman
021: */
022: public class EmptyBindingSet implements BindingSet {
023:
024: /*-----------*
025: * Constants *
026: *-----------*/
027:
028: private static final EmptyBindingSet singleton = new EmptyBindingSet();
029:
030: public static BindingSet getInstance() {
031: return singleton;
032: }
033:
034: /*-----------*
035: * Variables *
036: *-----------*/
037:
038: private EmptyBindingIterator iter = new EmptyBindingIterator();
039:
040: /*---------*
041: * Methods *
042: *---------*/
043:
044: public Iterator<Binding> iterator() {
045: return iter;
046: }
047:
048: public Set<String> getBindingNames() {
049: return Collections.emptySet();
050: }
051:
052: public Binding getBinding(String bindingName) {
053: return null;
054: }
055:
056: public boolean hasBinding(String bindingName) {
057: return false;
058: }
059:
060: public Value getValue(String bindingName) {
061: return null;
062: }
063:
064: public int size() {
065: return 0;
066: }
067:
068: @Override
069: public boolean equals(Object o) {
070: if (o instanceof BindingSet) {
071: return ((BindingSet) o).size() == 0;
072: }
073:
074: return false;
075: }
076:
077: @Override
078: public int hashCode() {
079: return 0;
080: }
081:
082: @Override
083: public String toString() {
084: return "[]";
085: }
086:
087: /*----------------------------------*
088: * Inner class EmptyBindingIterator *
089: *----------------------------------*/
090:
091: private static class EmptyBindingIterator implements
092: Iterator<Binding> {
093:
094: public boolean hasNext() {
095: return false;
096: }
097:
098: public Binding next() {
099: throw new NoSuchElementException();
100: }
101:
102: public void remove() {
103: throw new IllegalStateException();
104: }
105: }
106: }
|