This project has retired. For details please refer to its Attic page.
QueryParameter xref
View Javadoc
1   package org.apache.archiva.metadata;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Arrays;
23  import java.util.Collections;
24  import java.util.List;
25  
26  /**
27   *
28   * This class is used to provide additional query parameters to search queries.
29   * These parameters are hints for the metadata repository implementation, some parameters may be ignored.
30   *
31   * The defaults are:
32   * <li>
33   *     <ul>Sort order: ascending</ul>
34   *     <ul>Offset: 0</ul>
35   *     <ul>Limit: Long.MAX_VALUE</ul>
36   *     <ul>Sort fields: empty, which means it depends on the query</ul>
37   * </li>
38   *
39   * @author Martin Stockhammer <martin_s@apache.org>
40   */
41  public class QueryParameter {
42  
43      final boolean ascending;
44      final List<String> sortFields;
45      final long offset;
46      final long limit;
47  
48      public QueryParameter(boolean isAscending, long offset, long limit, String... sortFields) {
49          this.ascending = isAscending;
50          this.offset = offset;
51          this.limit = limit;
52          this.sortFields = Arrays.asList(sortFields);
53      }
54  
55      public QueryParameter(long offset, long limit) {
56          this.offset=offset;
57          this.limit = limit;
58          this.ascending = true;
59          this.sortFields = Collections.emptyList();
60      }
61  
62      public QueryParameter(boolean isAscending, long offset, long limit) {
63          this.ascending = isAscending;
64          this.offset = offset;
65          this.limit = limit;
66          this.sortFields = Collections.emptyList();
67      }
68  
69      public QueryParameter(long limit) {
70          this.offset=0;
71          this.ascending=true;
72          this.limit=limit;
73          this.sortFields = Collections.emptyList();
74      }
75  
76      public QueryParameter() {
77          this.ascending = true;
78          this.sortFields = Collections.emptyList();
79          this.offset = 0;
80          this.limit = Long.MAX_VALUE;
81      }
82  
83      public boolean isAscending() {
84          return ascending;
85      }
86  
87      public List<String> getSortFields() {
88          return sortFields;
89      }
90  
91      public long getOffset() {
92          return offset;
93      }
94  
95      public long getLimit() {
96          return limit;
97      }
98  }