TreeRewriteRule implements TreeRewriter<V>, Serializable { public static <V> TreeRewriteRule<V> parse( final String rule, final Function<? super String, ? extends V> mapper ) { final String[] parts = rule.split("->"); if (parts.length == 1) { throw new IllegalArgumentException(format( "Invalid rewrite rule; missing separator '->': %s", rule )); } if (parts.length > 2) { throw new IllegalArgumentException(format( "Invalid rewrite rule; found %d separators '->': %s", parts.length - 1, rule )); } return new TreeRewriteRule<>( TreePattern.compile(parts[0], mapper), TreePattern.compile(parts[1], mapper) ); } TreeRewriteRule(
		final TreePattern<V> left,
		final TreePattern<V> right
	); TreePattern<V> left(); TreePattern<V> right(); TreeRewriteRule<B> map(final Function<? super V, ? extends B> mapper); @Override int rewrite(final TreeNode<V> tree, final int limit); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); static TreeRewriteRule<V> parse(
		final String rule,
		final Function<? super String, ? extends V> mapper
	); static TreeRewriteRule<String> parse(final String rule);  }
@Test public void serialize() throws IOException { final TreeRewriteRule<String> rule = TreeRewriteRule.parse("mul($x,$x) -> pow($x,2)"); final byte[] data = IO.object.toByteArray(rule); Assert.assertEquals(IO.object.fromByteArray(data), rule); }