001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.server.web.utils;
020
021/**
022 * Provides some functions for handling query builds easier.
023 *
024 * @author Antonio
025 */
026public class Query
027{
028        /**
029         * For an input query adds the extra param to it, correctly.
030         *
031         * @param query the "up-to-now" query that we want to add the extra param to.
032         * @param param the param to add to the query.
033         * @param operator the logical operator to add between params.
034         * @return the new query that has the new/extra param on it.
035         */
036        public static String addExtraQueryParam(String query, String param, String operator)
037        {
038                String result = query;
039
040                // check if this is not the only param in the query
041                if (! result.isEmpty())
042                        result += " " + operator + " ";
043
044                // add the extra param
045                result += param;
046
047                return result;
048        }
049
050        /**
051         * Same as the overloaded version, but the operator is AND.
052         *
053         * @param query the "up-to-now" query that we want to add the extra param to.
054         * @param param the param to add to the query.
055         * @return the new query that has the new/extra param on it.
056         */
057        public static String addExtraQueryParam(String query, String param)
058        {
059                return addExtraQueryParam(query, param, "AND");
060        }
061}