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

net.fortytwo.sesametools.ContextInsensitiveStatementComparator Maven / Gradle / Ivy

The newest version!
package net.fortytwo.sesametools;

import org.openrdf.model.Statement;

import java.util.Comparator;

/**
 * Implements a Comparator for OpenRDF Statements
 * using the order Subject->Predicate->Object
 *
 * @author Peter Ansell [email protected]
 */
public class ContextInsensitiveStatementComparator implements Comparator {
    public final static int BEFORE = -1;
    public final static int EQUALS = 0;
    public final static int AFTER = 1;

    @Override
    public int compare(Statement first, Statement second) {
        if (first == second) {
            return EQUALS;
        }

        if (first.getSubject().equals(second.getSubject())) {
            if (first.getPredicate().equals(second.getPredicate())) {
                if (first.getObject().equals(second.getObject())) {
                    return EQUALS;
                } else {
                    return ValueComparator.getInstance().compare(first.getObject(), second.getObject());
                }
            } else {
                return ValueComparator.getInstance().compare(first.getPredicate(), second.getPredicate());
            }
        } else {
            return ValueComparator.getInstance().compare(first.getSubject(), second.getSubject());
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy