/*
* PageRank.java
*
* Created on den 9 oktober 2002, 14:33
*/
import java.util.*;
/**
*
* @author h&m
*/
public class PageRank {
private Collection pages = new Vector();
private boolean printIterations;
private int iterations = 0;
/** Creates a new instance of PageRank */
public PageRank(boolean pi) {
printIterations = pi;
}
public void addPage(Page p) {
pages.add(p);
}
public PageRank addPages(Collection pages) {
this.pages = pages;
return this;
}
/** Returns a string representation of the object. In general, the
* toString method returns a string that
* "textually represents" this object. The result should
* be a concise but informative representation that is easy for a
* person to read.
* It is recommended that all subclasses override this method.
*
* The toString method for class Object
* returns a string consisting of the name of the class of which the
* object is an instance, the at-sign character `@', and
* the unsigned hexadecimal representation of the hash code of the
* object. In other words, this method returns a string equal to the
* value of:
*
*
* getClass().getName() + '@' + Integer.toHexString(hashCode())
*
*
* @return a string representation of the object.
*
*/
public String toString() {
String tmp = new String();
Iterator iter = pages.iterator();
while(iter.hasNext())
tmp += ((Page) iter.next()).toString() + " ";
return tmp;
}
public int getIterations() {
return iterations;
}
public void calculatePR() {
boolean notDone = true;
iterations = 0;
while(notDone) {
iterations++;
notDone = false;
Iterator iter = pages.iterator();
while(iter.hasNext()) {
Page p = (Page) iter.next();
if(! p.calculatePR())
notDone = true;
}
if(printIterations)
System.out.println(toString());
}
}
}