[freenet-cvs] r18967 - trunk/freenet/src/freenet/support/math

nextgens at freenetproject.org nextgens at freenetproject.org
Fri Apr 4 05:21:19 UTC 2008


Author: nextgens
Date: 2008-04-04 05:21:19 +0000 (Fri, 04 Apr 2008)
New Revision: 18967

Modified:
   trunk/freenet/src/freenet/support/math/DecayingKeyspaceAverage.java
   trunk/freenet/src/freenet/support/math/RunningAverage.java
Log:
indent

Modified: trunk/freenet/src/freenet/support/math/DecayingKeyspaceAverage.java
===================================================================
--- trunk/freenet/src/freenet/support/math/DecayingKeyspaceAverage.java	2008-04-04 05:20:31 UTC (rev 18966)
+++ trunk/freenet/src/freenet/support/math/DecayingKeyspaceAverage.java	2008-04-04 05:21:19 UTC (rev 18967)
@@ -13,132 +13,131 @@
  * A filter on BootstrappingDecayingRunningAverage which makes it aware of the circular keyspace.
  */
 public class DecayingKeyspaceAverage implements RunningAverage, Cloneable {
+
 	private static final long serialVersionUID = 5129429614949179428L;
 	/**
-	 'avg' is the normalized average location, note that the the reporting bounds are (-2.0, 2.0) however.
+	'avg' is the normalized average location, note that the the reporting bounds are (-2.0, 2.0) however.
 	 */
 	BootstrappingDecayingRunningAverage avg;
-	
+
 	public DecayingKeyspaceAverage(double defaultValue, int maxReports, SimpleFieldSet fs) {
-		avg=new BootstrappingDecayingRunningAverage(defaultValue, -2.0, 2.0, maxReports, fs);
+		avg = new BootstrappingDecayingRunningAverage(defaultValue, -2.0, 2.0, maxReports, fs);
 	}
-	
+
 	public DecayingKeyspaceAverage(BootstrappingDecayingRunningAverage a) {
 		//check the max/min values? ignore them?
-		avg=(BootstrappingDecayingRunningAverage)a.clone();
+		avg = (BootstrappingDecayingRunningAverage) a.clone();
 	}
-	
+
 	public synchronized Object clone() {
 		return new DecayingKeyspaceAverage(avg);
 	}
-    
+
 	public synchronized double currentValue() {
 		return avg.currentValue();
 	}
-	
+
 	public synchronized void report(double d) {
-		if ((d < 0.0) || (d > 1.0)) {
+		if((d < 0.0) || (d > 1.0))
 			//Just because we use non-normalized locations doesn't mean we can accept them.
-			throw new IllegalArgumentException("Not a valid normalized key: "+d);
-        }
-		double superValue=avg.currentValue();
-		double thisValue=Location.normalize(superValue);
-		double diff=Location.change(thisValue, d);
-		double toAverage=(superValue+diff);
+			throw new IllegalArgumentException("Not a valid normalized key: " + d);
+		double superValue = avg.currentValue();
+		double thisValue = Location.normalize(superValue);
+		double diff = Location.change(thisValue, d);
+		double toAverage = (superValue + diff);
 		/*
-		 To gracefully wrap around the 1.0/0.0 threshold we average over (or under) it, and simply normalize the result when reporting a currentValue
-		 ---example---
-		 d=0.2;          //being reported
-		 superValue=1.9; //already wrapped once, but at 0.9
-		 thisValue=0.9;  //the normalized value of where we are in the keyspace
-		 diff = +0.3;    //the diff from the normalized values; Location.change(0.9, 0.2);
-		 avg.report(2.2);//to successfully move the average towards the closest route to the given value.
+		To gracefully wrap around the 1.0/0.0 threshold we average over (or under) it, and simply normalize the result when reporting a currentValue
+		---example---
+		d=0.2;          //being reported
+		superValue=1.9; //already wrapped once, but at 0.9
+		thisValue=0.9;  //the normalized value of where we are in the keyspace
+		diff = +0.3;    //the diff from the normalized values; Location.change(0.9, 0.2);
+		avg.report(2.2);//to successfully move the average towards the closest route to the given value.
 		 */
 		avg.report(toAverage);
-		double newValue=avg.currentValue();
-		if (newValue < 0.0 || newValue > 1.0)
+		double newValue = avg.currentValue();
+		if(newValue < 0.0 || newValue > 1.0)
 			avg.setCurrentValue(Location.normalize(newValue));
 	}
-	
-    public synchronized double valueIfReported(double d) {
-		if ((d < 0.0) || (d > 1.0)) {
-			throw new IllegalArgumentException("Not a valid normalized key: "+d);
-        }		
-		double superValue=avg.currentValue();
-		double thisValue=Location.normalize(superValue);
-		double diff=Location.change(thisValue, d);
-		return Location.normalize(avg.valueIfReported(superValue+diff));
+
+	public synchronized double valueIfReported(double d) {
+		if((d < 0.0) || (d > 1.0))
+			throw new IllegalArgumentException("Not a valid normalized key: " + d);
+		double superValue = avg.currentValue();
+		double thisValue = Location.normalize(superValue);
+		double diff = Location.change(thisValue, d);
+		return Location.normalize(avg.valueIfReported(superValue + diff));
 	}
-	
-    public synchronized long countReports() {
+
+	public synchronized long countReports() {
 		return avg.countReports();
 	}
-	
+
 	public void report(long d) {
 		throw new IllegalArgumentException("KeyspaceAverage does not like longs");
 	}
-	
+
 	public synchronized void changeMaxReports(int maxReports) {
 		avg.changeMaxReports(maxReports);
 	}
-	
+
 	public synchronized SimpleFieldSet exportFieldSet(boolean shortLived) {
 		return avg.exportFieldSet(shortLived);
 	}
-	
+
 	///@todo: make this a junit test
 	public static void main(String[] args) {
-		DecayingKeyspaceAverage a=new DecayingKeyspaceAverage(0.9, 10, null);
+		DecayingKeyspaceAverage a = new DecayingKeyspaceAverage(0.9, 10, null);
 		a.report(0.9);
-		for (int i=10; i!=0; i--) {
+		for(int i = 10; i != 0; i--) {
 			a.report(0.2);
-			System.out.println("<-0.2-- current="+a.currentValue());
+			System.out.println("<-0.2-- current=" + a.currentValue());
 		}
-		for (int i=10; i!=0; i--) {
+		for(int i = 10; i != 0; i--) {
 			a.report(0.8);
-			System.out.println("--0.8-> current="+a.currentValue());
+			System.out.println("--0.8-> current=" + a.currentValue());
 		}
 		System.out.println("--- positive wrap test ---");
-		for (int wrap=3; wrap!=0; wrap--) {
-			System.out.println("wrap test #"+wrap);
-			for (int i=10; i!=0; i--) {
+		for(int wrap = 3; wrap != 0; wrap--) {
+			System.out.println("wrap test #" + wrap);
+			for(int i = 10; i != 0; i--) {
 				a.report(0.25);
-				System.out.println("<-0.25- current="+a.currentValue());
+				System.out.println("<-0.25- current=" + a.currentValue());
 			}
-			for (int i=10; i!=0; i--) {
+			for(int i = 10; i != 0; i--) {
 				a.report(0.5);
-				System.out.println("--0.5-> current="+a.currentValue());
+				System.out.println("--0.5-> current=" + a.currentValue());
 			}
-			for (int i=10; i!=0; i--) {
+			for(int i = 10; i != 0; i--) {
 				a.report(0.75);
-				System.out.println("-0.75-> current="+a.currentValue());
+				System.out.println("-0.75-> current=" + a.currentValue());
 			}
-			for (int i=10; i!=0; i--) {
+			for(int i = 10; i != 0; i--) {
 				a.report(1.0);
-				System.out.println("<-1.0-- current="+a.currentValue());
+				System.out.println("<-1.0-- current=" + a.currentValue());
 			}
 		}
 		System.out.println("--- negative wrap test ---");
-		a=new DecayingKeyspaceAverage(0.2, 10, null);
+		a = new DecayingKeyspaceAverage(0.2, 10, null);
 		a.report(0.2);
-		for (int wrap=3; wrap!=0; wrap--) {
-			System.out.println("negwrap test #"+wrap);
-			for (int i=10; i!=0; i--) {
+		for(int wrap = 3; wrap != 0; wrap--) {
+			System.out.println("negwrap test #" + wrap);
+			for(int i = 10; i != 0; i--) {
 				a.report(0.75);
-				System.out.println("-0.75-> current="+a.currentValue());
+				System.out.println("-0.75-> current=" + a.currentValue());
 			}
-			for (int i=10; i!=0; i--) {
+			for(int i = 10; i != 0; i--) {
 				a.report(0.5);
-				System.out.println("<-0.5-- current="+a.currentValue());
+				System.out.println("<-0.5-- current=" + a.currentValue());
 			}
-			for (int i=10; i!=0; i--) {
+			for(int i = 10; i != 0; i--) {
 				a.report(0.25);
-				System.out.println("<-0.25- current="+a.currentValue());
+				System.out.println("<-0.25- current=" + a.currentValue());
 			}
-			for (int i=10; i!=0; i--) {
+			for(int i = 10; i != 0; i--) {
 				a.report(1.0);
-				System.out.println("--1.0-> current="+a.currentValue());
+				System.out.println("--1.0-> current=" + a.currentValue());
 			}
 		}
 	}
-}
\ No newline at end of file
+}

Modified: trunk/freenet/src/freenet/support/math/RunningAverage.java
===================================================================
--- trunk/freenet/src/freenet/support/math/RunningAverage.java	2008-04-04 05:20:31 UTC (rev 18966)
+++ trunk/freenet/src/freenet/support/math/RunningAverage.java	2008-04-04 05:21:19 UTC (rev 18967)
@@ -6,21 +6,25 @@
 import java.io.Serializable;
 
 public interface RunningAverage extends Serializable, Cloneable {
-    
-    public Object clone();
-    
+
+	public Object clone();
+
 	public double currentValue();
+
 	public void report(double d);
+
 	public void report(long d);
-    /**
-     * Get what currentValue() would be if we reported some given value
-     * @param r the value to mimic reporting
-     * @return the output of currentValue() if we were to report r
-     */
-    public double valueIfReported(double r);
-    /**
-     * @return the total number of reports on this RunningAverage so far.
-     * Used for weighted averages, confidence/newbieness estimation etc.
-     */
-    public long countReports();
+
+	/**
+	 * Get what currentValue() would be if we reported some given value
+	 * @param r the value to mimic reporting
+	 * @return the output of currentValue() if we were to report r
+	 */
+	public double valueIfReported(double r);
+
+	/**
+	 * @return the total number of reports on this RunningAverage so far.
+	 * Used for weighted averages, confidence/newbieness estimation etc.
+	 */
+	public long countReports();
 }




More information about the cvs mailing list