Author: xor
Date: 2008-10-24 12:16:31 +0000 (Fri, 24 Oct 2008)
New Revision: 23075
Modified:
trunk/freenet/src/freenet/node/BandwidthUsageHistory.java
Log:
Implement Iterator<BandwidthUsageSample>.
Modified: trunk/freenet/src/freenet/node/BandwidthUsageHistory.java
===================================================================
--- trunk/freenet/src/freenet/node/BandwidthUsageHistory.java 2008-10-24
12:14:07 UTC (rev 23074)
+++ trunk/freenet/src/freenet/node/BandwidthUsageHistory.java 2008-10-24
12:16:31 UTC (rev 23075)
@@ -3,6 +3,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Date;
+import java.util.NoSuchElementException;
/**
* A fixed-size list of bandwidth usage measurements. Storing a measurement
@@ -55,21 +56,28 @@
public Iterator<BandwidthUsageSample> iterator() {
return new Iterator<BandwidthUsageSample>() {
- int idx = (slot - data.length) % data.length;
+ int idx = 0;
public boolean hasNext() {
- // TODO Auto-generated method stub
- return false;
+ return (idx != data.length);
}
public BandwidthUsageSample next() {
- // TODO Auto-generated method stub
- return null;
+ if(!hasNext())
+ throw new NoSuchElementException();
+
+ // FIXME: figure out whether we should clone()
it.
+ BandwidthUsageSample result = data[(slot+idx) %
data.length];
+ ++idx;
+ return result;
}
+ /**
+ * This cannot be used: The BandwidthUsageHistory
contains a fixed
+ * amount of elements.
+ */
public void remove() {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException();
}
};