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

com.bigdata.rdf.internal.TermIVComparator Maven / Gradle / Ivy

package com.bigdata.rdf.internal;

import java.util.Comparator;

import com.bigdata.rdf.model.BigdataValue;

/**
 * Places {@link BigdataValue}s into an ordering determined by their assigned
 * {@link BigdataValue#getIV() IVs} (internal values).
 * 
 * @author Bryan Thompson
 * @version $Id$
 * 
 * @see BigdataValue#getIV()
 */
public class TermIVComparator implements Comparator {

    public static final transient Comparator INSTANCE =
        new TermIVComparator();

    /**
     * Note: comparison avoids possible overflow of long by
     * not computing the difference directly.
     */
    public int compare(final BigdataValue term1, final BigdataValue term2) {

        final IV iv1 = term1.getIV();
        final IV iv2 = term2.getIV();
        
        if (iv1 == null && iv2 == null)
            return 0;
        if (iv1 == null)
            return -1;
        if (iv2 == null)
            return 1;
        
        return iv1.compareTo(iv2);

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy