001 /* 002 * Copyright © 2008, 2009 Pedro Agulló Soliveres. 003 * 004 * This file is part of DirectJNgine. 005 * 006 * DirectJNgine 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. 009 * 010 * DirectJNgine is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with DirectJNgine. If not, see <http://www.gnu.org/licenses/>. 017 * 018 * This software uses the ExtJs library (http://extjs.com), which is 019 * distributed under the GPL v3 license (see http://extjs.com/license). 020 */ 021 022 package com.softwarementors.extjs.djn; 023 024 import java.util.ArrayList; 025 import java.util.List; 026 027 public final class StringUtils { 028 private StringUtils() { 029 // Disallow instantiation 030 } 031 032 public static boolean isEmpty( String value ) { 033 return value == null || value.equals( ""); 034 } 035 036 public static String concatWithSeparator(List<String> missingParameters, String separator) { 037 assert missingParameters != null; 038 assert separator != null; 039 040 if( missingParameters.isEmpty() ) { 041 return ""; 042 } 043 044 StringBuilder result = new StringBuilder(); 045 for( int i = 0; i < missingParameters.size() - 1; i++) { 046 result.append( missingParameters.get(i)); 047 result.append( separator ); 048 } 049 050 result.append( missingParameters.get( missingParameters.size() - 1)); 051 052 return result.toString(); 053 } 054 055 // Returns a list of strings form a 'delimiter' separated string. 056 // It removes whitespace from every value, and ignores empty strings 057 public static List<String> getNonBlankValues( String delimitedValues, String delimiter ) { 058 assert !StringUtils.isEmpty( delimitedValues ); 059 assert !StringUtils.isEmpty(delimiter); 060 061 List<String> result = new ArrayList<String>(); 062 String[] values = delimitedValues.split( delimiter); 063 for( String value : values ) { 064 value = value.trim(); 065 if( !value.equals( "")) { 066 result.add( value ); 067 } 068 } 069 070 return result; 071 } 072 073 }