View Javadoc

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.gogrid.options;
20  
21  import static com.google.common.base.Preconditions.checkNotNull;
22  import static com.google.common.base.Preconditions.checkState;
23  import static org.jclouds.gogrid.reference.GoGridQueryParams.DATACENTER_KEY;
24  import static org.jclouds.gogrid.reference.GoGridQueryParams.IS_SANDBOX_KEY;
25  import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_TYPE_KEY;
26  
27  import org.jclouds.http.options.BaseHttpRequestOptions;
28  
29  /**
30   * @author Oleksiy Yarmula
31   */
32  public class GetServerListOptions extends BaseHttpRequestOptions {
33  
34     public final static GetServerListOptions NONE = new GetServerListOptions();
35  
36     public GetServerListOptions limitServerTypeTo(String serverType) {
37        checkState(!queryParameters.containsKey(SERVER_TYPE_KEY),
38                 "Can't have duplicate server type limit");
39        queryParameters.put(SERVER_TYPE_KEY, serverType);
40        return this;
41     }
42  
43     public GetServerListOptions inDatacenter(String datacenterId) {
44        checkState(!queryParameters.containsKey(DATACENTER_KEY), "Can't have duplicate datacenter id");
45        queryParameters.put(DATACENTER_KEY, datacenterId);
46        return this;
47     }
48  
49     public GetServerListOptions onlySandboxServers() {
50        checkState(!queryParameters.containsKey(IS_SANDBOX_KEY),
51                 "Can't have duplicate sandbox type limit");
52        queryParameters.put(IS_SANDBOX_KEY, "true");
53        return this;
54     }
55  
56     public GetServerListOptions excludeSandboxServers() {
57        checkState(!queryParameters.containsKey(IS_SANDBOX_KEY),
58                 "Can't have duplicate sandbox type limit");
59        queryParameters.put(IS_SANDBOX_KEY, "false");
60        return this;
61     }
62  
63     public static class Builder {
64        public GetServerListOptions inDatacenter(String datacenterId) {
65           GetServerListOptions getServerListOptions = new GetServerListOptions();
66           getServerListOptions.inDatacenter(checkNotNull(datacenterId));
67           return getServerListOptions;
68        }
69  
70        public GetServerListOptions limitServerTypeTo(String serverType) {
71           GetServerListOptions getServerListOptions = new GetServerListOptions();
72           getServerListOptions.limitServerTypeTo(checkNotNull(serverType));
73           return getServerListOptions;
74        }
75  
76        public GetServerListOptions onlySandboxServers() {
77           GetServerListOptions getServerListOptions = new GetServerListOptions();
78           getServerListOptions.onlySandboxServers();
79           return getServerListOptions;
80        }
81  
82        public GetServerListOptions excludeSandboxServers() {
83           GetServerListOptions getServerListOptions = new GetServerListOptions();
84           getServerListOptions.excludeSandboxServers();
85           return getServerListOptions;
86        }
87  
88     }
89  
90  }