Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /* 
    * $Id: org/arakhne/afc/text/TextUtil.java v11.0 2014-07-01 13:43:43$
    * 
    * Copyright (c) 2005-10 Multiagent Team,
    * Laboratoire Systemes et Transports,
    * Universite de Technologie de Belfort-Montbeliard.
    * All rights reserved.
    * 
    * Copyright (C) 2012 Stephane GALLAND.
   * 
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 3 of the License, or (at your option) any later version.
   * 
   * This library 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
   * Lesser General Public License for more details.
   * 
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   * This program is free software; you can redistribute it and/or modify
   */
  
  package org.arakhne.afc.text;
  
  import java.util.Arrays;
  import java.util.List;
  import java.util.Map;
  import java.util.TreeMap;
  import java.util.UUID;
  
This class permits to manipulate texts.

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
  
  public class TextUtil {
  
  	private static final ReentrantLock lock = new ReentrantLock();
  	
  	private static SoftReference<Map<Character,String>> accentTransTbl = null;
  	private static SoftReference<Map<String,Integer>> htmlToJavaTransTbl = null;
  	private static SoftReference<Map<Character,String>> javaToHtmlTransTbl = null;

Enforced version of the equality test on two strings with case ignoring. This enforced version supported null values given as parameters.

Parameters:
a
b
isNullEmptyEquivalence indicates if the null value is assimilated to the empty string.
Returns:
true if a is equal to b; otherwise false.
  
  	public static boolean equalsIgnoreCase(String aString bboolean isNullEmptyEquivalence) {
  		String aa = (a!=null || !isNullEmptyEquivalence) ? a : "";  //$NON-NLS-1$
  		String bb = (b!=null || !isNullEmptyEquivalence) ? b : "";  //$NON-NLS-1$
  		if (aa==nullreturn bb==null;
  		if (bb==nullreturn false;
  		return aa.equalsIgnoreCase(bb);
  	}

Replies a base 26 encoding string for the given number.

Parameters:
number
Returns:
the base 26 encoding.
Since:
4.0
  
  	public static String encodeBase26(int number) {
  		StringBuilder value = new StringBuilder();
  		int q = number;
  		do {
  			int r = q % 26;
  			value.insert(0,(char)('A'+r));
  			q = q / 26 - 1;
  		}
  		while (q>=0);
  		return value.toString();
  	}

Replies the html-to-java's translation table.

This method read the translations from the resource file HTML_TRANS_TBL.

Returns:
the translation table or null if none was found. The translation table maps an HTML entity to its corresponding ISO chararacter code.
Since:
4.0
 
 		Map<String,Integermap = null;
 		try {
 			if (!=null)
 		}
 		finally {
 		}
 		
 		if (map!=nullreturn map;
 		
         // Get the resource file
 		ResourceBundle resource = null;
         try {
             resource = ResourceBundle.getBundle(
             		TextUtil.class.getCanonicalName(),
             		java.util.Locale.getDefault());
         }
         catch (MissingResourceException exep) {
             return null;
         }
         
         // get the resource string
         String result;
         
         try {
             result = resource.getString("HTML_TRANS_TBL"); //$NON-NLS-1$
         }
         catch (Exception e) {
             return null;
         }
         
         map = new TreeMap<String,Integer>();
         
         String[] pairs = result.split("(\\}\\{)|\\{|\\}"); //$NON-NLS-1$
         Integer isoCode;
         String entity;
         String code;
         for(int i=1; (i+1)<pairs.lengthi+=2) {
         	try {
         		entity = pairs[i];
         		code = pairs[i+1];
         		isoCode = Integer.valueOf(code);
         		if (isoCode!=nullmap.put(entityisoCode);
         	}
         	catch(Throwable _) {
         		//
         	}
 		}
         
 		try {
 		}
 		finally {
 		}
 
 		return map;
 	}

Replies the java-to-html's translation table.

This method read the translations from the resource file HTML_TRANS_TBL.

Returns:
the translation table or null if none was found. The translation table maps an ISO character code to its corresponding HTML entity.
Since:
4.0
 
 		Map<Character,Stringmap = null;
 		try {
 			if (!=null)
 		}
 		finally {
 		}
 		
 		if (map!=nullreturn map;
 		
         // Get the resource file
         ResourceBundle resource = null;
         try {
             resource = ResourceBundle.getBundle(
             		TextUtil.class.getCanonicalName(),
             		java.util.Locale.getDefault());
         }
         catch (MissingResourceException exep) {
             return null;
         }
         
         // get the resource string
         String result;
         
         try {
             result = resource.getString("HTML_TRANS_TBL"); //$NON-NLS-1$
         }
         catch (Exception e) {
             return null;
         }
         
         map = new TreeMap<Character,String>();
         
         String[] pairs = result.split("(\\}\\{)|\\{|\\}"); //$NON-NLS-1$
         Integer isoCode;
         String entity;
         String code;
         for(int i=1; (i+1)<pairs.lengthi+=2) {
         	try {
         		entity = pairs[i];
         		code = pairs[i+1];
         		isoCode = Integer.valueOf(code);
         		if (isoCode!=nullmap.put((char)isoCode.intValue(), entity);
         	}
         	catch(Throwable _) {
         		//
         	}
 		}
         
 		try {
 		}
 		finally {
 		}
 
 		return map;
 	}

Parse the given HTML text and replace all the HTML entities by the corresponding unicode character.

Parameters:
html is the HTML to convert.
Returns:
the unicode representation of the given html text.
Since:
4.0
See also:
toHTML(java.lang.String)
 
 	public static String parseHTML(String html) {
 		if (html==nullreturn null;
 		assert(transTbl!=null);
 		if (transTbl.isEmpty()) return html;
 		Pattern pattern = Pattern.compile("[&](([a-zA-Z]+)|(#x?[0-9]+))[;]"); //$NON-NLS-1$
 		Matcher matcher = pattern.matcher(html);
 		StringBuilder result = new StringBuilder();
 		String entity;
 		Integer isoCode;
 		int idxlastIndex = 0;
 		while (matcher.find()) {
 			idx = matcher.start();
 			result.append(html.substring(lastIndexidx));
 			lastIndex = matcher.end();
 			entity = matcher.group(1);
 			if (entity.startsWith("#x")) { //$NON-NLS-1$
 				try {
 					isoCode = Integer.valueOf(entity.substring(2), 16);
 				}
 				catch(Throwable _) {
 					isoCode = null;
 				}
 			}
 			else if (entity.startsWith("#")) { //$NON-NLS-1$
 				try {
 					isoCode = Integer.valueOf(entity.substring(1));
 				}
 				catch(Throwable _) {
 					isoCode = null;
 				}
 			}
 			else {
 				isoCode = transTbl.get(entity);
 			}
 			
 			if (isoCode==null) {
 				result.append(matcher.group());
 			}
 			else {
 				result.append((char)isoCode.intValue());
 			}
 		}
 		if (lastIndex<html.length()) result.append(html.substring(lastIndex));
 		return result.toString();
 	}

Translate all the special character from the given text to their equivalent HTML entities.

Parameters:
text is the text to convert.
Returns:
the HTML text which is corresponding to the given text.
Since:
4.0
See also:
parseHTML(java.lang.String)
 
 	public static String toHTML(String text) {
 		if (text==nullreturn null;
 		assert(transTbl!=null);
 		if (transTbl.isEmpty()) return text;
 		StringBuilder patternStr = new StringBuilder();
 		for(Character c : transTbl.keySet()) {
 			if (patternStr.length()>0) patternStr.append("|"); //$NON-NLS-1$
 			patternStr.append(Pattern.quote(c.toString()));
 		}
 		Pattern pattern = Pattern.compile(patternStr.toString());
 		Matcher matcher = pattern.matcher(text);
 		StringBuilder result = new StringBuilder();
 		String characterentity;
 		int idxlastIndex = 0;
 		while (matcher.find()) {
 			idx = matcher.start();
 			result.append(text.substring(lastIndexidx));
 			lastIndex = matcher.end();
 			character = matcher.group();
 			if (character.length()==1) {
 				entity = transTbl.get(Character.valueOf(character.charAt(0)));
 				if (entity!=null) {
 					entity = "&"+entity+";"//$NON-NLS-1$ //$NON-NLS-2$
 				}
 				else {
 					entity = character;
 				}
 			}
 			else {
 				entity = character;
 			}
 			result.append(entity);
 		}
 		if (lastIndex<text.length()) result.append(text.substring(lastIndex));
 		return result.toString();
 	}

Format the text to be sure that each line is not more longer than the specified quantity of characters.

Parameters:
text is the string to cut
column is the column number that corresponds to the splitting point.
Returns:
the given text splitted in lines separated by \n.
 
 	public static String cutString(String textint column) {
 		StringBuilder buffer = new StringBuilder();
 		cutStringAlgo(textnew CutStringColumnCritera(column), new CutStringToString(buffer));
 		return buffer.toString();
 	}

Format the text to be sure that each line is not more longer than the specified quantity of characters.

Parameters:
text is the string to cut
column is the column number that corresponds to the splitting point.
Returns:
the given text splitted in lines separated by \n.
 
 	public static String[] cutStringAsArray(String textint column) {
 		List<Stringlist = new ArrayList<String>();
 		cutStringAlgo(textnew CutStringColumnCritera(column), new CutStringToArray(list));
 		String[] result = new String[list.size()];
 		list.toArray(result);
 		list.clear();
 		return result;
 	}

Format the text to be sure that each line is not more longer than the specified critera.

Parameters:
text is the string to cut
critera is the critera to respect.
output is the given text splitted in lines separated by \n.
Since:
4.0
 
 	public static void cutStringAsArray(String textCutStringCritera criteraList<Stringoutput) {
 		cutStringAlgo(textcriteranew CutStringToArray(output));
 	}
 
 	private static void cutStringAlgo(String textCutStringCritera criteraCutStringAlgorithm algo) {
 		assert(critera!=null);
 		
 		if (text==null || critera.getCritera()<=0) return;
 		
 		assert(algo!=null);
 		
 		StringBuilder line = new StringBuilder();
 		String[] lines = text.split("[\\n\\r\r\n]"); //$NON-NLS-1$
 		String[] words;
 		String word;
 		long lineLength;
 		int maxLength;
 		
 		for(int idxLine=0; idxLine<lines.length; ++idxLine) {
 			words = lines[idxLine].split("[\t \n\r\f]+"); //$NON-NLS-1$
 			lineLength = 0;
 			for(int i=0; i<words.length; ++i) {
 				word = words[i];
 				if (critera.isOverfull(lineLength,word)) {
 					if (line.length()>0 || i>0)
 						algo.addLine(line.toString());
 					line.setLength(0);
 					line.append(word);
 					// Split the word
 					maxLength = critera.getCutIndexFor(line.toString());
 					while (maxLength>0) {
 						algo.addLine(line.substring(0, maxLength));
 						line.delete(0, maxLength);
 						maxLength = critera.getCutIndexFor(line.toString());
 					}
 					// Append last part of the word
 					lineLength = critera.getLengthFor(line.toString());
 				}
 				else {
 					if (line.length()>0) {
 						line.append(' ');
 						lineLength += critera.getLengthFor(" "); //$NON-NLS-1$
 					}
 					// Append word
 					line.append(word);
 					lineLength += critera.getLengthFor(word);
 				}
 			}
 			if (line.length()>0) {
 				algo.addLine(line.toString());
 				line.setLength(0);
 			}
 		}
 	}

Replies the character which follow the first '&'.

Parameters:
text is the text to scan.
Returns:
the character that is following the first '&' or '\0'
 
 	public static char getMnemonicChar(String text) {
 		if (text!=null) {
 			int pos = text.indexOf('&');
 			if ((pos!=-1)&&(pos<text.length()-1)) {
 				return text.charAt(pos+1);
 			}
 		}
 		return '\0';
 	}

Remove the mnemonic char from the specified string.

Parameters:
text is the text to scan.
Returns:
the given text without the mnemonic character.
 
 	public static String removeMnemonicChar(String text) {
 		if (text==nullreturn text;
 		return text.replaceFirst("&",""); //$NON-NLS-1$ //$NON-NLS-2$
 	}

Replies the accent's translation table.

This method read the translations from the resource file ACCENT_TRANS_TBL.

Returns:
the translation table or null if none was found.
 
 		Map<Character,Stringmap = null;
 		try {
 			if (!=null)
 				map = .get();
 		}
 		finally {
 		}
 		
 		if (map!=nullreturn map;
 		
         // Get the resource file
         ResourceBundle resource = null;
         try {
             resource = ResourceBundle.getBundle(
             		TextUtil.class.getCanonicalName(),
             		java.util.Locale.getDefault());
         }
         catch (MissingResourceException exep) {
             return null;
         }
         
         // get the resource string
         String result;
         
         try {
             result = resource.getString("ACCENT_TRANS_TBL"); //$NON-NLS-1$
         }
         catch (Exception e) {
             return null;
         }
         
         map = new TreeMap<Character,String>();
         
         String[] pairs = result.split("(\\}\\{)|\\{|\\}"); //$NON-NLS-1$
         for (String pair : pairs) {
         	if (pair.length()>1) {
         		map.put(pair.charAt(0),pair.substring(1));
         	}
 		}
         
 		try {
 		}
 		finally {
 		}
 
 		return map;
 	}

Remove the accents inside the specified string.

Parameters:
text is the string into which the accents must be removed.
Returns:
the given string without the accents
 
 	public static String removeAccents(String text) {
 		if ((map==null)||(map.isEmpty())) return text;
         return removeAccents(textmap);
 	}

Remove the accents inside the specified string.

Parameters:
text is the string into which the accents must be removed.
map is the translation table from an accentuated character to an unaccentuated character.
Returns:
the given string without the accents
 
 	public static String removeAccents(String textMap<Character,Stringmap) {
 		if (text==nullreturn text;
 		StringBuilder buffer = new StringBuilder();
 		for (char c : text.toCharArray()) {
 			String trans = map.get(c);
 			if (trans!=null)
 				buffer.append(trans);
 			else
 				buffer.append(c);
 		}
 		return buffer.toString();
 	}

Split the given string according to brackets. The brackets are used to delimit the groups of characters.

Examples:

  • splitBrackets("{a}{b}{cd}") returns the array ["a","b","cd"]
  • splitBrackets("abcd") returns the array ["abcd"]
  • splitBrackets("a{bcd") returns the array ["a","bcd"]
    • Parameters:
      str is the strig with brackets.
      Returns:
      the groups of strings
 
 	public static String[] splitBrackets(String str) {
 		return split('{','}',str);
 	}

Split the given string according to the separators. The separators are used to delimit the groups of characters.

Examples:

  • split('{','}',"{a}{b}{cd}") returns the array ["a","b","cd"]
  • split('{','}',"abcd") returns the array ["abcd"]
  • split('{','}',"a{bcd") returns the array ["a","bcd"]
    • Parameters:
      leftSeparator is the left separator.
      rightSeparator is the right separator.
      str is the strig with brackets.
      Returns:
      the groups of strings
      Since:
      4.0
 
 	public static String[] split(char leftSeparatorchar rightSeparatorString str) {
 		splitSeparatorAlgorithm(leftSeparatorrightSeparatorstralgo);
 		return algo.toArray();
 	}

Split the given string according to brackets. The brackets are used to delimit the groups of characters.

Examples:

  • splitBrackets("{a}{b}{cd}") returns the array ["a","b","cd"]
  • splitBrackets("abcd") returns the array ["abcd"]
  • splitBrackets("a{bcd") returns the array ["a","bcd"]
    • Parameters:
      str is the elements enclosed by backets.
      Returns:
      the groups of strings
 
 	public static List<StringsplitBracketsAsList(String str) {
 		return splitAsList('{''}'str);
 	}

Split the given string according to separators. The separators are used to delimit the groups of characters.

Examples:

  • split('{','}',"{a}{b}{cd}") returns the array ["a","b","cd"]
  • split('{','}',"abcd") returns the array ["abcd"]
  • split('{','}',"a{bcd") returns the array ["a","bcd"]
    • Parameters:
      leftSeparator is the left separator.
      rightSeparator is the right separator.
      str is the elements enclosed by backets.
      Returns:
      the groups of strings
 
 	public static List<StringsplitAsList(char leftSeparatorchar rightSeparatorString str) {
 		List<Stringlist = new ArrayList<String>();
 				leftSeparatorrightSeparatorstr,
 		return list;
 	}
 
 	private static void splitSeparatorAlgorithm(
 			char leftSeparatorchar rightSeparator,
 			String strSplitSeparatorAlgorithm buffer) {
 		assert(buffer!=null);
 		if (str!=null && str.length()>0) {
 			StringBuilder patternStr = new StringBuilder();
 			patternStr.append("([^\\"); //$NON-NLS-1$
 			patternStr.append(leftSeparator);
 			patternStr.append("\\"); //$NON-NLS-1$
 			patternStr.append(rightSeparator);
 			patternStr.append("]*)(\\"); //$NON-NLS-1$
 			patternStr.append(leftSeparator);
 			patternStr.append("|\\"); //$NON-NLS-1$
 			patternStr.append(rightSeparator);
 			patternStr.append(")"); //$NON-NLS-1$
 			Pattern pattern = Pattern.compile(patternStr.toString());
 			Matcher matcher = pattern.matcher(str);
 			
 			int startOffset = 0; // inclusive
 			int endOffset = 0; // exclusive
 			String sseparatorpreviousText;
 			int depth = 0;
 			
 			StringBuilder token = new StringBuilder();
 			
 			while (matcher.find()) {
 				previousText = matcher.group(1);
 				separator = matcher.group(2);
 				endOffset = startOffset+previousText.length();
 			
 				if (startOffset<str.length() && endOffset>startOffset) {
 					token.append(str.substring(startOffsetendOffset));
 				}
 				
 				if (separator.equals(Character.toString(leftSeparator))) {
 					if (depth>0) {
 						token.append(separator);
 					}
 					else if (token.length()>0) {
 						s = token.toString().trim();
 						if (s.length()>0) buffer.addToken(s);
 						token.setLength(0);
 					}
 					++depth;
 				}
 				else if (separator.equals(Character.toString(rightSeparator))) {
 					if (depth==0) {
 						token.append(separator);
 					}
 					else {
 						--depth;
 						if (depth>0) {
 							token.append(separator);
 						}
 						else {
 							buffer.addToken(token.toString());
 							token.setLength(0);
 						}
 					}
 				}
 				else {
 					throw new IllegalStateException();
 				}
 				
 				startOffset = endOffset + separator.length();
 			}
 			
 			if (startOffset<str.length()) {
 				token.append(str.substring(startOffset));
 			}
 			
 			if (token.length()>0) {
 				s = token.toString().trim();
 				if (s.length()>0) buffer.addToken(s);
 			}
 		}
 	}

Split the given string according to brackets. The brackets are used to delimit the groups of characters.

Examples:

  • splitBrackets("{a}{b}{cd}") returns the array ["a","b","cd"]
  • splitBrackets("abcd") returns the array ["abcd"]
  • splitBrackets("a{bcd") returns the array ["a","bcd"]
    • Parameters:
      str is the elements enclosed by backets.
      Returns:
      the groups of strings
 
 	public static List<UUIDsplitBracketsAsUUIDs(String str) {
 		return splitAsUUIDs('{','}',str);
 	}

Split the given string according to separators. The separators are used to delimit the groups of characters.

Examples:

  • split('{','}',"{a}{b}{cd}") returns the array ["a","b","cd"]
  • split('{','}',"abcd") returns the array ["abcd"]
  • split('{','}',"a{bcd") returns the array ["a","bcd"]
    • Parameters:
      leftSeparator is the left separator.
      rightSeparator is the right separator.
      str is the elements enclosed by backets.
      Returns:
      the groups of strings
      Since:
      4.0
 
 	public static List<UUIDsplitAsUUIDs(char leftSeparatorchar rightSeparatorString str) {
 		List<UUIDlist = new ArrayList<UUID>();
 		splitSeparatorAlgorithm(leftSeparatorrightSeparatorstrnew UUIDSplitSeparatorAlgorithm(list));
 		return list;
 	}

Merge the given strings with to brackets. The brackets are used to delimit the groups of characters.

Examples:

  • mergeBrackets("a","b","cd") returns the string "{a}{b}{cd}"
  • mergeBrackets("a{bcd") returns the string "{a{bcd}"
    • Parameters:
      <T> is the type of the parameters.
      strs is the array of strings.
      Returns:
      the string with bracketed strings.
 
 	public static <T> String mergeBrackets(T... strs) {
 		return join('{','}',strs);
 	}

Merge the given strings with to separators. The separators are used to delimit the groups of characters.

Examples:

  • merge('{','}',"a","b","cd") returns the string "{a}{b}{cd}"
  • merge('{','}',"a{bcd") returns the string "{a{bcd}"
    • Parameters:
      <T> is the type of the parameters.
      leftSeparator is the left separator to use.
      rightSeparator is the right separator to use.
      strs is the array of strings.
      Returns:
      the string with merged strings.
      Since:
      4.0
 
 	public static <T> String join(char leftSeparatorchar rightSeparator, T... strs) {
 		StringBuilder buffer = new StringBuilder();
 		for(Object s : strs) {
 			buffer.append(leftSeparator);
 			if (s!=nullbuffer.append(s.toString());
 			buffer.append(rightSeparator);
 		}
 		return buffer.toString();
 	}

Merge the given strings with to brackets. The brackets are used to delimit the groups of characters.

Examples:

  • mergeBrackets("a","b","cd") returns the string "{a}{b}{cd}"
  • mergeBrackets("a{bcd") returns the string "{a{bcd}"
 
 	public static String mergeBrackets(Iterable<?> strs) {
 		return join('{','}',strs);
 	}

Merge the given strings with to separators. The separators are used to delimit the groups of characters.

Examples:

  • merge('{','}',"a","b","cd") returns the string "{a}{b}{cd}"
  • merge('{','}',"a{bcd") returns the string "{a{bcd}"
    • Parameters:
      leftSeparator is the left separator to use.
      rightSeparator is the right separator to use.
      strs is the array of strings.
      Returns:
      the string with merged strings.
      Since:
      4.0
 
 	public static String join(char leftSeparatorchar rightSeparatorIterable<?> strs) {
 		StringBuilder buffer = new StringBuilder();
 		for(Object s : strs) {
 			buffer.append(leftSeparator);
 			if (s!=nullbuffer.append(s.toString());
 			buffer.append(rightSeparator);
 		}
 		return buffer.toString();
 	}

Compares this String to another String, ignoring accent considerations. Two strings are considered equal ignoring accents if they are of the same length, and corresponding characters in the two strings are equal ignoring accents.

This method is equivalent to:


 TextUtil.removeAccents(s1,map).equals(TextUtil.removeAccents(s2,map));
 

Parameters:
s1 is the first string to compare.
s2 is the second string to compare.
map is the translation table from an accentuated character to an unaccentuated character.
Returns:
true if the argument is not null and the Strings are equal, ignoring case; false otherwise.
See also:
removeAccents(java.lang.String,java.util.Map)
 
 	public static boolean equalsIgnoreAccents(String s1String s2Map<Character,Stringmap) {
 		return removeAccents(s1,map).equals(removeAccents(s2,map));
 	}

Compares this String to another String, ignoring case and accent considerations. Two strings are considered equal ignoring case and accents if they are of the same length, and corresponding characters in the two strings are equal ignoring case and accents.

This method is equivalent to:


 TextUtil.removeAccents(s1,map).equalsIgnoreCase(TextUtil.removeAccents(s2,map));
 

Parameters:
s1 is the first string to compare.
s2 is the second string to compare.
map is the translation table from an accentuated character to an unaccentuated character.
Returns:
true if the argument is not null and the Strings are equal, ignoring case; false otherwise.
See also:
removeAccents(java.lang.String,java.util.Map)
 
 	public static boolean equalsIgnoreCaseAccents(String s1String s2Map<Character,Stringmap) {
 		return removeAccents(s1,map).equalsIgnoreCase(removeAccents(s2,map));
 	}

Translate the specified string to lower case and remove the accents.

Parameters:
text is the text to scan.
Returns:
the given string without the accents and lower cased
 
 	public static String toLowerCaseWithoutAccent(String text) {
 		if ((map==null)||(map.isEmpty())) return text;
         return toLowerCaseWithoutAccent(textmap);
 	}

Translate the specified string to lower case and remove the accents.

Parameters:
text is the text to scan.
map is the translation table from an accentuated character to an unaccentuated character.
Returns:
the given string without the accents and lower cased
 
 	public static String toLowerCaseWithoutAccent(String textMap<Character,Stringmap) {
 		StringBuilder buffer = new StringBuilder();
 		for (char c : text.toCharArray()) {
 			String trans = map.get(c);
 			if (trans!=null)
 				buffer.append(trans.toLowerCase());
 			else
 				buffer.append(Character.toLowerCase(c));
 		}
 		return buffer.toString();
 	}

Translate the specified string to upper case and remove the accents.

Parameters:
text is the text to scan.
Returns:
the given string without the accents and upper cased
 
 	public static String toUpperCaseWithoutAccent(String text) {
 		if ((map==null)||(map.isEmpty())) return text;
         return toUpperCaseWithoutAccent(textmap);
 	}

Translate the specified string to upper case and remove the accents.

Parameters:
text is the text to scan.
map is the translation table from an accentuated character to an unaccentuated character.
Returns:
the given string without the accents and upper cased
 
 	public static String toUpperCaseWithoutAccent(String textMap<Character,Stringmap) {
 		StringBuilder buffer = new StringBuilder();
 		for (char c : text.toCharArray()) {
 			String trans = map.get(c);
 			if (trans!=null)
 				buffer.append(trans.toUpperCase());
 			else
 				buffer.append(Character.toUpperCase(c));
 		}
 		return buffer.toString();
 	}

Compute the better metric representing the given time amount and reply a string representation of the given amount with this selected unit.

This function try to use a greater metric unit.

Parameters:
amount is the amount expressed in the given unit.
unit is the unit of the given amount.
Returns:
a string representation of the given amount.
 
 	public static String formatTime(double amountTimeUnit unit) {
 		double amt;
 		double coef = 1.;
 		switch(unit) {
 		case :
 			coef = 86400.;
 			break;
 		case :
 			coef = 3600.;
 			break;
		case :
			coef = 60.;
			break;
		case :
			break;
			coef = 1e-3;
			break;
			coef = 1e-6;
			break;
			coef = 1e-9;
			break;
		default:
		// amount is in seconds
		amt = amount * coef;
		StringBuilder text = new StringBuilder();
		String centuriesyearsdayshoursminutesseconds;
		int idx;
		long aahamas;
		centuries = years = days = hours = minutes = seconds = ""//$NON-NLS-1$
		ah = am = as = 0;
		idx = 0;
		if (amt>=3153600000.) {
			a = (long)Math.floor(amt / 3153600000.);
			centuries = Locale.getString((a>=2) ? "TIME_FORMAT_Cs" : "TIME_FORMAT_C", Long.toString(a)); //$NON-NLS-1$ //$NON-NLS-2$
			amt -= a * 3153600000.;
			text.append(centuries);
			idx |= 32;
		if (amt>=31536000.) {
			a = (long)Math.floor(amt / 31536000.);
			years = Locale.getString((a>=2) ? "TIME_FORMAT_Ys" : "TIME_FORMAT_Y", Long.toString(a)); //$NON-NLS-1$ //$NON-NLS-2$
			amt -= a * 31536000.;
			if (text.length()>0) text.append(' ');
			text.append(years);
			idx |= 16;
		if (amt>=86400.) {
			a = (long)Math.floor(amt / 86400.);
			days = Locale.getString((a>=2) ? "TIME_FORMAT_Ds" : "TIME_FORMAT_D", Long.toString(a)); //$NON-NLS-1$ //$NON-NLS-2$
			amt -= a * 86400.;
			if (text.length()>0) text.append(' ');
			text.append(days);
			idx |= 8;
		//-------------------
		if (amt>=3600.) {
			ah = (long)Math.floor(amt / 3600.);
			hours = Long.toString(ah);
			if (ah<10.) hours = "0" + hours//$NON-NLS-1$
			amt -= ah * 3600.;
			idx |= 4;
		if (amt>=60.) {
			am = (long)Math.floor(amt / 60.);
			minutes = Long.toString(am);
			if (am<10.) minutes = "0" + minutes//$NON-NLS-1$
			amt -= am * 60.;
			idx |= 2;
		if (amt>=0. || idx==0) {
			if (idx>=8) {
				as = (long)Math.floor(amt);
				seconds = Long.toString(as);
			else {
				NumberFormat fmt = new DecimalFormat("#0.000"); //$NON-NLS-1$				
				seconds = fmt.format(amt);
			idx |= 1;
		if ((idx&7)==7) {
			if (text.length()>0) text.append(' ');
			if (idx>=8 && as>0) {
				if (as<10.) seconds = "0" + seconds//$NON-NLS-1$
			else if (idx<8 && amt>0.) {
				if (amt<10.) seconds = "0" + seconds//$NON-NLS-1$
			}			
			text.append(Locale.getString("TIME_FORMAT_HMS"hoursminutesseconds)); //$NON-NLS-1$
		else {
			if (ah>0) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((ah>=2) ? "TIME_FORMAT_Hs" : "TIME_FORMAT_H"hours)); //$NON-NLS-1$ //$NON-NLS-2$
			if (am>0) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((am>=2) ? "TIME_FORMAT_Ms" : "TIME_FORMAT_M"minutes)); //$NON-NLS-1$ //$NON-NLS-2$
			if (idx>=8 && as>0) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((as>=2) ? "TIME_FORMAT_Ss" : "TIME_FORMAT_S"seconds)); //$NON-NLS-1$ //$NON-NLS-2$
			else if (idx<8 && amt>0.) {
				if (text.length()>0) text.append(' ');
				text.append(Locale.getString((amt>=2.) ? "TIME_FORMAT_Ss" : "TIME_FORMAT_S"seconds)); //$NON-NLS-1$ //$NON-NLS-2$
		return text.toString();
	}

Format the given double value.

Parameters:
amount
decimalCount is the maximal count of decimal to put in the string.
Returns:
a string representation of the given value.
	public static String formatDouble(double amountint decimalCount) {
		int dc = (decimalCount<0) ? 0 : decimalCount;
		StringBuilder str = new StringBuilder("#0"); //$NON-NLS-1$
		if (dc>0) {
			str.append('.');
			for(int i=0; i<dc; ++i)
				str.append('0');
		return fmt.format(amount);
	}

Format the given float value.

Parameters:
amount
decimalCount is the maximal count of decimal to put in the string.
Returns:
a string representation of the given value.
	public static String formatFloat(float amountint decimalCount) {
		int dc = (decimalCount<0) ? 0 : decimalCount;
		StringBuilder str = new StringBuilder("#0"); //$NON-NLS-1$
		if (dc>0) {
			str.append('.');
			for(int i=0; i<dc; ++i)
				str.append('0');
		return fmt.format(amount);
	}

Join the elements of the given array with the given join text.

Parameters:
<T> is the type of the elements
joinText
elements
Returns:
the joining text
	public static <T> String join(String joinText, T... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextboolean... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextbyte... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextchar... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextshort... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextint... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextlong... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextfloat... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextdouble... elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text.

Parameters:
joinText
elements
Returns:
the joining text
	public static String join(String joinTextIterable<?> elements) {
		return join(joinTextnullnullelements);
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
<T> is the type of the elements
joinText
prefix
postfix
elements
Returns:
the joining text
	public static <T> String join(String joinTextString prefixString postfix, T... elements) {
		return join(joinTextprefixpostfix, Arrays.asList(elements));
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixIterable<?> elements) {
		StringBuilder buffer = new StringBuilder();
		String txt;
		for(Object e : elements) {
			if (e!=null) {
				txt = e.toString();
				if (txt!=null && txt.length()>0) {
					if (buffer.length()>0) buffer.append(joinText);
					if (prefix!=nullbuffer.append(prefix);
					buffer.append(txt);
					if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixboolean... elements) {
		StringBuilder buffer = new StringBuilder();
		for(boolean e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixbyte... elements) {
		StringBuilder buffer = new StringBuilder();
		for(byte e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixchar... elements) {
		StringBuilder buffer = new StringBuilder();
		for(char e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixshort... elements) {
		StringBuilder buffer = new StringBuilder();
		for(short e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixint... elements) {
		StringBuilder buffer = new StringBuilder();
		for(int e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixlong... elements) {
		StringBuilder buffer = new StringBuilder();
		for(long e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixfloat... elements) {
		StringBuilder buffer = new StringBuilder();
		for(float e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Join the elements of the given array with the given join text. The prefix and postfix values will be put just before and just after each element respectively.

Parameters:
joinText
prefix
postfix
elements
Returns:
the joining text
	public static String join(String joinTextString prefixString postfixdouble... elements) {
		StringBuilder buffer = new StringBuilder();
		for(double e : elements) {
			if (buffer.length()>0) buffer.append(joinText);
			if (prefix!=nullbuffer.append(prefix);
			buffer.append(e);
			if (postfix!=nullbuffer.append(postfix);
		return buffer.toString();
	}

Algorithm interface used by cut string functions to provide a buffer filler.

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private interface CutStringAlgorithm {

Add a line to the output buffer.

Parameters:
line
		public void addLine(String line);
	}

Algorithm interface used by split bracket functions to provide a buffer filler.

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private interface SplitSeparatorAlgorithm {

Add a token to the output buffer.

Parameters:
token
		public void addToken(String token);
	}

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private static class CutStringToArray implements CutStringAlgorithm {
		private final List<Stringbuffer;

Parameters:
buffer is the buffer to fill.
		public CutStringToArray(List<Stringbuffer) {
			this. = buffer;
		}

		public void addLine(String line) {
			this..add(line);
	}

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private static class CutStringToString implements CutStringAlgorithm {
		private final StringBuilder buffer;

Parameters:
buffer is the buffer to fill.
			this. = buffer;
		}

		public void addLine(String line) {
			if (this..length()>0)
				this..append('\n');
			this..append(line);
	}

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private static class SplitSeparatorToListAlgorithm implements SplitSeparatorAlgorithm {
		private final List<Stringlist;

Parameters:
tab
			this. = tab;
		}

		public void addToken(String token) {
			this..add(token);
	}

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private static class SplitSeparatorToArrayAlgorithm implements SplitSeparatorAlgorithm {
		private static final int BUFFER_SIZE = 20;

		private String[] array = new String[];
		private int size = 0;

			//
		}

		public void addToken(String token) {
			if (this.>=this..length) {
				String[] t = new String[this..length+];
				System.arraycopy(this., 0, t, 0, this..length);
				this. = t;
			this.[this.] = token;
			++this.;
		}

Replies the array;

Returns:
the array.
		public String[] toArray() {
			if (this..length>this.) {
				String[] t = new String[this.];
				System.arraycopy(this., 0, t, 0, this.);
				return t;
			return this.;
	}

Author(s):
Stéphane GALLAND
Version:
11.0 2014-07-01 13:43:43
Mavengroupid:
org.arakhne.afc.core
Mavenartifactid:
text
	private static class UUIDSplitSeparatorAlgorithm implements SplitSeparatorAlgorithm {
		private final List<UUIDlist;

Parameters:
tab
			this. = tab;
		}