CycleFilter extends Filter { public void process(ScoreChart scorechart, User user, InetAddress peer, char direction, InodeHandleInterface dir, RemoteSlave sourceSlave) throws NoAvailableSlaveException { ArrayList<ScoreChart.SlaveScore> tempList = new ArrayList<>(scorechart .getSlaveScores()); while (true) { if (tempList.isEmpty()) { return; } ScoreChart.SlaveScore first = tempList.get(0); ArrayList<ScoreChart.SlaveScore> equalList = new ArrayList<>(); equalList.add(first); tempList.remove(first); for (Iterator<ScoreChart.SlaveScore> iter = tempList.iterator(); iter.hasNext(); ) { ScoreChart.SlaveScore match = iter.next(); if (match.compareTo(first) == 0) { equalList.add(match); iter.remove(); } } ScoreChart.SlaveScore leastUsed = first; for (ScoreChart.SlaveScore match : equalList) { if (match.getRSlave().getLastTransferForDirection(direction) < leastUsed .getRSlave().getLastTransferForDirection(direction)) { leastUsed = match; } } if (leastUsed != null) { leastUsed.addScore(1); } } } CycleFilter(int i, Properties p); void process(ScoreChart scorechart, User user, InetAddress peer,
                        char direction, InodeHandleInterface dir, RemoteSlave sourceSlave);  }
@Test public void testProcess() throws NoAvailableSlaveException, ObjectNotFoundException { RemoteSlave[] rslaves = { new DummyRemoteSlave("slave1"), new DummyRemoteSlave("slave2"), new DummyRemoteSlave("slave3") }; ScoreChart sc = new ScoreChart(Arrays.asList(rslaves)); Filter f = new CycleFilter(0, null); f.process(sc, null, null, Transfer.TRANSFER_SENDING_DOWNLOAD, null, null); assertEquals(1, sc.getScoreForSlave(rslaves[0]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[1]).getScore()); assertEquals(0, sc.getScoreForSlave(rslaves[2]).getScore()); }