/* Loom.java * * Copyright (c) 2003 by Benja Fallenstein * * This file is part of Fenfire. * * Fenfire 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 of the License, or * (at your option) any later version. * * Fenfire 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 Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * */ /* * Written by Benja Fallenstein */ package gzz.loom; import java.util.*; import com.hp.hpl.mesa.rdf.jena.model.*; /** A simple lexical order of statements. * Statements are first ordered by the URI of predicate, * then by the URI or anonymous node id or literal value * of the subject/object (subject if dir<0, object * if dir>0). */ public class SimpleOrder implements Comparator { protected int dir; public static final Comparator subjOrder = new SimpleOrder(-1); public static final Comparator objOrder = new SimpleOrder(1); public SimpleOrder(int dir) { if(dir == 0) throw new IllegalArgumentException("zero dir"); this.dir = dir; } public int compare(Object o1, Object o2) { Statement s1 = (Statement)o1, s2 = (Statement)o2; int cmp = s1.getPredicate().toString() .compareTo(s2.getPredicate().toString()); if(cmp == 0) { if(dir < 0) cmp = s1.getSubject().toString() .compareTo(s2.getSubject().toString()); else cmp = s1.getObject().toString() .compareTo(s2.getObject().toString()); } return cmp; } }