0
|
1 package nabble.naml.namespaces;
|
|
2
|
|
3 import nabble.naml.compiler.Command;
|
|
4 import nabble.naml.compiler.CommandSpec;
|
|
5 import nabble.naml.compiler.IPrintWriter;
|
|
6 import nabble.naml.compiler.Interpreter;
|
|
7 import nabble.naml.compiler.Namespace;
|
|
8
|
|
9 import java.util.Collections;
|
|
10 import java.util.List;
|
|
11
|
|
12
|
|
13 @Namespace (
|
|
14 name = "string_list",
|
|
15 global = true
|
|
16 )
|
|
17 public class StringList extends ListSequence<String> {
|
|
18
|
|
19 public StringList(List<String> strings) {
|
|
20 super(strings);
|
|
21 }
|
|
22
|
|
23 @Command public void current_string(IPrintWriter out,Interpreter interp) {
|
|
24 current_element(out,interp);
|
|
25 }
|
|
26
|
|
27 @Command public void string_count(IPrintWriter out,Interpreter interp) {
|
|
28 element_count(out,interp);
|
|
29 }
|
|
30
|
|
31 public static final CommandSpec add = CommandSpec.NO_OUTPUT()
|
|
32 .dotParameter("s")
|
|
33 .build()
|
|
34 ;
|
|
35
|
|
36 @Command public void add(IPrintWriter out,Interpreter interp) {
|
|
37 String s = interp.getArgString("s");
|
|
38 if( s != null && !elements.contains(s))
|
|
39 elements.add(s);
|
|
40 }
|
|
41
|
|
42 public static final CommandSpec remove = add;
|
|
43
|
|
44 @Command public void remove(IPrintWriter out,Interpreter interp) {
|
|
45 String s = interp.getArgString("s");
|
|
46 if( s != null )
|
|
47 elements.remove(s);
|
|
48 }
|
|
49
|
|
50 public static final CommandSpec sort = CommandSpec.NO_OUTPUT;
|
|
51
|
|
52 @Command public void sort(IPrintWriter out,Interpreter interp) {
|
|
53 Collections.sort(elements);
|
|
54 }
|
|
55
|
|
56 public static final CommandSpec contains = new CommandSpec.Builder()
|
|
57 .dotParameter("s")
|
|
58 .build()
|
|
59 ;
|
|
60
|
|
61 @Command public void contains(IPrintWriter out,Interpreter interp) {
|
|
62 String s = interp.getArgString("s");
|
|
63 out.print( elements.contains(s) );
|
|
64 }
|
|
65
|
|
66 @Command public void next_string(IPrintWriter out,Interpreter interp) {
|
|
67 next_element(out,interp);
|
|
68 }
|
|
69
|
|
70 public static final CommandSpec has_more_strings = has_more_elements;
|
|
71
|
|
72 @Command public final void has_more_strings(IPrintWriter out,Interpreter interp) {
|
|
73 has_more_elements(out,interp);
|
|
74 }
|
|
75
|
|
76 public static final CommandSpec at_index = new CommandSpec.Builder()
|
|
77 .dotParameter("index")
|
|
78 .build()
|
|
79 ;
|
|
80
|
|
81 @Command public void at_index(IPrintWriter out,Interpreter interp) {
|
|
82 int i = interp.getArgAsInt("index");
|
|
83 out.print(elements.get(i));
|
|
84 }
|
|
85 }
|