/* * (c) Copyright 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP * [See end of file] */ package arqo.histogram; import java.util.*; import com.hp.hpl.jena.datatypes.RDFDatatype; import com.hp.hpl.jena.graph.Node; import arqo.histogram.impl.HistogramNumeric; public class HistogramFactory { public static Histogram create(List nodes) { List stringNodes = new ArrayList() ; // List List uriNodes = new ArrayList() ; for (Iterator iter = nodes.iterator(); iter.hasNext(); ) { } Collections.sort(stringNodes, new NodeComparator()) ; Collections.sort(uriNodes, new NodeComparator()) ; for (Iterator iter = stringNodes.iterator(); iter.hasNext(); ) { Node node = (Node)iter.next() ; System.out.println(node.getLiteralDatatype()) ; } return new HistogramNumeric() ; } static class NodeComparator implements Comparator { public int compare(Object object1, Object object2) { if (! (object1 instanceof Node)) throw new ClassCastException() ; if (! (object2 instanceof Node)) throw new ClassCastException() ; Node node1 = (Node)object1 ; Node node2 = (Node)object2 ; if (node1.isURI() && node2.isURI()) { int value = node1.getURI().compareTo(node2.getURI()) ; return value ; } Object literal1 = node1.getLiteralValue() ; Object literal2 = node2.getLiteralValue() ; String lexical1 = node1.getLiteralLexicalForm() ; String lexical2 = node2.getLiteralLexicalForm() ; if (literal1 instanceof Number && literal2 instanceof Number) return (new Double(lexical1)).compareTo(new Double(lexical2)) ; if (literal1 instanceof String && literal2 instanceof String) return lexical1.compareTo(lexical2) ; throw new ClassCastException("Nodes have to be of the same type: " + lexical1 + ", " + lexical2) ; } } } /* * (c) Copyright 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */