Project

General

Profile

« Previous | Next » 

Revision b606df4d

Added by Andreas Müller almost 11 years ago

first version of abbreviated title cache generation for references : #1551

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java
29 29
import java.util.regex.Matcher;
30 30
import java.util.regex.Pattern;
31 31

  
32
import org.apache.commons.lang.StringUtils;
32 33
import org.apache.log4j.Logger;
33 34

  
34 35
/**
......
259 260
        String[] strings = {string1, string2};
260 261
        return concat(separator, strings);
261 262
    }
263
    
264
	
265
	/**
266
	 * Returns <code>preferred</code> if not blank, else returns <code>alternative</code>.
267
	 * If reverse is <code>true</code> computation is 
268
	 * the other way round (<code>alternative</code> if not blank, otherwise <code>preferred</code>).
269
	 * @param preferred first string
270
	 * @param alternative second string
271
	 * @param reverse reverse flag
272
	 * @param nzTrim if <code>true</code> the result is trimmed and <code>null</code> values are replaced by empty string.
273
	 * @return the preferred string
274
	 */
275
	static public String getPreferredNonEmptyString(String preferred, String alternative, boolean reverse, boolean nzTrim){
276
		String result;
277
		if (! reverse){
278
			result = StringUtils.isBlank(preferred) ? alternative : preferred;
279
		}else{
280
			result = StringUtils.isBlank(alternative) ? preferred : alternative;
281
		}
282
		if (nzTrim){
283
			result = Nz(result).trim();
284
		}
285
		return result;
286
	}
262 287

  
263 288

  
264 289
    /** Returns a version of the input where all contiguous

Also available in: Unified diff