001package org.apache.archiva.metadata; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Arrays; 023import java.util.Collections; 024import java.util.List; 025 026/** 027 * 028 * This class is used to provide additional query parameters to search queries. 029 * These parameters are hints for the metadata repository implementation, some parameters may be ignored. 030 * 031 * The defaults are: 032 * <li> 033 * <ul>Sort order: ascending</ul> 034 * <ul>Offset: 0</ul> 035 * <ul>Limit: Long.MAX_VALUE</ul> 036 * <ul>Sort fields: empty, which means it depends on the query</ul> 037 * </li> 038 * 039 * @author Martin Stockhammer <martin_s@apache.org> 040 */ 041public class QueryParameter { 042 043 final boolean ascending; 044 final List<String> sortFields; 045 final long offset; 046 final long limit; 047 048 public QueryParameter(boolean isAscending, long offset, long limit, String... sortFields) { 049 this.ascending = isAscending; 050 this.offset = offset; 051 this.limit = limit; 052 this.sortFields = Arrays.asList(sortFields); 053 } 054 055 public QueryParameter(long offset, long limit) { 056 this.offset=offset; 057 this.limit = limit; 058 this.ascending = true; 059 this.sortFields = Collections.emptyList(); 060 } 061 062 public QueryParameter(boolean isAscending, long offset, long limit) { 063 this.ascending = isAscending; 064 this.offset = offset; 065 this.limit = limit; 066 this.sortFields = Collections.emptyList(); 067 } 068 069 public QueryParameter(long limit) { 070 this.offset=0; 071 this.ascending=true; 072 this.limit=limit; 073 this.sortFields = Collections.emptyList(); 074 } 075 076 public QueryParameter() { 077 this.ascending = true; 078 this.sortFields = Collections.emptyList(); 079 this.offset = 0; 080 this.limit = Long.MAX_VALUE; 081 } 082 083 public boolean isAscending() { 084 return ascending; 085 } 086 087 public List<String> getSortFields() { 088 return sortFields; 089 } 090 091 public long getOffset() { 092 return offset; 093 } 094 095 public long getLimit() { 096 return limit; 097 } 098}