-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepetidor.java
More file actions
74 lines (62 loc) · 1.71 KB
/
Repetidor.java
File metadata and controls
74 lines (62 loc) · 1.71 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
package src;
import java.util.*;
import java.util.regex.*;
public class Repetidor {
private static final Pattern REPT = Pattern.compile("^\s*REPT\s([0-9]{1,2})$");
private static final Pattern REND = Pattern.compile("^\s*REND\s*$");
private final ArrayList<String> body;
private final Integer start;
private final Integer jump;
private final Integer counter;
public Repetidor(int start, int end, ArrayList<String> lines){
this.start=start;
this.jump=end-start;
this.body=new ArrayList<>();
String line = lines.get(start);
int c=0;
if(rept(line)){
start++;
Matcher obj=REPT.matcher(line);
if(obj.find()){
c=Integer.parseInt(obj.group(1));
}
while(start<end){
line=lines.get(start);
body.add(line);
start++;
}
}
this.counter=c;
}
public static boolean rept(String line)
{
Matcher match=REPT.matcher(line);
return match.find();
}
public static boolean rend(String line){
Matcher match=REND.matcher(line);
return match.find();
}
public ArrayList<String> getBody()
{
return this.body;
}
public int getStart(){
return this.start;
}
public int getJump(){
return this.jump;
}
public int getCounter(){
return this.counter;
}
@Override
public String toString(){
String r="";
for(String s:this.body){
r+=s+"\n";
}
r+=this.start.toString()+"\n";
return r;
}
}