001/** 002 * Copyright (C) 2007 - 2016, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.dllearner.algorithms.el; 020 021import java.util.Comparator; 022import java.util.Iterator; 023import java.util.Set; 024 025import org.semanticweb.owlapi.model.OWLProperty; 026 027/** 028 * A comparator implementation for the tree and role set convenience structure. 029 * 030 * @author Jens Lehmann 031 * 032 */ 033public class TreeAndRoleSetComparator implements Comparator<TreeAndRoleSet> { 034 035 private ELDescriptionTreeComparator treeComp = new ELDescriptionTreeComparator(); 036 037 /* (non-Javadoc) 038 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 039 */ 040 @Override 041 public int compare(TreeAndRoleSet o1, TreeAndRoleSet o2) { 042 int comp = treeComp.compare(o1.getTree(), o2.getTree()); 043 if(comp == 0) { 044 Set<OWLProperty> op1 = o1.getRoles(); 045 Set<OWLProperty> op2 = o2.getRoles(); 046 int sizeDiff = op1.size() - op2.size(); 047 if(sizeDiff == 0) { 048 Iterator<OWLProperty> it1 = op1.iterator(); 049 Iterator<OWLProperty> it2 = op2.iterator(); 050 while(it1.hasNext()) { 051 int stringComp = it1.next().compareTo(it2.next()); 052 if(stringComp != 0) { 053 return stringComp; 054 } 055 } 056 return 0; 057 } else { 058 return sizeDiff; 059 } 060 } else { 061 return comp; 062 } 063 } 064 065}