Last change
on this file since 193 was
193,
checked in by Maciej Komosinski, 10 years ago
|
Set svn:eol-style native for all textual files
|
-
Property svn:eol-style set to
native
|
File size:
1.2 KB
|
Line | |
---|
1 | package com.framsticks.communication.queries; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import com.framsticks.util.lang.Delimeted; |
---|
7 | import com.framsticks.util.lang.Pair; |
---|
8 | |
---|
9 | /** |
---|
10 | * @author Piotr Sniegowski |
---|
11 | */ |
---|
12 | public class GetRequest extends ApplicationRequest { |
---|
13 | protected final List<String> fields = new ArrayList<>(); |
---|
14 | |
---|
15 | public GetRequest() { |
---|
16 | } |
---|
17 | |
---|
18 | public GetRequest fields(List<String> fields) { |
---|
19 | this.fields.clear(); |
---|
20 | this.fields.addAll(fields); |
---|
21 | return this; |
---|
22 | } |
---|
23 | |
---|
24 | public GetRequest field(String field) { |
---|
25 | this.fields.clear(); |
---|
26 | this.fields.add(field); |
---|
27 | return this; |
---|
28 | } |
---|
29 | |
---|
30 | @Override |
---|
31 | public String getCommand() { |
---|
32 | return "get"; |
---|
33 | } |
---|
34 | |
---|
35 | @Override |
---|
36 | protected StringBuilder construct(StringBuilder buffer) { |
---|
37 | super.construct(buffer); |
---|
38 | if (!fields.isEmpty()) { |
---|
39 | buffer.append(' ').append(new Delimeted<String>(",", "").append(fields.iterator())); |
---|
40 | } |
---|
41 | return buffer; |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * @return the fields |
---|
46 | */ |
---|
47 | public List<String> getFields() { |
---|
48 | return fields; |
---|
49 | } |
---|
50 | |
---|
51 | @Override |
---|
52 | public CharSequence parseRest(CharSequence rest) { |
---|
53 | rest = super.parseRest(rest); |
---|
54 | Pair<CharSequence, CharSequence> p = takeIdentifier(rest); |
---|
55 | if (p != null) { |
---|
56 | for (String a : p.first.toString().split(",")) { |
---|
57 | fields.add(a); |
---|
58 | } |
---|
59 | } |
---|
60 | return null; |
---|
61 | } |
---|
62 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.