com.daioware.commons.string.StringUtil Maven / Gradle / Ivy
package com.daioware.commons.string;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Pattern;
import com.daioware.commons.wrapper.WrapperInt;
import com.daioware.math.Number;
/**
*
* @author Diego Olvera
*
*/
public class StringUtil {
public static final char A_UPPER_CASE=65;
public static final char Z_UPPER_CASE=90;
public static final char ZERO=48;
public static final char NINE=57;
public static final char ASCII_START=33;
public static final char ASCII_END=126;
public static final int ONLY_LETTERS=1;
public static final int ONLY_DIGITS=2;
public static final int DIGITS_AND_LETTERS=3;
public static final int ANY_CHARACTER=4;
public static final int RFC_SIZE=13;
//RFC Validations
public static final int CHAR_FIRST_VALIDATION=4,CHAR_SECOND_VALIDATION=10;
public static final Pattern pwdPattern = Pattern
.compile("((?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,100})");
public static final Pattern mailPattern=
Pattern.compile("^[_a-z0-9-]+(.[_a-z0-9-]+)*@(\\w)(.[a-z]{2,3})*$");
public static final String REG_EXP_CALENDAR="\\d+-\\d+$";
public static final String REG_EXP_BI_CALENDAR="\\d+[a|A|b|B]$";
private static final Pattern validVariableNamePattern=Pattern.compile("^[a-zA-Z_$][a-zA-Z_$0-9]*$");
public static final Regex regexCalendar=new Regex(REG_EXP_CALENDAR);
public static final Regex regexBiCalendar=new Regex(REG_EXP_BI_CALENDAR);
public static String getOrEmpty(String s) {
return getOr(s,null);
}
public static String getOr(String s,String defaultValue) {
return s!=null?s:"";
}
public static boolean isValidEMail(String possibleMail) {
return mailPattern.matcher(possibleMail).matches();
}
public static boolean isValidCalendar(String c) {
return regexCalendar.matches(c) | regexBiCalendar.matches(c);
}
public static boolean anagram(ArrayList strings) {
int i,stringsSize=strings.size();
ArrayList> stringFrequencies=new ArrayList<>(stringsSize);
boolean anagram;
for(String string:strings) {
stringFrequencies.add(getFrequencies(string));
}
anagram=true;
for(i=0;i1;
}
public static String getCamelCaseStringWithNoSpaces(String str) {
StringBuilder newString=new StringBuilder();
char aux;
int state=0;
for(int i=0,j=str.length();i getFrequencies(String str){
HashMap frequencies=new HashMap<>();
char aux;
WrapperInt wrapperInt;
for(int i=0,j=str.length();i fillers){
str=str.trim();
ArrayList cadenas=new ArrayList();
int indiceComa,indiceEspacio,desde=0,hasta;
int longStr=str.length();
boolean aunHayPalabrasPorLeer;
String rellenador;
int cuantasVecesHastaEsIgualAMenos1=1;
char aux;
int cuentaComas;
if(longStr>=1){
do{
indiceEspacio=str.indexOf(" ",desde);
indiceComa=str.indexOf(",",desde);
if(indiceComa!=-1 && indiceEspacio!=-1){
hasta=Math.min(indiceComa, indiceEspacio);
}
else{
hasta=indiceComa==-1?indiceEspacio:indiceComa;
if(hasta==-1 && cuantasVecesHastaEsIgualAMenos1==1){
hasta=longStr;
cuantasVecesHastaEsIgualAMenos1++;
}
}
aunHayPalabrasPorLeer=hasta!=-1;
if(aunHayPalabrasPorLeer){
if(str.charAt(hasta-1)==')'){
hasta--;
}
cadenas.add(str.substring(desde,hasta));
rellenador="";
if(hasta+1"+t+"