Project

General

Profile

« Previous | Next » 

Revision 568fd3bc

Added by Andreas Müller about 16 years ago

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
9

  
9 10
package eu.etaxonomy.cdm.common;
10 11

  
11 12
import java.io.BufferedReader;
......
110 111
	static public String Nz(String value){
111 112
		return (value == null ? "" : value);
112 113
	}
114

  
115
	
116
	static public Integer Nz(Integer value){
117
		return (value == null ? 0 : value);
118
	}
119
	
120
	/**
121
	 * Concatenates the an Array of Strings, using the defined seperator.
122
	 * Null values are interpreted as empty Strings
123
	 * If all Strings are null a null is returned 
124
	 * @param strings
125
	 * @param seperator
126
	 * @return String 
127
	 */
128
	static public String concat(CharSequence seperator, String[] strings){
129
		String result = "";
130
		boolean allNull = true;
131
		for (String string : strings){
132
			if (string != null){
133
				if (result.length() > 0 && string.length() > 0){
134
					result += seperator;
135
				}
136
				result += string;
137
				allNull = false;
138
			}
139
		}
140
		//if all strings are null result should be null, not ""
141
		if (allNull){
142
			return null;
143
		}else {
144
			return result;
145
		}
146
	}
147

  
148
	static public String concat(CharSequence seperator, String string1, String string2){
149
		String[] strings = {string1, string2};
150
		return concat(seperator, strings);
151
	}
113 152
	
114 153
}

Also available in: Unified diff