@Test public void testTransform() { assertEquals("*", Matcher.all().transform(Functions.constant("foo")).patternString()); assertSame(Matcher.all(), Matcher.all().transform(Functions.constant("bar"))); assertEquals("identity/path", Matcher.of("identity/path").transform(Functions.<String>identity()).patternString()); assertEquals("foo(foo),*", Matcher.of("any(thing),*").transform(Functions.constant("foo")).patternString()); assertEquals("FOO/*,BAR/*(BAZ)", Matcher.of("foo/*,bar/*(baz)").transform(upperCase()).patternString()); }
public Matcher transform(final Function<? super String, String> nameTransformer) { checkNotNull(nameTransformer); if (matchesAll()) { return this; } AstNode ast = getAstNode(); AstNode transformed = new CopyVisitor() { @Override protected Word createWordCopy(String stringValue) { return super.createWordCopy(nameTransformer.apply(stringValue)); } }.applyTo(ast); return new AstMatcher(transformed); }
Matcher implements Predicate<Leaf> { public Matcher transform(final Function<? super String, String> nameTransformer) { checkNotNull(nameTransformer); if (matchesAll()) { return this; } AstNode ast = getAstNode(); AstNode transformed = new CopyVisitor() { @Override protected Word createWordCopy(String stringValue) { return super.createWordCopy(nameTransformer.apply(stringValue)); } }.applyTo(ast); return new AstMatcher(transformed); } }
Matcher implements Predicate<Leaf> { public Matcher transform(final Function<? super String, String> nameTransformer) { checkNotNull(nameTransformer); if (matchesAll()) { return this; } AstNode ast = getAstNode(); AstNode transformed = new CopyVisitor() { @Override protected Word createWordCopy(String stringValue) { return super.createWordCopy(nameTransformer.apply(stringValue)); } }.applyTo(ast); return new AstMatcher(transformed); } Matcher(); }
Matcher implements Predicate<Leaf> { public Matcher transform(final Function<? super String, String> nameTransformer) { checkNotNull(nameTransformer); if (matchesAll()) { return this; } AstNode ast = getAstNode(); AstNode transformed = new CopyVisitor() { @Override protected Word createWordCopy(String stringValue) { return super.createWordCopy(nameTransformer.apply(stringValue)); } }.applyTo(ast); return new AstMatcher(transformed); } Matcher(); static Matcher all(); static Matcher of(CharSequence fields); boolean matchesAll(); abstract boolean matches(Leaf leaf); boolean matches(CharSequence path); abstract boolean matchesParent(Leaf node); boolean matchesParent(CharSequence path); Matcher transform(final Function<? super String, String> nameTransformer); @Override @Deprecated boolean apply(@Nullable Leaf input); @Override String toString(); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); }
Matcher implements Predicate<Leaf> { public Matcher transform(final Function<? super String, String> nameTransformer) { checkNotNull(nameTransformer); if (matchesAll()) { return this; } AstNode ast = getAstNode(); AstNode transformed = new CopyVisitor() { @Override protected Word createWordCopy(String stringValue) { return super.createWordCopy(nameTransformer.apply(stringValue)); } }.applyTo(ast); return new AstMatcher(transformed); } Matcher(); static Matcher all(); static Matcher of(CharSequence fields); boolean matchesAll(); abstract boolean matches(Leaf leaf); boolean matches(CharSequence path); abstract boolean matchesParent(Leaf node); boolean matchesParent(CharSequence path); Matcher transform(final Function<? super String, String> nameTransformer); @Override @Deprecated boolean apply(@Nullable Leaf input); @Override String toString(); @Override boolean equals(@Nullable Object obj); @Override int hashCode();  }