View Javadoc

1   /* Copyright (2005-2007) Schibsted Søk AS
2    * This file is part of SESAT.
3    *
4    *   SESAT is free software: you can redistribute it and/or modify
5    *   it under the terms of the GNU Affero General Public License as published by
6    *   the Free Software Foundation, either version 3 of the License, or
7    *   (at your option) any later version.
8    *
9    *   SESAT is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU Affero General Public License for more details.
13   *
14   *   You should have received a copy of the GNU Affero General Public License
15   *   along with SESAT.  If not, see <http://www.gnu.org/licenses/>.
16   *
17   * AbstractRunningQuery.java
18   *
19   * Created on 16 February 2006, 19:49
20   *
21   */
22  
23  package no.sesat.search.run;
24  
25  import org.apache.log4j.Logger;
26  
27  /**
28   * @version $Id$
29   *
30   */
31  public abstract class AbstractRunningQuery implements RunningQuery {
32  
33      private static final Logger LOG = Logger.getLogger(AbstractRunningQuery.class);
34  
35      protected final Context context;
36  
37      /** Creates a new instance of AbstractRunningQuery */
38      protected AbstractRunningQuery(final Context cxt) {
39          context = cxt;
40      }
41  
42  
43      /**
44       * Remote duplicate spaces. Leading and trailing spaces will
45       * be preserved
46       * @param query that may conaint duplicate spaces
47       * @return string with duplicate spaces removed
48       */
49      protected static String trimDuplicateSpaces(final String query){
50  
51          LOG.trace("trimDuplicateSpaces(" + query + ")");
52  
53          return query == null
54                  ? null
55                  : query.replaceAll("\\s+", " ").trim();
56      }
57  
58  }