| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.cloudloadbalancers.options; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkArgument; |
| 22 | |
| 23 | import org.jclouds.http.options.BaseHttpRequestOptions; |
| 24 | |
| 25 | import com.google.common.collect.ImmutableSet; |
| 26 | |
| 27 | /** |
| 28 | * To reduce load on the service, list operations will return a maximum of 100 items at a time. To |
| 29 | * navigate the collection, the limit and marker parameters (for example, ?limit=50&marker=1 ) can |
| 30 | * be set in the URI. If a marker beyond the end of a list is given, an empty list is returned. Note |
| 31 | * that list operations never return 404 (itemNotFound) faults. |
| 32 | * |
| 33 | * @see <a |
| 34 | * href="http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch03s06.html" |
| 35 | * /> |
| 36 | * @author Adrian Cole |
| 37 | */ |
| 38 | public class ListOptions extends BaseHttpRequestOptions { |
| 39 | public static final ListOptions NONE = new ListOptions(); |
| 40 | |
| 41 | /** |
| 42 | * Indicates where to begin listing, if the previous list was larger than the limit. |
| 43 | */ |
| 44 | public ListOptions marker(String marker) { |
| 45 | checkArgument(marker != null, "marker cannot be null"); |
| 46 | queryParameters.replaceValues("marker", ImmutableSet.of(marker)); |
| 47 | return this; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * To reduce load on the service, list operations will return a maximum of 100 items at a time. |
| 52 | * <p/> |
| 53 | * Note that list operations never return itemNotFound (404) faults. |
| 54 | */ |
| 55 | public ListOptions limit(int limit) { |
| 56 | checkArgument(limit >= 0, "limit must be >= 0"); |
| 57 | checkArgument(limit <= 10000, "limit must be <= 10000"); |
| 58 | queryParameters.replaceValues("limit", ImmutableSet.of(limit + "")); |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | public static class Builder { |
| 63 | |
| 64 | /** |
| 65 | * @see ListOptions#marker(marker) |
| 66 | */ |
| 67 | public static ListOptions marker(String marker) { |
| 68 | ListOptions options = new ListOptions(); |
| 69 | return options.marker(marker); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @see ListOptions#limit(long) |
| 74 | */ |
| 75 | public static ListOptions limit(int limit) { |
| 76 | ListOptions options = new ListOptions(); |
| 77 | return options.limit(limit); |
| 78 | } |
| 79 | |
| 80 | } |
| 81 | } |