package com.doumee.core.utils; 
 | 
  
 | 
  
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.slf4j.Logger; 
 | 
import org.slf4j.LoggerFactory; 
 | 
  
 | 
import java.security.SecureRandom; 
 | 
import java.util.Random; 
 | 
  
 | 
/** 
 | 
 * A null-safe utility to handle the String instances. 
 | 
 * 
 | 
 * @author Guang YANG 
 | 
 * @version 1.1 
 | 
 */ 
 | 
public final class Strings { 
 | 
  
 | 
    public static final String EMPTY = ""; 
 | 
    public static final String INSTANTIATION_PROHIBITED = "Instantiation prohibited."; 
 | 
    private static final Logger LOGGER = LoggerFactory.getLogger(Strings.class); 
 | 
  
 | 
    private Strings() { 
 | 
        throw new AssertionError(INSTANTIATION_PROHIBITED); 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * Generate random string with alpha and numeric of given length. 
 | 
     */ 
 | 
    public static String randomAlphanumeric(int length) { 
 | 
        return new RandomString(length).nextString(); 
 | 
    } 
 | 
  
 | 
    public static String randomNumeric(int length) { 
 | 
        return new RandomString(length, new SecureRandom(), "0123456789").nextString(); 
 | 
    } 
 | 
  
 | 
    public static String getRandomNumberString(Integer strLength) { 
 | 
  
 | 
        Random rnd = new Random(); 
 | 
  
 | 
        String str = "9999"; 
 | 
  
 | 
        if(strLength >= str.length()){ 
 | 
            str = StringUtils.leftPad(str,strLength,"9"); 
 | 
        } 
 | 
  
 | 
        int number = rnd.nextInt(Integer.parseInt(str)); 
 | 
  
 | 
        return String.format("%06d", number); 
 | 
  
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |