本文整理汇总了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()));
}