下面列出了java.util.regex.Pattern#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
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();
}
/**
* 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;
}
/**
* 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();
}
};
}
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);
}
/**
* 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();
}
}
}
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();
}
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();
}
}
/**
* 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;
}
/**
* 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.");
}
@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();
}
protected String getTextFor ( final Pattern pattern )
{
if ( pattern == null )
{
return null;
}
else
{
return pattern.toString ();
}
}
/**
* 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;
}
@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*"));
}
}
}
@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"));
}
@Override
public Object resovleValue(Pattern target) {
return target.toString();
}
public Clause matches(Pattern pattern) {
return new AtomicClause(this, Operator.MATCHES, pattern.toString());
}