Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.common.util » [javadoc | source]
    1   /*
    2    *  SSHTools - Java SSH2 API
    3    *
    4    *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
    5    *
    6    *  Contributions made by:
    7    *
    8    *  Brett Smith
    9    *  Richard Pernavas
   10    *  Erwin Bolwidt
   11    *
   12    *  This program is free software; you can redistribute it and/or
   13    *  modify it under the terms of the GNU General Public License
   14    *  as published by the Free Software Foundation; either version 2
   15    *  of the License, or (at your option) any later version.
   16    *
   17    *  This program is distributed in the hope that it will be useful,
   18    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20    *  GNU General Public License for more details.
   21    *
   22    *  You should have received a copy of the GNU General Public License
   23    *  along with this program; if not, write to the Free Software
   24    *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   25    */
   26   package com.sshtools.common.util;
   27   
   28   
   29   /**
   30    *
   31    *
   32    * @author $author$
   33    * @version $Revision: 1.8 $
   34    */
   35   public class Search {
   36       /**
   37   *
   38   *
   39   * @param str
   40   * @param query
   41   *
   42   * @return
   43   *
   44   * @throws IllegalArgumentException
   45   */
   46       public static boolean matchesWildcardQuery(String str, String query)
   47           throws IllegalArgumentException {
   48           int idx = query.indexOf("*");
   49   
   50           if (idx > -1) {
   51               // We have a wildcard search
   52               if ((idx > 0) && (idx < (query.length() - 1))) {
   53                   throw new IllegalArgumentException(
   54                       "Wildcards not supported in middle of query string; use either 'searchtext*' or '*searchtext'");
   55               }
   56   
   57               if (idx == (query.length() - 1)) {
   58                   return str.startsWith(query.substring(0, idx));
   59               } else {
   60                   return str.endsWith(query.substring(idx + 1));
   61               }
   62           } else {
   63               if (str.equalsIgnoreCase(query)) {
   64                   return true;
   65               }
   66           }
   67   
   68           return false;
   69       }
   70   }

Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.common.util » [javadoc | source]