Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package structuredoutputcbr.adaptation; import java.util.Comparator; import structuredoutputcbr.ontology.OntologyElement; import org.apache.commons.collections4.CollectionUtils; /** * Class that compare two exercises taking into account the disjunction, in terms of muscles, with a previously given one * @author Joan T. Matamalas Llodr <jtmatamalas@gmail.com> */ public class ExerciseComparatorDisjunction implements Comparator { //Exercise take as reference OntologyElement exercise; /** * Constructor of the class * @param exercise Exercise take as reference */ public ExerciseComparatorDisjunction(OntologyElement exercise) { this.exercise = exercise; } @Override /** * Compare two elements taking into account the disjunction, in terms of muscles, with a previously given exercise */ public int compare(Object o1, Object o2) { OntologyElement ex1 = (OntologyElement) o1; OntologyElement ex2 = (OntologyElement) o2; int sizeDisjunctionEx1 = CollectionUtils .disjunction(ex1.getRelationValues("muscles"), this.exercise.getRelationValues("muscles")).size(); int sizeDisjunctionEx2 = CollectionUtils .disjunction(ex2.getRelationValues("muscles"), this.exercise.getRelationValues("muscles")).size(); return sizeDisjunctionEx1 - sizeDisjunctionEx2; } }