1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.blobstore.options;
20
21 import static com.google.common.base.Preconditions.checkArgument;
22 import static com.google.common.base.Preconditions.checkNotNull;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public class ListContainerOptions extends ListOptions implements Cloneable {
40
41 public static final ImmutableListContainerOptions NONE = new ImmutableListContainerOptions(
42 new ListContainerOptions());
43
44 private String dir;
45 private boolean recursive;
46 private boolean detailed;
47
48 public ListContainerOptions() {
49 }
50
51 ListContainerOptions(Integer maxKeys, String marker, String dir, boolean recursive,
52 boolean detailed) {
53 super(maxKeys, marker);
54 this.dir = dir;
55 this.recursive = recursive;
56 this.detailed = detailed;
57 }
58
59 public static class ImmutableListContainerOptions extends ListContainerOptions {
60 private final ListContainerOptions delegate;
61
62 @Override
63 public ListContainerOptions afterMarker(String marker) {
64 throw new UnsupportedOperationException();
65 }
66
67 public ImmutableListContainerOptions(ListContainerOptions delegate) {
68 this.delegate = delegate;
69 }
70
71 @Override
72 public String getDir() {
73 return delegate.getDir();
74 }
75
76 @Override
77 public ListContainerOptions inDirectory(String dir) {
78 throw new UnsupportedOperationException();
79 }
80
81 @Override
82 public boolean isDetailed() {
83 return delegate.isDetailed();
84 }
85
86 @Override
87 public boolean isRecursive() {
88 return delegate.isRecursive();
89 }
90
91 @Override
92 public ListContainerOptions maxResults(int maxKeys) {
93 throw new UnsupportedOperationException();
94 }
95
96 @Override
97 public ListContainerOptions recursive() {
98 throw new UnsupportedOperationException();
99
100 }
101
102 @Override
103 public String getMarker() {
104 return delegate.getMarker();
105 }
106
107 @Override
108 public Integer getMaxResults() {
109 return delegate.getMaxResults();
110 }
111
112 @Override
113 public ListContainerOptions clone() {
114 return delegate.clone();
115 }
116
117 @Override
118 public String toString() {
119 return delegate.toString();
120 }
121
122 }
123
124 public String getDir() {
125 return dir;
126 }
127
128 public boolean isRecursive() {
129 return recursive;
130 }
131
132 public boolean isDetailed() {
133 return detailed;
134 }
135
136
137
138
139
140 public ListContainerOptions inDirectory(String dir) {
141 this.dir = checkNotNull(dir, "dir");
142 checkArgument(!dir.equals("/"), "dir must not be a slash");
143 return this;
144 }
145
146
147
148
149 public ListContainerOptions afterMarker(String marker) {
150 return (ListContainerOptions) super.afterMarker(marker);
151 }
152
153
154
155
156 public ListContainerOptions maxResults(int maxKeys) {
157 return (ListContainerOptions) super.maxResults(maxKeys);
158 }
159
160
161
162
163 public ListContainerOptions recursive() {
164
165 this.recursive = true;
166 return this;
167 }
168
169
170
171
172
173 public ListContainerOptions withDetails() {
174 this.detailed = true;
175 return this;
176 }
177
178 public static class Builder {
179
180
181
182
183 public static ListContainerOptions inDirectory(String directory) {
184 ListContainerOptions options = new ListContainerOptions();
185 return options.inDirectory(directory);
186 }
187
188
189
190
191 public static ListContainerOptions afterMarker(String marker) {
192 ListContainerOptions options = new ListContainerOptions();
193 return options.afterMarker(marker);
194 }
195
196
197
198
199 public static ListContainerOptions maxResults(int maxKeys) {
200 ListContainerOptions options = new ListContainerOptions();
201 return options.maxResults(maxKeys);
202 }
203
204
205
206
207 public static ListContainerOptions recursive() {
208 ListContainerOptions options = new ListContainerOptions();
209 return options.recursive();
210 }
211
212
213
214
215 public static ListContainerOptions withDetails() {
216 ListContainerOptions options = new ListContainerOptions();
217 return options.withDetails();
218 }
219 }
220
221 @Override
222 public ListContainerOptions clone() {
223 return new ListContainerOptions(getMaxResults(), getMarker(), dir, recursive, detailed);
224 }
225
226 @Override
227 public String toString() {
228 return "[dir=" + dir + ", recursive=" + recursive + ", detailed=" + detailed
229 + ", maxResults=" + getMaxResults() + "]";
230 }
231 }