Java Code Examples for java.util.regex.Pattern#toString()

The following examples show how to use java.util.regex.Pattern#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that waits for the current page URL
 * to match the provided regular expression.
 */
public static ExpectedCondition<Boolean> urlToMatch(final Pattern regexPattern) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            String url = driver.getCurrentUrl();
            Boolean matches = regexPattern.matcher(url).matches();
            return matches;
        }

        @Override
        public String toString() {
            return "current page URL to match: " + regexPattern.toString();
        }
    };
}
 
Example 2
Source File: KylinConfig.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private static String getFileName(String homePath, Pattern pattern) {
    File home = new File(homePath);
    SortedSet<String> files = Sets.newTreeSet();
    if (home.exists() && home.isDirectory()) {
        for (File file : home.listFiles()) {
            final Matcher matcher = pattern.matcher(file.getName());
            if (matcher.matches()) {
                files.add(file.getAbsolutePath());
            }
        }
    }
    if (files.isEmpty()) {
        throw new RuntimeException("cannot find " + pattern.toString() + " in " + homePath);
    } else {
        return files.last();
    }
}
 
Example 3
Source File: Strings.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public static String concat(Object[] s, Pattern t) {
    String sepstr = t.toString();
    int len = 0;
    for (int i = 0; i < s.length; i++) {
        if (s[i] != null) {
            len += s[i].toString().length();
        } else {
            len += 4;
        }
    }
    len += ((s.length - 1) * t.toString().length());


    StringBuilder output = new StringBuilder(len);
    for (int i = 0; i < s.length; i++) {
        if (i == 0) {
            output.append(s[i].toString());
        } else {
            output.append(sepstr).append(s[i].toString());
        }
    }
    return output.toString();
}
 
Example 4
Source File: Game.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/**
 * checkWin - has anyone won.
 */
public void checkWin() {
  final Pattern[] wins;
  if (moveX) {
    wins = XWins;
  } else {
    wins = OWins;
  }

  for (Pattern winPattern : wins) {
    if (winPattern.matcher(board).matches()) {
      if (moveX) {
        winner = userX;
      } else {
        winner = userO;
      }
      winningBoard = winPattern.toString();
    }
  }
}
 
Example 5
Source File: PostgreSQLFunctionNotificationParser.java    From binnavi with Apache License 2.0 6 votes vote down vote up
private FunctionNotificationContainer parseFunctionNotification(final PGNotification notification,
    final SQLProvider provider) {

  final Pattern pattern = Pattern.compile(functionNotificationPattern);
  final Matcher matcher = pattern.matcher(notification.getParameter());
  if (!matcher.find()) {
    throw new IllegalStateException("IE02739: compiled pattern: " + pattern.toString()
        + " did not match notification: " + notification.getParameter());
  }

  final String databaseOperation = matcher.group(2);
  final Integer moduleId = Integer.parseInt(matcher.group(3));
  final IAddress functionAddress = new CAddress(new BigInteger(matcher.group(4)));
  final INaviModule module = provider.findModule(moduleId);
  return new FunctionNotificationContainer(moduleId, module, functionAddress, databaseOperation);
}
 
Example 6
Source File: AknProxyItemProvider.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This returns the label styled text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object getStyledText ( Object object )
{
    Pattern labelValue = ( (AknProxy)object ).getPattern ();
    String label = labelValue == null ? null : labelValue.toString ();
    StyledString styledLabel = new StyledString ();
    if ( label == null || label.length () == 0 )
    {
        styledLabel.append ( getString ( "_UI_AknProxy_type" ), StyledString.Style.QUALIFIER_STYLER ); //$NON-NLS-1$
    }
    else
    {
        styledLabel.append ( getString ( "_UI_AknProxy_type" ), StyledString.Style.QUALIFIER_STYLER ).append ( " " + label ); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return styledLabel;
}
 
Example 7
Source File: Strings.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public static String concat(String[] s, Pattern t) {
    String sepstr = t.toString();
    int len = 0;
    for (int i = 0; i < s.length; i++) {
        if (s[i] != null) {
            len += s[i].length();
        } else {
            len += 4;
        }
    }
    len += ((s.length - 1) * sepstr.length());

    StringBuilder output = new StringBuilder(len);
    for (int i = 0; i < s.length; i++) {
        if (i == 0) {
            output.append(s[i]);
        } else {
            output.append(sepstr).append(s[i]);
        }
    }
    return output.toString();
}
 
Example 8
Source File: ExcludeItemProvider.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This returns the label styled text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object getStyledText ( Object object )
{
    Pattern labelValue = ( (Exclude)object ).getPattern ();
    String label = labelValue == null ? null : labelValue.toString ();
    StyledString styledLabel = new StyledString ();
    if ( label == null || label.length () == 0 )
    {
        styledLabel.append ( getString ( "_UI_Exclude_type" ), StyledString.Style.QUALIFIER_STYLER ); //$NON-NLS-1$
    }
    else
    {
        styledLabel.append ( getString ( "_UI_Exclude_type" ), StyledString.Style.QUALIFIER_STYLER ).append ( " " + label ); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return styledLabel;
}
 
Example 9
Source File: PatternFilterItemProvider.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This returns the label styled text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object getStyledText ( Object object )
{
    Pattern labelValue = ( (PatternFilter)object ).getPattern ();
    String label = labelValue == null ? null : labelValue.toString ();
    StyledString styledLabel = new StyledString ();
    if ( label == null || label.length () == 0 )
    {
        styledLabel.append ( getString ( "_UI_PatternFilter_type" ), StyledString.Style.QUALIFIER_STYLER ); //$NON-NLS-1$
    }
    else
    {
        styledLabel.append ( getString ( "_UI_PatternFilter_type" ), StyledString.Style.QUALIFIER_STYLER ).append ( " " + label ); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return styledLabel;
}
 
Example 10
Source File: IncludeItemProvider.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This returns the label styled text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object getStyledText ( Object object )
{
    Pattern labelValue = ( (Include)object ).getPattern ();
    String label = labelValue == null ? null : labelValue.toString ();
    StyledString styledLabel = new StyledString ();
    if ( label == null || label.length () == 0 )
    {
        styledLabel.append ( getString ( "_UI_Include_type" ), StyledString.Style.QUALIFIER_STYLER ); //$NON-NLS-1$
    }
    else
    {
        styledLabel.append ( getString ( "_UI_Include_type" ), StyledString.Style.QUALIFIER_STYLER ).append ( " " + label ); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return styledLabel;
}
 
Example 11
Source File: KylinConfigBase.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static String getFileName(String homePath, Pattern pattern) {
    File home = new File(homePath);
    SortedSet<String> files = Sets.newTreeSet();
    if (home.exists() && home.isDirectory()) {
        File[] listFiles = home.listFiles();
        if (listFiles != null) {
            for (File file : listFiles) {
                final Matcher matcher = pattern.matcher(file.getName());
                if (matcher.matches()) {
                    files.add(file.getAbsolutePath());
                }
            }
        }
    }
    if (files.isEmpty()) {
        throw new RuntimeException("cannot find " + pattern.toString() + " in " + homePath);
    } else {
        return files.last();
    }
}
 
Example 12
Source File: RuleItemProvider.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected String getTextFor ( final Pattern pattern )
{
    if ( pattern == null )
    {
        return null;
    }
    else
    {
        return pattern.toString ();
    }
}
 
Example 13
Source File: CustomObjectInputStream.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Construct a new instance of CustomObjectInputStream with filtering of
 * deserialized classes.
 *
 * @param stream The input stream we will read from
 * @param classLoader The class loader used to instantiate objects
 * @param log The logger to use to report any issues. It may only be null if
 *            the filterMode does not require logging
 * @param allowedClassNamePattern The regular expression to use to filter
 *                                deserialized classes. The fully qualified
 *                                class name must match this pattern for
 *                                deserialization to be allowed if filtering
 *                                is enabled.
 * @param warnOnFailure Should any failures be logged?
 *
 * @exception IOException if an input/output error occurs
 */
public CustomObjectInputStream(InputStream stream, ClassLoader classLoader,
        Log log, Pattern allowedClassNamePattern, boolean warnOnFailure)
        throws IOException {
    super(stream);
    if (log == null && allowedClassNamePattern != null && warnOnFailure) {
        throw new IllegalArgumentException(
                sm.getString("customObjectInputStream.logRequired"));
    }
    this.classLoader = classLoader;
    this.log = log;
    this.allowedClassNamePattern = allowedClassNamePattern;
    if (allowedClassNamePattern == null) {
        this.allowedClassNameFilter = null;
    } else {
        this.allowedClassNameFilter = allowedClassNamePattern.toString();
    }
    this.warnOnFailure = warnOnFailure;

    Set<String> reportedClasses;
    synchronized (reportedClassCache) {
        reportedClasses = reportedClassCache.get(classLoader);
    }
    if (reportedClasses == null) {
        reportedClasses = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>());
        synchronized (reportedClassCache) {
            Set<String> original = reportedClassCache.get(classLoader);
            if (original == null) {
                reportedClassCache.put(classLoader, reportedClasses);
            } else {
                // Concurrent attempts to create the new Set. Make sure all
                // threads use the first successfully added Set.
                reportedClasses = original;
            }
        }
    }
    this.reportedClasses = reportedClasses;
}
 
Example 14
Source File: CustomObjectInputStream.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new instance of CustomObjectInputStream with filtering of
 * deserialized classes.
 *
 * @param stream The input stream we will read from
 * @param classLoader The class loader used to instantiate objects
 * @param log The logger to use to report any issues. It may only be null if
 *            the filterMode does not require logging
 * @param allowedClassNamePattern The regular expression to use to filter
 *                                deserialized classes. The fully qualified
 *                                class name must match this pattern for
 *                                deserialization to be allowed if filtering
 *                                is enabled.
 * @param warnOnFailure Should any failures be logged?
 *
 * @exception IOException if an input/output error occurs
 */
public CustomObjectInputStream(InputStream stream, ClassLoader classLoader,
        Log log, Pattern allowedClassNamePattern, boolean warnOnFailure)
        throws IOException {
    super(stream);
    if (log == null && allowedClassNamePattern != null && warnOnFailure) {
        throw new IllegalArgumentException(
                sm.getString("customObjectInputStream.logRequired"));
    }
    this.classLoader = classLoader;
    this.log = log;
    this.allowedClassNamePattern = allowedClassNamePattern;
    if (allowedClassNamePattern == null) {
        this.allowedClassNameFilter = null;
    } else {
        this.allowedClassNameFilter = allowedClassNamePattern.toString();
    }
    this.warnOnFailure = warnOnFailure;

    Set<String> reportedClasses;
    synchronized (reportedClassCache) {
        reportedClasses = reportedClassCache.get(classLoader);
        if (reportedClasses == null) {
            reportedClasses = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>());
            reportedClassCache.put(classLoader, reportedClasses);
        }
    }
    this.reportedClasses = reportedClasses;
}
 
Example 15
Source File: OpenAPI3PathResolverTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveEmptyStringQuoting() {
  OpenAPI3PathResolver resolver = instantiatePathResolver("path_multi_simple_label");
  Optional<Pattern> optional = resolver.solve();
  Pattern p = optional.get();
  String pattern = p.toString();
  assertThat(pattern.contains("\\Q\\E")).isFalse();
}
 
Example 16
Source File: CardTypeTest.java    From android-card-form with MIT License 5 votes vote down vote up
@Test
public void allParametersSane() {
    for (final CardType cardType : CardType.values()) {
        final int minCardLength = cardType.getMinCardLength();
        assertTrue(String.format("%s: Min card length %s too small",
                cardType, minCardLength), minCardLength >= MIN_MIN_CARD_LENGTH);

        final int maxCardLength = cardType.getMaxCardLength();
        assertTrue(String.format("%s: Max card length %s too large",
                cardType, maxCardLength), maxCardLength <= MAX_MAX_CARD_LENGTH);

        assertTrue(String.format("%s: Min card length %s greater than its max %s",
                        cardType, minCardLength, maxCardLength),
                minCardLength <= maxCardLength
        );

        final int securityCodeLength = cardType.getSecurityCodeLength();
        assertTrue(String.format("%s: Unusual security code length %s",
                        cardType, securityCodeLength),
                securityCodeLength >= MIN_SECURITY_CODE_LENGTH &&
                        securityCodeLength <= MAX_SECURITY_CODE_LENGTH
        );

        assertTrue(String.format("%s: No front resource declared", cardType),
                cardType.getFrontResource() != 0);
        assertTrue(String.format("%s: No Security code resource declared", cardType),
                cardType.getSecurityCodeName() != 0);

        if (cardType != CardType.UNKNOWN && cardType != CardType.EMPTY) {
            final Pattern pattern = cardType.getPattern();
            final String regex = pattern.toString();
            assertTrue(String.format("%s: Pattern must start with ^", cardType),
                    regex.startsWith("^"));
            assertTrue(String.format("%s: Pattern must end with \\d*", cardType),
                    regex.endsWith("\\d*"));
        }
    }
}
 
Example 17
Source File: OpenAPI3PathResolverTest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotHaveEmptyStringQuoting() {
  OpenAPI3PathResolver resolver = instantiatePathResolver("path_multi_simple_label");
  Optional<Pattern> optional = resolver.solve();
  Pattern p = optional.get();
  String pattern = p.toString();
  assertFalse(pattern.contains("\\Q\\E"));
}
 
Example 18
Source File: Container.java    From spring-localstack with Apache License 2.0 5 votes vote down vote up
/**
 * Poll the docker logs until a specific token appears, then return.  Primarily used to look
 * for the "Ready." token in the localstack logs.
 */
public void waitForLogToken(Pattern pattern) {
    int attempts = 0;
    do {
        if(logContainsPattern(pattern)) {
            return;
        }
        waitForLogs();
        attempts++;
    }
    while(attempts < MAX_LOG_COLLECTION_ATTEMPTS);

    throw new IllegalStateException("Could not find token: " + pattern.toString() + " in docker logs.");
}
 
Example 19
Source File: RegexTypeHandler.java    From mongodb-orm with Apache License 2.0 4 votes vote down vote up
@Override
public Object resovleValue(Pattern target) {
  return target.toString();
}
 
Example 20
Source File: Projection.java    From orientqb with Apache License 2.0 4 votes vote down vote up
public Clause matches(Pattern pattern) {
	return new AtomicClause(this, Operator.MATCHES, pattern.toString());
}