StepIterator.java
2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.example.mina.client.experiment;
import com.example.mina.client.base.MatrixCommand;
import com.example.mina.client.base.StationPair;
import java.util.Iterator;
/**
* This is used for handover iterations
* Usage:
* StationPair stationPair = StationPair.builder().out(5).inList(Arrays.asList(1,2,3)).build();
* StepIterator stepIterator = new StepIterator(stationPair, 3, 43, 10);
*
*
* while (stepIterator.hasNext()) {
* MatrixCommand[] cmds = stepIterator.next();
* System.out.println(cmds[0] + "----------"+ cmds[1]);
* }
*
*/
public class StepIterator implements Iterator{
private StationPair stationPair;
private int minAttn;
private int maxAttn;
private int step;
private int curInputIndex;
private int nextInputIndex;
private int curAttn1;
private int curAttn2;
public StepIterator(StationPair station, int min, int max, int step) {
this.stationPair = station;
this.minAttn = min;
this.maxAttn = max;
this.step = step;
curInputIndex = 0;
nextInputIndex = curInputIndex + 1;
curAttn1 = minAttn;
curAttn2 = maxAttn;
}
@Override
public boolean hasNext() {
return curInputIndex<stationPair.getInList().size() && curAttn2<=maxAttn;
}
@Override
public MatrixCommand[] next() {
MatrixCommand[] cmds = new MatrixCommand[2];
cmds[0] = MatrixCommand.builder().row(stationPair.getInList().get(curInputIndex))
.col(stationPair.getOut()).attn(curAttn1).build();
cmds[1] = MatrixCommand.builder().row(stationPair.getInList().get(nextInputIndex))
.col(stationPair.getOut()).attn(curAttn2).build();
if(curAttn1 >= maxAttn) {
cmds[0].setAttn(maxAttn);
cmds[1].setAttn(minAttn);
curInputIndex++;
nextInputIndex = (curInputIndex + 1) % stationPair.getInList().size();
curAttn1 = minAttn;
curAttn2 = maxAttn;
}else{
curAttn1 = curAttn1 + step;
curAttn2 = curAttn2 - step;
}
return cmds;
}
}