1 /*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jdigg.arguments;
17
18 /**
19 * Abstract base class for arguments with 'sort', 'count' and 'offset'.
20 * <p>Please read this before you use the API:
21 * <a href="http://apidoc.digg.com/BasicConcepts#BePolitePlease">Be Polite, Please!</a></p>
22 * @author Philip May
23 * @since 1.0 M1
24 */
25 public abstract class AbstractSortCountOffsetArguments extends AbstractArguments {
26
27 private static final String SORT_ARGUMENT_NAME = "sort";
28
29 private static final String COUNT_ARGUMENT_NAME = "count";
30
31 private static final String OFFSET_ARGUMENT_NAME = "offset";
32
33 public AbstractSortCountOffsetArguments(String appkey) {
34 super(appkey);
35 }
36
37 /**
38 * How to sort the results.
39 */
40 public final void setSort(String sort) {
41 addArgument(SORT_ARGUMENT_NAME, sort);
42 }
43
44 /**
45 * Number of results to retrieve.
46 * @param count Default: 10, Maximum: 100
47 */
48 public final void setCount(int count) {
49 // TODO: maybe check if > 0
50 // TODO: maybe check if <= 100
51 addArgument(COUNT_ARGUMENT_NAME, String.valueOf(count));
52 }
53
54 /**
55 * Offset in complete results list.
56 * @param offset Default: 0
57 */
58 public final void setOffset(int offset) {
59 // TODO: maybe check if >= 0
60 addArgument(OFFSET_ARGUMENT_NAME, String.valueOf(offset));
61 }
62
63 }