List of usage examples for java.lang String matches
public boolean matches(String regex)
From source file:cn.wanghaomiao.seimi.utils.StructValidator.java
public static boolean validateAllowRules(String[] rules, String target) { if (ArrayUtils.isEmpty(rules)) { return true; }/*from w w w . j ava2 s . co m*/ Assert.notNull(target, "rule target can not be null"); for (String rule : rules) { if (target.matches(rule)) { return true; } } return false; }
From source file:cn.wanghaomiao.seimi.utils.StructValidator.java
public static boolean validateDenyRules(String[] rules, String target) { if (ArrayUtils.isEmpty(rules)) { return false; }//from w w w . j a v a 2s .co m Assert.notNull(target, "rule target can not be null"); for (String rule : rules) { if (target.matches(rule)) { return true; } } return false; }
From source file:com.dtolabs.rundeck.core.cli.project.BaseAction.java
protected static BaseActionArgs parseBaseActionArgs(CommandLine cli) { final String project = cli.getOptionValue('p'); // validate that project name is just alpha-numeric if (null != project && !project.matches(FrameworkResource.VALID_RESOURCE_NAME_REGEX)) { throw new ProjectToolException("Error: CreateAction: project names can only contain these characters: " + FrameworkResource.VALID_RESOURCE_NAME_REGEX); }/*from ww w . j a va 2 s .co m*/ return createArgs(project, cli.hasOption('v')); }
From source file:com.csc.fi.ioapi.utils.LDHelper.java
public static boolean isAlphaString(String name) { return name.matches("[a-zA-Z]+"); }
From source file:Main.java
/** * Checks if a participant is excluded./*from w w w.j av a 2 s. c o m*/ * * @param botNameVersion the name and version of the participant. * @return true if the participant is excluded; false otherwise. */ public static boolean isExcluded(String botNameVersion) { if (excludes == null) { return false; } // Check the name against all exclude filters for (int i = excludes.length - 1; i >= 0; i--) { try { if (botNameVersion.matches(excludes[i])) { return true; } } catch (java.util.regex.PatternSyntaxException e) { // Clear the current exclude if the syntax is illegal (for next time this method is called) excludes[i] = ""; } } // Not excluded return false; }
From source file:eu.digitisation.idiomaident.utils.CorpusFilter.java
private static HashSet getPosibleNames(String text) { HashSet<String> posibleNames = new HashSet(); try {/* w w w . j a v a 2 s.c o m*/ WordScanner scanner = new WordScanner(text); String word = ""; while ((word = scanner.nextWord()) != null) { //check the first letter if (word.matches("\\p{Upper}+.*")) { posibleNames.add(word); } } return posibleNames; } catch (IOException ex) { System.out.println(ex.toString()); } return null; }
From source file:adams.data.image.ImageMetaDataHelper.java
/** * Fixes date/time strings. Replaces the ":" in the date with "-" to be * ADAMS compatible.// w w w . j a v a 2s .c o m * * @param s the string to inspect * @return the (potentially) fixed string */ protected static String fixDateTime(String s) { String result; if (s.matches(DATETIME_MASK)) result = s.replaceAll(DATETIME_MASK, "$1-$2-$3 $4:$5:$6"); else result = s; return result; }
From source file:com.microsoftopentechnologies.windowsazurestorage.helper.Utils.java
/** * Check for the validity of file share name. Rules: * 1. must be from 3 through 63 characters long * 2. can contain only lowercase letters, numbers, and hyphens * 3. must begin and end with a letter or a number. * 4. cannot contain two consecutive hyphens. * @param fileShareName/*from w ww.j av a2 s . c om*/ * @return */ public static boolean validateFileShareName(final String fileShareName) { return StringUtils.isNotBlank(fileShareName) && fileShareName.matches(Constants.VAL_SHARE_NAME); }
From source file:de.jaetzold.philips.hue.HueBridgeComm.java
static List<HueBridge> discover() { final Logger log = Logger.getLogger(HueBridge.class.getName()); final SimpleServiceDiscovery serviceDiscovery = new SimpleServiceDiscovery(); int attempted = 0; int maxAttempts = Math.min(4, Math.max(1, HueBridge.discoveryAttempts)); Map<String, URL> foundBriges = new HashMap<>(); // if nothing is found the first time try up to maxAttempts times with increasing timeouts while (foundBriges.isEmpty() && attempted < maxAttempts) { serviceDiscovery.setSearchMx(1 + attempted); serviceDiscovery.setSocketTimeout(500 + attempted * 1500); final List<? extends SimpleServiceDiscovery.Response> responses = serviceDiscovery .discover(SimpleServiceDiscovery.SEARCH_TARGET_ROOTDEVICE); try {/* w w w .j a v a 2s. c o m*/ for (SimpleServiceDiscovery.Response response : responses) { String urlBase = null; final String usn = response.getHeader("USN"); if (usn != null && usn.matches("uuid:[-\\w]+")) { if (!foundBriges.containsKey(usn)) { final String server = response.getHeader("SERVER"); if (server != null && server.contains("IpBridge")) { final String location = response.getHeader("LOCATION"); if (location != null && location.endsWith(".xml")) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new URL(location).openStream()); final NodeList modelNames = doc.getElementsByTagName("modelName"); for (int i = 0; i < modelNames.getLength(); i++) { final Node item = modelNames.item(i); if (item.getParentNode().getNodeName().equals("device") && item .getTextContent().matches("(?i).*philips\\s+hue\\s+bridge.*")) { final NodeList urlBases = doc.getElementsByTagName("URLBase"); if (urlBases.getLength() > 0) { urlBase = urlBases.item(0).getTextContent(); break; } } } } } } } if (urlBase != null) { foundBriges.put(usn, new URL(urlBase)); } } } catch (Exception e) { HueBridge.lastDiscoveryException = e; log.log(Level.INFO, "Exception when dicovering devices", e); } attempted++; } List<HueBridge> result = new ArrayList<>(); for (Map.Entry<String, URL> entry : foundBriges.entrySet()) { final HueBridge bridge = new HueBridge(entry.getValue(), null); bridge.UDN = entry.getKey(); result.add(bridge); } return result; }
From source file:at.illecker.sentistorm.commons.util.io.IOUtils.java
public static InputStream getInputStream(String fileOrUrl, boolean unzip) { InputStream in = null;/*from w w w .ja va 2s . c o m*/ try { if (fileOrUrl.matches("https?://.*")) { URL u = new URL(fileOrUrl); URLConnection uc = u.openConnection(); in = uc.getInputStream(); } else { // 1) check if file is within jar in = IOUtils.class.getClassLoader().getResourceAsStream(fileOrUrl); // windows File.separator is \, but getting resources only works with / if (in == null) { in = IOUtils.class.getClassLoader().getResourceAsStream(fileOrUrl.replaceAll("\\\\", "/")); } // 2) if not found in jar, load from the file system if (in == null) { in = new FileInputStream(fileOrUrl); } } // unzip if necessary if ((unzip) && (fileOrUrl.endsWith(".gz"))) { in = new GZIPInputStream(in, GZIP_FILE_BUFFER_SIZE); } // buffer input stream in = new BufferedInputStream(in); } catch (FileNotFoundException e) { LOG.error("FileNotFoundException: " + e.getMessage()); } catch (IOException e) { LOG.error("IOException: " + e.getMessage()); } return in; }