List of usage examples for java.lang String matches
public boolean matches(String regex)
From source file:eu.annocultor.converters.solr.SolrPeriodsTagger.java
static Date parseDate(String dateString, String affixToTryOnYearOnly) { try {/*from ww w . j a v a 2s . c o m*/ if (dateString.length() == 4 && dateString.matches("\\d\\d\\d\\d")) { dateString += affixToTryOnYearOnly; } DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); if (StringUtils.isEmpty(dateString)) { return null; } return dateFormat.parse(dateString); } catch (Exception e) { System.out.println(e.getMessage()); return null; } }
From source file:com.minlia.cloud.framework.common.util.SearchCommonUtil.java
public static List<Triple<String, ClientOperation, String>> parseQueryString(final String queryString) { Preconditions.checkNotNull(queryString); Preconditions.checkState(queryString.matches("((id~?=[0-9]+)?,?)*((name~?=[0-9a-zA-Z\\-_/*]+),?)*")); final List<Triple<String, ClientOperation, String>> tuplesList = Lists.newArrayList(); final String[] tuples = queryString.split(QueryConstants.SEPARATOR); for (final String tuple : tuples) { final String[] keyAndValue = tuple.split(QueryConstants.OP); Preconditions.checkState(keyAndValue.length == 2); tuplesList.add(createConstraintFromUriParam(keyAndValue[0], keyAndValue[1])); }//from w ww. j a v a 2s .c o m return tuplesList; }
From source file:com.genentech.chemistry.openEye.apps.SDFMCSSSphereExclusion.java
/** * Construct the ComparatorFactory from the command line options *///from www. ja v a 2 s . co m private static SimComparatorFactory<OEMolBase, OEMolBase, SimComparator<OEMolBase>> getComparatorFactory( CommandLine cmd) { SimComparatorFactory<OEMolBase, OEMolBase, SimComparator<OEMolBase>> compFact; if (cmd.hasOption("AAPathSim")) { String aaPathSimType = cmd.getOptionValue("AAPathSim"); int version = AAPathComparatorFact.DEFAULTVersion; if (aaPathSimType.matches(".*\\d")) { version = aaPathSimType.charAt(aaPathSimType.length() - 1) - '0'; aaPathSimType = aaPathSimType.substring(0, aaPathSimType.length() - 1); } AAPathCompareType type = AAPathCompareType.valueOf(aaPathSimType); compFact = new AAPathComparatorFact(type, version); } else { compFact = new MCSSComparatorFact(MCSSCompareType.DEFAULT); } return compFact; }
From source file:io.woolford.processors.nifibenford.BenfordsLaw.java
private static long[] getFirstDigitArray(String input) { String[] inputArray = input.split("\\s+"); long[] firstDigitArray = new long[9]; for (String elem : inputArray) { String firstChar = String.valueOf(elem.charAt(0)); boolean isDigit = firstChar.matches("[1-9]{1}"); if (isDigit) { firstDigitArray[Integer.parseInt(firstChar) - 1] = firstDigitArray[Integer.parseInt(firstChar) - 1] + 1;/*from w w w. j a va 2s. co m*/ } } return firstDigitArray; }
From source file:Main.java
public static boolean isEmailAdd(String email) { String emailRegex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; if (TextUtils.isEmpty(email)) return false; else/*from ww w. jav a 2s. c o m*/ return email.matches(emailRegex); }
From source file:keywhiz.utility.SecretTemplateCompiler.java
public static boolean validName(String name) { // "." is allowed at any position but the first. return !name.isEmpty() && !name.startsWith(".") && name.matches(VALID_NAME_PATTERN); }
From source file:Main.java
public static String url(String baseUrl, String relativePath) { if (relativePath == null || relativePath.length() == 0) { return relativePath; }/*from w w w . j a va 2s. c om*/ if (relativePath.contains("://") || relativePath.matches("(?s)^[a-zA-Z][a-zA-Z0-9+-.]*:.*$")) { // matches Non-relative URI; see rfc3986 return relativePath; } if (relativePath.charAt(0) == '/') { int index = baseUrl.indexOf("://"); index = baseUrl.indexOf("/", index + 3); if (index == -1) { return baseUrl + relativePath; } else { return baseUrl.substring(0, index) + relativePath; } } else { int index = baseUrl.lastIndexOf('/'); // FIXME: if (baseUrl.charAt(baseUrl.length() - 1) == '/') while (index > 0 && relativePath.startsWith("../")) { index = baseUrl.lastIndexOf('/', index - 1); relativePath = relativePath.substring(3); } return baseUrl.substring(0, index + 1) + relativePath; } }
From source file:Main.java
public static String assetFile2Str(Context c, String urlStr) { InputStream in = null;/*from ww w . j a v a 2 s. c om*/ try { in = c.getAssets().open(urlStr); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); String line = null; StringBuilder sb = new StringBuilder(); do { line = bufferedReader.readLine(); if (line != null && !line.matches("^\\s*\\/\\/.*")) { sb.append(line); } } while (line != null); bufferedReader.close(); in.close(); return sb.toString(); } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } return null; }
From source file:com.yahoo.sql4dclient.BeanGenUtil.java
private static Map<String, String> getFields(String rawFields) { Map<String, String> fields = new HashMap<>(); String[] args = rawFields.split(","); for (String arg : args) { Matcher fMatcher = fieldPattern.matcher(arg); if (fMatcher.matches()) { String actual = fMatcher.group(1).trim(); String alias = fMatcher.group(3).trim(); if (actual.matches("(COUNT|count)\\(\\*\\)(.*)")) { fields.put(alias, "long"); } else if (actual.matches("(LONG_SUM|long_sum)\\((.*)\\)(.*)")) { fields.put(alias, "long"); } else if (actual.matches("(DOUBLE_SUM|double_sum)\\((.*)\\)(.*)")) { fields.put(alias, "double"); } else { fields.put(alias, "String"); }//from w ww . ja va 2 s.co m } else {// Type cannot be inferred. fields.put(arg.trim(), "String"); } } return fields; }
From source file:fr.avianey.androidsvgdrawable.QualifiedResource.java
/** * Create a {@link QualifiedResource} from an input SVG file. * @param file/*from w w w. j ava2 s . c o m*/ * @return */ public static final QualifiedResource fromFile(final File file) { Preconditions.checkNotNull(file); final String fileName = FilenameUtils.getBaseName(file.getAbsolutePath()); Preconditions.checkArgument(fileName.length() > 0); Preconditions.checkArgument(fileName.indexOf("-") > 0); // unqualified name final String unqualifiedName = fileName.substring(0, fileName.indexOf("-")); Preconditions.checkArgument(unqualifiedName != null && unqualifiedName.matches("\\w+")); // qualifiers final EnumMap<Type, String> typedQualifiers = Qualifier .fromQualifiedString(fileName.substring(fileName.indexOf("-") + 1)); // a density qualifier must be provided Preconditions.checkNotNull(typedQualifiers.get(Type.density)); return new QualifiedResource(file, unqualifiedName, typedQualifiers); }