📄 urinode.java
字号:
/* Sesame - Storage and Querying architecture for RDF and RDF Schema * Copyright (C) 2001-2005 Aduna * * Contact: * Aduna * Prinses Julianaplein 14 b * 3817 CS Amersfoort * The Netherlands * tel. +33 (0)33 465 99 87 * fax. +33 (0)33 465 99 87 * * http://aduna.biz/ * http://www.openrdf.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package org.openrdf.sesame.sailimpl.memory;import java.util.ArrayList;import java.util.List;import org.openrdf.model.GraphException;import org.openrdf.model.Resource;import org.openrdf.model.Statement;import org.openrdf.model.URI;import org.openrdf.model.Value;import org.openrdf.model.impl.URIImpl;import org.openrdf.sesame.sail.SailUpdateException;import org.openrdf.sesame.sail.StatementIterator;import org.openrdf.sesame.sail.util.EmptyStatementIterator;/** * An extension of URI giving it node properties. * * @author Arjohn Kampman * @version $Revision: 1.15 $ **/public class URINode extends URIImpl implements ResourceNode { /*---------------+| Variables |+---------------*/ transient protected RdfSource _source; /** The list of statements for which this URINode is the subject. **/ transient protected StatementList _subjectStatements; /** The list of statements for which this URINode is the predicate. **/ transient protected StatementList _predicateStatements; /** The list of statements for which this URINode is the object. **/ transient protected StatementList _objectStatements; transient protected StatementList _directTypeStatements; transient protected StatementList _directSubClassStatements; transient protected StatementList _directSubPropertyStatements; /*---------------+| Constructors |+---------------*/ /** * Creates a new URINode for a URI. * * @param source The Sail instance that created this URINode. * @param namespace namespace part of URI * @param localName localname part of URI */ URINode(RdfSource source, String namespace, String localName) { super(namespace, localName); _source = source; } URINode(RdfSource source, String uri) { super(uri); _source = source; } /*-----------------------------------+| Methods for _subjectStatements |+-----------------------------------*/ public StatementList getSubjectStatementList() { if (_subjectStatements == null) { return EMPTY_LIST; } else { return _subjectStatements; } } /** * Gets the list of Statements for which this URINode is the subject. * @return A List of Statements. **/ public StatementIterator getSubjectStatements() { if (_subjectStatements == null) { return new EmptyStatementIterator(); } else { return new MemStatementIterator(_subjectStatements); } } /** * Gets the amount of Statements for which this URINode is the subject. * @return An integer larger than or equal to 0. **/ public int getSubjectStatementCount() { if (_subjectStatements == null) { return 0; } else { return _subjectStatements.size(); } } /** * Adds a statement to this URINode's list of statements for which * it is the subject. **/ public void addSubjectStatement(Statement st) { if (_subjectStatements == null) { _subjectStatements = new StatementList(4); } _subjectStatements.add(st); } /** * Removes a statement from this URINode's list of statements for which * it is the subject. **/ public void removeSubjectStatement(Statement st) { _subjectStatements.remove(st); if (_subjectStatements.isEmpty()) { _subjectStatements = null; } } /*-----------------------------------+| Methods for _predicateStatements |+-----------------------------------*/ public StatementList getPredicateStatementList() { if (_predicateStatements == null) { return EMPTY_LIST; } else { return _predicateStatements; } } /** * Gets the list of Statements for which this URINode is the predicate. * @return A List of Statements. **/ public StatementIterator getPredicateStatements() { if (_predicateStatements == null) { return new EmptyStatementIterator(); } else { return new MemStatementIterator(_predicateStatements); } } /** * Gets the amount of Statements for which this URINode is the predicate. * @return An integer larger than or equal to 0. **/ public int getPredicateStatementCount() { if (_predicateStatements == null) { return 0; } else { return _predicateStatements.size(); } } /** * Adds a statement to this URINode's list of statements for which * it is the predicate. **/ public void addPredicateStatement(Statement st) { if (_predicateStatements == null) { _predicateStatements = new StatementList(4); } _predicateStatements.add(st); } /** * Removes a statement from this URINode's list of statements for which * it is the predicate. **/ public void removePredicateStatement(Statement st) { _predicateStatements.remove(st); if (_predicateStatements.isEmpty()) { _predicateStatements = null; } } /*-----------------------------------+| Methods for _objectStatements |+-----------------------------------*/ public StatementList getObjectStatementList() { if (_objectStatements == null) { return EMPTY_LIST; } else { return _objectStatements; } } /** * Gets the list of Statements for which this URINode is the object. * @return A List of Statements, or null if no such statement exists. **/ public StatementIterator getObjectStatements() { if (_objectStatements == null) { return new EmptyStatementIterator(); } else { return new MemStatementIterator(_objectStatements); } } /** * Gets the amount of Statements for which this URINode is the object. * @return An integer larger than or equal to 0. **/ public int getObjectStatementCount() { if (_objectStatements == null) { return 0; } else { return _objectStatements.size(); } } /** * Adds a statement to this URINode's list of statements for which * it is the object. **/ public void addObjectStatement(Statement st) { if (_objectStatements == null) { _objectStatements = new StatementList(4); } _objectStatements.add(st); } /** * Removes a statement from this URINode's list of statements for which * it is the object. **/ public void removeObjectStatement(Statement st) { _objectStatements.remove(st); if (_objectStatements.isEmpty()) { _objectStatements = null; } } public RdfSource getRdfSource() { return _source; } public void addProperty(URI property, Value value) throws GraphException { if (_source instanceof RdfRepository) { RdfRepository rep = (RdfRepository)_source; rep.startTransaction(); try { rep.addStatement(this, property, value); } catch (SailUpdateException e) { throw new GraphException(e); } finally { rep.commitTransaction();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -