📄 rdflist.java
字号:
/*****************************************************************************
* Source code information
* -----------------------
* Original author Ian Dickinson, HP Labs Bristol
* Author email Ian.Dickinson@hp.com
* Package Jena 2
* Web http://sourceforge.net/projects/jena/
* Created 24 Jan 2003
* Filename $RCSfile: RDFList.java,v $
* Revision $Revision: 1.12 $
* Release status @releaseStatus@ $State: Exp $
*
* Last modified on $Date: 2007/01/02 11:48:34 $
* by $Author: andy_seaborne $
*
* (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* (see footer for full conditions)
*****************************************************************************/
// Package
///////////////
package com.hp.hpl.jena.rdf.model;
// Imports
///////////////
import com.hp.hpl.jena.util.iterator.*;
import java.util.*;
/**
* <p>
* Provides a convenience encapsulation for lists formed from chains of RDF
* statements arranged to form a head/tail cons-cell structure. The properties
* that form the links between cells, and from cells to values, are specified by
* a vocabulary interface, so this abstraction is designed to cope equally well
* with DAML lists, RDF lists, and user-defined lists.
* </p>
* <p>
* A well-formed list has cells that are made up of three statements: one
* denoting the <code>rdf:type</code> of the list cell, one denoting the link
* to the value of the list at that point, and one pointing to the list tail. If
* a list cell is not well-formed, list operations may fail in unpredictable
* ways. However, to explicitly check that the list is well-formed at all times
* is expensive. Therefore the list operates in two modes: in <i>strict</i>
* mode, the well-formedness of the list is checked at the start of each list
* operation, and an {@link InvalidListException} is thrown if the list is not
* well- formed. This ensures that list operations are safe, but will slow down
* processing. In <i>non-strict</i> mode, this checking is switched off, but can
* be invoked explicitly by clients by calling {@link #isValid}. By default, RDF
* lists are processed in non-strict mode.
* </p>
*
* @author Ian Dickinson, HP Labs
* (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
* @version Release ($Id: RDFList.java,v 1.12 2007/01/02 11:48:34 andy_seaborne Exp $)
*/
public interface RDFList
extends Resource
{
// Constants
//////////////////////////////////
// External signature methods
//////////////////////////////////
/**
* <p>
* Answer the number of elements in the list.
* </p>
*
* @return The size of the list as an integer
*/
public int size();
/**
* <p>
* Answer the value that is at the head of the list.
* </p>
*
* @return The value that is associated with the head of the list.
* @exception EmptyListException if this list is the empty list
*/
public RDFNode getHead();
/**
* <p>
* Update the head of the list to have the given value, and return the
* previous value.
* </p>
*
* @param value The value that will become the value of the list head
* @exception EmptyListException if this list is the empty list
*/
public RDFNode setHead( RDFNode value );
/**
* <p>
* Answer the list that is the tail of this list.
* </p>
*
* @return The tail of the list, as a list
* @exception EmptyListException if this list is the empty list
*/
public RDFList getTail();
/**
* <p>
* Update the list cell at the front of the list to have the given list as
* tail. The old tail is returned, and remains in the model.
* </p>
*
* @param tail The new tail for this list.
* @return The old tail.
*/
public RDFList setTail( RDFList tail );
/**
* Answer true if this list is the empty list.
*
* @return True if this is the empty (nil) list, otherwise false.
*/
public boolean isEmpty();
/**
* <p>
* Return a reference to a new list cell whose head is <code>value</code>
* and whose tail is this list.
* </p>
*
* @param value A new value to add to the head of the list
* @return The new list, whose head is <code>value</code>
*/
public RDFList cons( RDFNode value );
/**
* <p>
* Add the given value to the end of the list. This is a side-effecting
* operation on the underlying model that is only defined if this is not the
* empty list. If this list is the empty (nil) list, we cannot perform a
* side-effecting update without changing the URI of this node (from <code>rdf:nil</code)
* to a blank-node for the new list cell) without violating a Jena invariant.
* Therefore, this update operation will throw an exception if an attempt is
* made to add to the nil list. Safe ways to add to an empty list include
* {@link #with} and {@link #cons}.
* </p>
*
* @param value A value to add to the end of the list
* @exception EmptyListUpdateException if an attempt is made to
* <code>add</code> to the empty list.
*/
public void add( RDFNode value );
/**
* <p>
* Answer the list that is this list with the given value added to the end
* of the list. This operation differs from {@link #add} in that it will
* always work, even on an empty list, but the return value is the updated
* list. Specifically, in the case of adding a value to the empty list, the
* returned list will not be the same as this list. <strong>Client code should
* not assume that this is an in-place update, but should ensure that the resulting
* list is asserted back into the graph into the appropriate relationships.</strong>
* </p>
*
* @param value A value to add to the end of the list
* @return The list that results from adding a value to the end of this list
*/
public RDFList with( RDFNode value );
/**
* <p>
* Answer the node that is the i'th element of the list, assuming that the
* head is item zero. If the list is too short to have an i'th element,
* throws a {@link ListIndexException}.
* </p>
*
* @param i The index into the list, from 0
* @return The list value at index i, or null
* @exception ListIndexException if the list has fewer than (i + 1)
* elements.
*/
public RDFNode get( int i );
/**
* <p>
* Replace the value at the i'th position in the list with the given value.
* If the list is too short to have an i'th element, throws a {@link
* ListIndexException}.
* </p>
*
* @param i The index into the list, from 0
* @param value The new value to associate with the i'th list element
* @return The value that was previously at position i in the list
* @exception ListIndexException if the list has fewer than (i + 1)
* elements.
*/
public RDFNode replace( int i, RDFNode value );
/**
* <p>
* Answer true if the given node appears as the value of a value of any
* of the cells of this list.
* </p>
*
* @param value A value to test for
* @return True if the list contains value.
*/
public boolean contains( RDFNode value );
/**
* <p>
* Answer the index of the first occurrence of the given value in the list,
* or -1 if the value is not in the list.
* </p>
*
* @param value The value to search for
* @return The index of the first occurrence of value in the list, or
* <code>-1</code> if not found.
*/
public int indexOf( RDFNode value );
/**
* <p>
* Answer the index of the first occurrence of the given value in the list
* after index <code>start</code>, or -1 if the value is not in the list
* after the given start point.
* </p>
*
* @param value The value to search for
* @param start The index into the list to start searching from
* @return The index of the first occurrence of value in the list not less
* than <code>start</code>, or <code>-1</code> if not found.
* @exception ListIndexException if <code>start</code> is greater than the
* length of the list.
*/
public int indexOf( RDFNode value, int start );
/**
* <p>
* Answer a new list that is formed by adding each element of this list to
* the head of the given <code>list</code>. This is a non side-effecting
* operation on either this list or the given list, but generates a copy
* of this list. For a more storage efficient alternative, see {@link
* #concatenate concatenate}.
* </p>
*
* @param list The argument list
* @return A new RDFList that contains all of this elements of this list,
* followed by all of the elements of the given list.
*/
public RDFList append( RDFList list );
/**
* <p>
* Answer a new list that is formed by adding each element of this list to
* the head of the the list formed from the
* given <code>nodes</code>. This is a non side-effecting
* operation on either this list or the given list, but generates a copy
* of this list. For a more storage efficient alternative, see {@link
* #concatenate concatenate}.
* </p>
*
* @param nodes An iterator whose range is RDFNode
* @return A new RDFList that contains all of this elements of this list,
* followed by all of the elements of the given iterator.
*/
public RDFList append( Iterator nodes );
/**
* <p>
* Change the tail of this list to point to the given list, so that this
* list becomes the list of the concatenation of the elements of both lists.
* This is a side-effecting operation on this list; for a non side-effecting
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -