All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ontoware.rdf2go.model.impl.ModelAddRemoveMemoryImpl Maven / Gradle / Ivy

Go to download

RDF2go is an implementation-independent Java API with the design goals: portability (hence the name), performance and ease of implementation. This project was started at FZI Forschungszentrum Informatik Karlsruhe, Germany - www.fzi.de

The newest version!
/**
 * LICENSE INFORMATION
 *
 * Copyright 2005-2008 by FZI (http://www.fzi.de).
 * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
 *  = Max Völkel
 *  = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
 *  = 2010
 *
 * Further project information at http://semanticweb.org/wiki/RDF2Go
 */

package org.ontoware.rdf2go.model.impl;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.ontoware.aifbcommons.collection.ClosableIterator;
import org.ontoware.rdf2go.exception.LockException;
import org.ontoware.rdf2go.exception.ModelRuntimeException;
import org.ontoware.rdf2go.model.Diff;
import org.ontoware.rdf2go.model.ModelAddRemove;
import org.ontoware.rdf2go.model.Statement;
import org.ontoware.rdf2go.model.node.Node;
import org.ontoware.rdf2go.model.node.Resource;
import org.ontoware.rdf2go.model.node.URI;

public class ModelAddRemoveMemoryImpl extends AbstractModelAddRemove implements ModelAddRemove {

	/**
     * 
     */
    private static final long serialVersionUID = 7704116494068276793L;
	protected Set set = new HashSet();

	@Override
	public void addStatement(Resource subject, URI predicate, Node object) throws ModelRuntimeException {
		Statement s = new StatementImpl(null, subject, predicate, object);
		this.set.add(s);
	}

	@Override
	public void removeStatement(Resource subject, URI predicate, Node object) throws ModelRuntimeException {
		Statement s = new StatementImpl(null, subject, predicate, object);
		this.set.remove(s);
	}
	
	public Set getSet() {
		return this.set;
	}

	@Override
    public void lock() throws LockException {
		throw new UnsupportedOperationException();
	}

	@Override
    public boolean isLocked() {
		throw new UnsupportedOperationException();
	}

	@Override
    public void unlock() {
		throw new UnsupportedOperationException();
	}

	@Override
    public Diff getDiff(Iterator statements) throws ModelRuntimeException {
		ModelAddRemoveMemoryImpl other = new ModelAddRemoveMemoryImpl();
		other.addAll(statements);

		ModelAddRemoveMemoryImpl add = new ModelAddRemoveMemoryImpl();
		add.addAll(other.iterator());
		add.removeAll(this.iterator());

		ModelAddRemoveMemoryImpl removed = new ModelAddRemoveMemoryImpl();
		removed.addAll(this.iterator());
		removed.removeAll(other.iterator());

		return new DiffImpl(add.iterator(), removed.iterator());
	}

	@Override
    public ClosableIterator iterator() {
		Iterator it = this.set.iterator();
		assert it != null;
		return new PseudoClosableIterator( it );
	}

	public long size() {
		return this.set.size();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy