001: /*
002: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: Domain.java,v 1.15 2008/01/02 12:07:57 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.query;
008:
009: import com.hp.hpl.jena.graph.*;
010:
011: import java.util.*;
012:
013: /**
014: A Domain is an answer to a Binding query. It satisfies the List
015: interface so that casual users don't have to worry about its special
016: features - for them, it is immutable (they only ever get to see Domains
017: that have emerged from the query process).
018:
019: @author kers
020: */
021:
022: public final class Domain extends AbstractList implements IndexValues {
023: /**
024: The array holding the bound values.
025: */
026: private final Node[] value;
027:
028: /**
029: Initialise a Domain with a copy of a Node value array.
030: */
031: public Domain(Node[] value) {
032: Node[] result = new Node[value.length];
033: for (int i = 0; i < value.length; i += 1)
034: result[i] = value[i];
035: this .value = result;
036: }
037:
038: /**
039: Initialise this Domain with <code>size</code> null slots.
040: */
041: public Domain(int size) {
042: this .value = new Node[size];
043: }
044:
045: public int size() {
046: return value.length;
047: }
048:
049: public Object get(int i) {
050: return value[i];
051: }
052:
053: public void setElement(int i, Node x) {
054: value[i] = x;
055: }
056:
057: public Node getElement(int i) {
058: return value[i];
059: }
060:
061: public Domain copy() {
062: return new Domain(this .value);
063: }
064:
065: public boolean equals(Object x) {
066: return x instanceof Domain
067: && Arrays.equals(this .value, ((Domain) x).value)
068: || super .equals(x);
069: }
070:
071: public String toString() {
072: StringBuffer b = new StringBuffer(200);
073: b.append("<domain");
074: for (int i = 0; i < value.length; i += 1)
075: b.append(" ").append(i).append(":").append(value[i]);
076: b.append(">");
077: return b.toString();
078: }
079: }
080:
081: /*
082: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
083: All rights reserved.
084:
085: Redistribution and use in source and binary forms, with or without
086: modification, are permitted provided that the following conditions
087: are met:
088:
089: 1. Redistributions of source code must retain the above copyright
090: notice, this list of conditions and the following disclaimer.
091:
092: 2. Redistributions in binary form must reproduce the above copyright
093: notice, this list of conditions and the following disclaimer in the
094: documentation and/or other materials provided with the distribution.
095:
096: 3. The name of the author may not be used to endorse or promote products
097: derived from this software without specific prior written permission.
098:
099: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
100: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
101: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
102: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
103: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
105: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
108: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109: */
|