List of usage examples for java.lang String matches
public boolean matches(String regex)
From source file:com.jcalvopinam.utils.Utilities.java
/** * Check if the string has a Date format * * @param date// w ww . j ava 2 s. c om * @return */ private static boolean hasFormat(String date) { return date.matches(DATE_MATCH_FORMAT); }
From source file:Main.java
public static Integer getUID(String name) { if (name != null) { if (name.matches("^[0-9]+$")) { return Integer.parseInt(name); }//from w w w . j av a2 s . c om if (UIDS.containsKey(name)) { return UIDS.get(name); } else if (name.startsWith("u")) { Integer sep = name.indexOf("_"); if (sep > 0) { Integer uid = Integer.parseInt(name.substring(1, sep)); Integer gid = Integer.parseInt(name.substring(sep + 2)); return uid * 100000 + ((Process.FIRST_APPLICATION_UID + gid) % 100000); } } } return -10000; }
From source file:com.thinkbiganalytics.nifi.rest.support.NifiTemplateNameUtil.java
/** * Check to see if the incoming name includes a versioned timestamp * * @param name the process group name//from www .jav a 2 s .c om * @return {@code true} if the incoming name contains the version timestamp, {@code false} if the name is not versioned. */ public static boolean isVersionedProcessGroup(String name) { return StringUtils.isNotBlank(name) && name.matches(VERSION_NAME_REGEX); }
From source file:Main.java
public static String camelCaseToSnakeCase(String camelCase) { List<String> tokens = new ArrayList<>(); Matcher matcher = PATTERN.matcher(camelCase); String acronym = ""; while (matcher.find()) { String found = matcher.group(); if (found.matches("^[A-Z]$")) { acronym += found;/*from www . j a va2s . c o m*/ } else { if (acronym.length() > 0) { // we have an acronym to add before we continue tokens.add(acronym); acronym = ""; } tokens.add(found.toLowerCase()); } } if (acronym.length() > 0) { tokens.add(acronym); } if (tokens.size() > 0) { StringBuilder sb = new StringBuilder(tokens.remove(0)); for (String s : tokens) { sb.append("_").append(s); } return sb.toString(); } else { return camelCase; } }
From source file:Main.java
public static Boolean checkemil(String emil) { String str = "[a-zA-Z0-9_]{1,20}@{1}[a-zA-Z0-9]{2,10}(\\.{1}[a-zA-Z]{2,5}){1,5}"; if (!emil.matches(str)) { return false; }/*w w w .jav a 2s . c o m*/ return true; }
From source file:Main.java
public static String camelCaseToSnakeCase(String camelCase) { List<String> tokens = new ArrayList<String>(); Matcher matcher = pattern.matcher(camelCase); String acronym = ""; while (matcher.find()) { String found = matcher.group(); if (found.matches("^[A-Z]$")) { acronym += found;//ww w . j a v a 2s .c o m } else { if (acronym.length() > 0) { // we have an acronym to add before we continue tokens.add(acronym); acronym = ""; } tokens.add(found.toLowerCase()); } } if (acronym.length() > 0) { tokens.add(acronym); } if (tokens.size() > 0) { StringBuilder sb = new StringBuilder(tokens.remove(0)); for (String s : tokens) { sb.append("_").append(s); } return sb.toString(); } else { return camelCase; } }
From source file:Main.java
public static Boolean isNumberLetter(String str) { Boolean isNoLetter = false;/* www . ja v a 2s .c o m*/ String expr = "^[A-Za-z0-9]+$"; if (str.matches(expr)) { isNoLetter = true; } return isNoLetter; }
From source file:Main.java
public static Boolean isNumberOrDouble(String str) { Boolean isNumber = false;/*ww w .j ava2s. c o m*/ String expr = "-?[0-9]+.*[0-9]*"; if (str.matches(expr)) { isNumber = true; } return isNumber; }
From source file:Main.java
/** * When the amount is displayed as a string it is 10.25 but when stored as a * long it needs to be converted to pennies as 1025 * //from www. jav a2 s . com * @param amount * @return */ public static Long convertAmount(String displayAmount) { Long amount = 0L; if (displayAmount != null && displayAmount.matches("^\\d+.\\d\\d$")) { displayAmount = displayAmount.substring(0, displayAmount.length() - 3) + displayAmount.substring(displayAmount.length() - 2, displayAmount.length()); amount = new Long(displayAmount); } return amount; }
From source file:Main.java
static String composeFilesString(final String dirPath, final List<String> subDirPaths, final String pattern, int skip) { final StringBuilder sb = new StringBuilder(); final List<File> allFiles = new ArrayList<>(); final FilenameFilter filter = new FilenameFilter() { @Override/*from w w w .j a v a 2 s.c o m*/ public boolean accept(File dir, String name) { return name.matches(pattern); } }; for (final String subDirPath : subDirPaths) { final File subDir = new File(dirPath, subDirPath); final File[] files = subDir.listFiles(filter); if (files == null) { throw new RuntimeException(String.format("%s directory does not exist", subDir.getPath())); } Arrays.sort(files); Collections.addAll(allFiles, files); } final int m; final int n; if (skip >= 0) { m = skip; n = allFiles.size(); } else { m = 0; n = allFiles.size() + skip; } for (int i = m; i < n; i++) { final File file = allFiles.get(i); if (sb.length() > 0) { sb.append(' '); } sb.append(file.getPath()); } return sb.toString(); }