Java tutorial
/* * COPYRIGHT (c) 2008-2009 by Institute of Computer Science, * Foundation for Research and Technology - Hellas * Contact: * POBox 1385, Heraklio Crete, GR-700 13 GREECE * Tel:+30-2810-391632 * Fax: +30-2810-391638 * E-mail: isl@ics.forth.gr * http://www.ics.forth.gr/isl * * Authors : Dimitris Andreou, Nelly Vouzoukidou. * * This file is part of SWKM model APIs (see also http://athena.ics.forth.gr:9090/SWKM/). * * SWKM model APIs 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 3 of the License, or * (at your option) any later version. * * SWKM model APIs 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 SWKM model APIs. If not, see <http://www.gnu.org/licenses/>. * * SWKM has been partially supported by EU project KP-Lab (IP IST-27490) kp-lab.org */ package gr.forth.ics.swkm.model2; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import java.util.Set; /** * * @author Andreou Dimitris, email: jim.andreou (at) gmail (dot) com */ public class ModelDiff { private ModelDiff() { } public static void checkEqual(Model m1, Model m2) { Set<Resource> namedGraphs1 = Sets.newHashSet(m1.namedGraphs()); Set<Resource> namedGraphs2 = Sets.newHashSet(); for (Resource ng : m2.namedGraphs()) { namedGraphs2.add(ng.mappedTo(m1)); } checkTriplesOfFirstContainedInSecond(m1, m2); checkTriplesOfFirstContainedInSecond(m2, m1); if (!namedGraphs1.equals(namedGraphs2)) { throw new AssertionError("Not equal named graphs: " + namedGraphs1 + " vs " + namedGraphs2); } } private static void checkTriplesOfFirstContainedInSecond(Model m1, Model m2) { for (Triple t : m1.triples().fetch()) { for (Resource ng : t.graphs()) { Triples triples = m2.triples().g(ng.mappedTo(m2)).s(t.subject().mappedTo(m2)) .p(t.predicate().mappedTo(m2)).o(t.object().mappedTo(m2)).fetch(); Iterables.getOnlyElement(triples); } } } }