本文整理匯總了Java中java.util.regex.Pattern.pattern方法的典型用法代碼示例。如果您正苦於以下問題:Java Pattern.pattern方法的具體用法?Java Pattern.pattern怎麽用?Java Pattern.pattern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.regex.Pattern
的用法示例。
在下文中一共展示了Pattern.pattern方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ofMatcher
import java.util.regex.Pattern; //導入方法依賴的package包/類
public static XmEntityKey ofMatcher(String xmKey, Pattern pattern) {
Objects.requireNonNull(xmKey, "XM entity key can't be null");
Matcher xmKeyMatcher = pattern.matcher(xmKey);
if (!xmKeyMatcher.matches()) {
// add more appropriate exception ...
throw new BusinessException("XM entity key '" + xmKey + "' doesn't match pattern: "
+ pattern.pattern());
}
int count = xmKeyMatcher.groupCount();
String groups[] = new String[count];
for (int i = 0; i < count; i++) {
groups[i] = xmKeyMatcher.group(i + 1);
}
return new XmEntityKey(xmKey, groups);
}
示例2: testGetParameterizedMartini
import java.util.regex.Pattern; //導入方法依賴的package包/類
@SuppressWarnings("Guava")
@Test
public void testGetParameterizedMartini() throws NoSuchMethodException {
String id = "Parameterized_Method_Calls:A_Parameterized_Case:25";
Martini martini = getMartini(id);
checkState(null != martini, "no Martini found matching ID [%s]", id);
Map<Step, StepImplementation> stepIndex = martini.getStepIndex();
Collection<StepImplementation> implementations = stepIndex.values();
ImmutableList<StepImplementation> filtered = FluentIterable.from(implementations)
.filter(notNull())
.filter(Predicates.not(Predicates.instanceOf(UnimplementedStep.class)))
.toList();
assertFalse(filtered.isEmpty(), "expected at least one implementation");
StepImplementation givenImplementation = filtered.get(0);
Pattern pattern = givenImplementation.getPattern();
assertNotNull(pattern, "expected implementation to have a Pattern");
String regex = pattern.pattern();
assertEquals(regex, "^a pre-existing condition known as \"(.+)\"$", "Pattern contains wrong regex");
Method method = givenImplementation.getMethod();
Method expected = ParameterizedTestSteps.class.getDeclaredMethod("aPreExistingConditionKnownAs", String.class);
assertEquals(method, expected, "implementation contains wrong Method");
}
示例3: getNoKeepAliveUserAgents
import java.util.regex.Pattern; //導入方法依賴的package包/類
public String getNoKeepAliveUserAgents() {
Pattern p = noKeepAliveUserAgents;
if (p == null) {
return null;
} else {
return p.pattern();
}
}
示例4: getValueAt
import java.util.regex.Pattern; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
final Pattern pattern = patterns.get(rowIndex);
if (columnIndex == 0) {
return pattern.pattern();
}
return "??";
}
示例5: testMultipleGivenRegex
import java.util.regex.Pattern; //導入方法依賴的package包/類
@Test
public void testMultipleGivenRegex() throws NoSuchMethodException {
MultipleGivenBean source = new MultipleGivenBean();
ClassPathXmlApplicationContext context = getContext(source);
process(context, source);
MultipleGivenBean steps = context.getBean(MultipleGivenBean.class);
Class<?> wrapped = AopUtils.getTargetClass(steps);
Method method = wrapped.getMethod("doSomething");
Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class);
Collection<StepImplementation> givens = givenBeanIndex.values();
Set<String> matches = Sets.newHashSetWithExpectedSize(2);
for (StepImplementation given : givens) {
Method givenMethod = given.getMethod();
if (givenMethod.equals(method)) {
Pattern pattern = given.getPattern();
String regex = pattern.pattern();
matches.add(regex);
}
}
int count = matches.size();
assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()");
Set<String> expected = Sets.newHashSet(
"this is regular expression one", "this is regular expression two");
assertEquals(matches, expected, "Steps contain wrong regex Pattern objects");
}
示例6: parseStringAttr
import java.util.regex.Pattern; //導入方法依賴的package包/類
private static String parseStringAttr(String line, Pattern pattern) throws ParserException {
Matcher matcher = pattern.matcher(line);
if (matcher.find() && matcher.groupCount() == 1) {
return matcher.group(1);
}
throw new ParserException("Couldn't match " + pattern.pattern() + " in " + line);
}
示例7: getNoKeepAliveUserAgents
import java.util.regex.Pattern; //導入方法依賴的package包/類
public String getNoKeepAliveUserAgents() {
Pattern p = noKeepAliveUserAgents;
if (p == null) {
return null;
} else {
return p.pattern();
}
}
示例8: getMatch
import java.util.regex.Pattern; //導入方法依賴的package包/類
public String getMatch(Pattern p, String msg) {
Matcher m = p.matcher(msg);
if (!m.find()) throw new RuntimeException("Regexp '" + p.pattern() + "' does not match onto '" + msg + "'.");
return m.group(0);
}
示例9: getAsText
import java.util.regex.Pattern; //導入方法依賴的package包/類
@Override
public String getAsText() {
Pattern value = (Pattern) getValue();
return (value != null ? value.pattern() : "");
}
示例10: setPattern
import java.util.regex.Pattern; //導入方法依賴的package包/類
protected void setPattern() {
Pattern pattern = implementation.getPattern();
String serializedPattern = pattern.pattern();
serialized.addProperty("pattern", serializedPattern);
}
示例11: regexFilterNew
import java.util.regex.Pattern; //導入方法依賴的package包/類
private Filter regexFilterNew(Pattern pattern) {
return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
CompareOp.EQUAL,
new RegexStringComparator(pattern.pattern(), pattern.flags()));
}