/**
*
*/
package dblpq.distance;
import java.util.LinkedList;
import dblpq.person.Person;
/**
* Cette classe nous permetra de donner la distance entre deux auteurs. En d´autre terme,
* elle nous donnera le nombre d´ebene qui separent deux authors...
*
*/
public class DistanceBetweenAuthors {
private Person p1,p2;
private int distance = 0;
public DistanceBetweenAuthors(){}
// public DistanceBetweenAuthors( Person p1 , Person p2){
// this.p1 = p1;
// this.p2 = p2;
//
// }
public boolean areCoAuthors(Person p1, Person p2){
Person[] coAuthors = p1.getCoauthors();
for(Person p : coAuthors){
if(p.getName()==p2.getName()){
return true;
}
}
return false;
}
public int getDistance(Person p1, Person p2){
LinkedList<Person> usedPerson = new LinkedList<Person>();
if( areCoAuthors(p1,p2)){
distance++;
}
else{
Person[] coAuthors = p1.getCoauthors();
usedPerson.add(p1);
for (int i=0;i<coAuthors.length;i++){
Person coAuthor = coAuthors[i];
usedPerson.add(coAuthor);
for( int j = 0 ; j< coAuthor.getCoauthors().length ;j++ ){
Person p = coAuthor.getCoauthors()[j];
if ( ! usedPerson.contains(p)){
getDistance(coAuthor,p2);
distance++;
}
else{}
}
}
// }
}
return distance;
}
}