Here you can find the source of splitTerms(String text, String pattern)
Parameter | Description |
---|---|
text | The string to split. |
pattern | The delimiting regular expression. |
public static List<String> splitTerms(String text, String pattern)
//package com.java2s; /*/*from w ww . j av a 2 s .co m*/ * org.openmicroscopy.shoola.util.ui.search.SearchUtil * *------------------------------------------------------------------------------ * Copyright (C) 2006-2007 University of Dundee. All rights reserved. * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * *------------------------------------------------------------------------------ */ import java.util.ArrayList; import java.util.List; public class Main { /** Separator between words. */ public static final String COMMA_SEPARATOR = ","; /** The separator between the first name and the last name. */ public static final String SPACE_SEPARATOR = " "; /** The separator between the first name and the last name. */ public static final String QUOTE_SEPARATOR = "\""; /** The default text value. */ static final String ALL = "All"; /** * Splits the passed string around matches of the given pattern. * Returns a list of elements * * @param text The string to split. * @param pattern The delimiting regular expression. * @return See above. */ public static List<String> splitTerms(String text, String pattern) { List<String> l = new ArrayList<String>(); if (text == null) return l; text = text.trim(); String[] r = text.split(pattern); String value; for (int i = 0; i < r.length; i++) { value = r[i]; if (value != null) { value = value.trim(); if (value.length() != 0 && !value.equals(ALL)) l.add(value); } } return l; } /** * Splits the passed string around matches of the given pattern. * Returns a list of elements * * @param text The string to split. * @return See above. */ public static List<String> splitTerms(String text) { List<String> l = new ArrayList<String>(); if (text == null) return l; text = text.trim(); String pattern = SPACE_SEPARATOR; if (text.contains(QUOTE_SEPARATOR)) pattern = QUOTE_SEPARATOR; String[] r = text.split(pattern); String value; for (int i = 0; i < r.length; i++) { value = r[i]; if (value != null) { value = value.trim(); if (value.length() != 0 && !value.equals(ALL) && !value.equals(COMMA_SEPARATOR)) { if (value.contains(",")) value = value.replace(",", ""); l.add(value); } } } return l; } }