Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–24 unchanged (24 lines)
25 *
26 * @since 3.0
27 * @version $Id$
28 */
29public class LookupTranslator extends CharSequenceTranslator {
30
31 private final HashMap<CharSequence, CharSequence> lookupMap;
32 private final int shortest;
33 private final int longest;
34
35 /**
36 * Define the lookup table to be used in translation
37 *
38 * Note that, as of Lang 3.1, the key to the lookup table is converted to a
39 * java.lang.String, while the value remains as a java.lang.CharSequence.
40 * This is because we need the key to support hashCode and equals(Object),
41 * allowing it to be the key for a HashMap. See LANG-882.
42 *
43 * @param lookup CharSequence[][] table of size [*][2]
44 */
45 public LookupTranslator(final CharSequence[]... lookup) {
46 lookupMap = new HashMap<CharSequence, CharSequence>();
47 int _shortest = Integer.MAX_VALUE;
48 int _longest = 0;
49 if (lookup != null) {
50 for (final CharSequence[] seq : lookup) {
51 this.lookupMap.put(seq[0], seq[1]);
52 final int sz = seq[0].length();
53 if (sz < _shortest) {
54 _shortest = sz;
55 }
56 if (sz > _longest) {
57 _longest = sz;
…lines 58–70 unchanged (13 lines)
71 if (index + longest > input.length()) {
72 max = input.length() - index;
73 }
74 // descend so as to get a greedy algorithm
75 for (int i = max; i >= shortest; i--) {
76 final CharSequence subSeq = input.subSequence(index, index + i);
77 final CharSequence result = lookupMap.get(subSeq);
78 if (result != null) {
79 out.write(result.toString());
80 return i;
81 }
82 }
83 return 0;
84 }
85}
86

After

…lines 1–24 unchanged (24 lines)
25 *
26 * @since 3.0
27 * @version $Id$
28 */
29public class LookupTranslator extends CharSequenceTranslator {
30
31 private final HashMap<String, CharSequence> lookupMap;
32 private final int shortest;
33 private final int longest;
34
35 /**
36 * Define the lookup table to be used in translation
37 *
38 * Note that, as of Lang 3.1, the key to the lookup table is converted to a
39 * java.lang.String, while the value remains as a java.lang.CharSequence.
40 * This is because we need the key to support hashCode and equals(Object),
41 * allowing it to be the key for a HashMap. See LANG-882.
42 *
43 * @param lookup CharSequence[][] table of size [*][2]
44 */
45 public LookupTranslator(final CharSequence[]... lookup) {
46 lookupMap = new HashMap<String, CharSequence>();
47 int _shortest = Integer.MAX_VALUE;
48 int _longest = 0;
49 if (lookup != null) {
50 for (final CharSequence[] seq : lookup) {
51 this.lookupMap.put(seq[0].toString(), seq[1]);
52 final int sz = seq[0].length();
53 if (sz < _shortest) {
54 _shortest = sz;
55 }
56 if (sz > _longest) {
57 _longest = sz;
…lines 58–70 unchanged (13 lines)
71 if (index + longest > input.length()) {
72 max = input.length() - index;
73 }
74 // descend so as to get a greedy algorithm
75 for (int i = max; i >= shortest; i--) {
76 final CharSequence subSeq = input.subSequence(index, index + i);
77 final CharSequence result = lookupMap.get(subSeq.toString());
78 if (result != null) {
79 out.write(result.toString());
80 return i;
81 }
82 }
83 return 0;
84 }
85}
86

Before

program
block_comment "/*\n * Licensed to the Apache Software Foundation (ASF) under"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "lang3"
. "."
identifier "text"
. "."
identifier "translate"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "IOException"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "Writer"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "HashMap"
; ";"
block_comment "/**\n * Translates a value using a lookup table.\n *\n * @since"...
class_declaration
modifiers
public "public"
class "class"
identifier "LookupTranslator"
superclass
extends "extends"
type_identifier "CharSequenceTranslator"
class_body
{ "{"
field_declaration
modifiers
private "private"
final "final"
generic_type
type_identifier "HashMap"
type_arguments
< "<"
type_identifier "CharSequence"
, ","
type_identifier "CharSequence"
> ">"
variable_declarator
identifier "lookupMap"
; ";"
field_declaration
modifiers
private "private"
final "final"
integral_type
int "int"
variable_declarator
identifier "shortest"
; ";"
field_declaration
modifiers
private "private"
final "final"
integral_type
int "int"
variable_declarator
identifier "longest"
; ";"
block_comment "/**\n * Define the lookup table to be used in translation"...
constructor_declaration
modifiers
public "public"
identifier "LookupTranslator"
formal_parameters
( "("
spread_parameter
modifiers
final "final"
array_type
type_identifier "CharSequence"
dimensions
[ "["
] "]"
... "..."
variable_declarator
identifier "lookup"
) ")"
constructor_body
{ "{"
expression_statement
assignment_expression
identifier "lookupMap"
= "="
object_creation_expression
new "new"
generic_type
type_identifier "HashMap"
type_arguments
< "<"
type_identifier "CharSequence"
, ","
type_identifier "CharSequence"
> ">"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "_shortest"
= "="
field_access
identifier "Integer"
. "."
identifier "MAX_VALUE"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "_longest"
= "="
decimal_integer_literal "0"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "lookup"
!= "!="
null_literal "null"
) ")"
block
{ "{"
enhanced_for_statement
for "for"
( "("
modifiers
final "final"
array_type
type_identifier "CharSequence"
dimensions
[ "["
] "]"
identifier "seq"
: ":"
identifier "lookup"
) ")"
block
{ "{"
expression_statement
method_invocation
field_access
this "this"
. "."
identifier "lookupMap"
. "."
identifier "put"
argument_list
( "("
array_access
identifier "seq"
[ "["
decimal_integer_literal "0"
] "]"
, ","
array_access
identifier "seq"
[ "["
decimal_integer_literal "1"
] "]"
) ")"
; ";"
local_variable_declaration
modifiers
final "final"
integral_type
int "int"
variable_declarator
identifier "sz"
= "="
method_invocation
array_access
identifier "seq"
[ "["
decimal_integer_literal "0"
] "]"
. "."
identifier "length"
argument_list
( "("
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "sz"
< "<"
identifier "_shortest"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "_shortest"
= "="
identifier "sz"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "sz"
> ">"
identifier "_longest"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "_longest"
= "="
identifier "sz"
; ";"
} "}"
} "}"
} "}"
expression_statement
assignment_expression
identifier "shortest"
= "="
identifier "_shortest"
; ";"
expression_statement
assignment_expression
identifier "longest"
= "="
identifier "_longest"
; ";"
} "}"
block_comment "/**\n * {@inheritDoc}\n */"
method_declaration
modifiers
marker_annotation
@ "@"
identifier "Override"
public "public"
integral_type
int "int"
identifier "translate"
formal_parameters (+21 nodes collapsed)
throws
throws "throws"
type_identifier "IOException"
block
{ "{"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "max"
= "="
identifier "longest"
; ";"
if_statement (+36 nodes collapsed)
line_comment "// descend so as to get a greedy algorithm"
for_statement
for "for"
( "("
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "i"
= "="
identifier "max"
; ";"
binary_expression
identifier "i"
>= ">="
identifier "shortest"
; ";"
update_expression
identifier "i"
-- "--"
) ")"
block
{ "{"
local_variable_declaration (+21 nodes collapsed)
local_variable_declaration
modifiers
final "final"
type_identifier "CharSequence"
variable_declarator
identifier "result"
= "="
method_invocation
identifier "lookupMap"
. "."
identifier "get"
argument_list
( "("
identifier "subSeq"
) ")"
; ";"
if_statement (+32 nodes collapsed)
} "}"
return_statement
return "return"
decimal_integer_literal "0"
; ";"
} "}"
} "}"

After

program
block_comment "/*\n * Licensed to the Apache Software Foundation (ASF) under"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "org"
. "."
identifier "apache"
. "."
identifier "commons"
. "."
identifier "lang3"
. "."
identifier "text"
. "."
identifier "translate"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "IOException"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "io"
. "."
identifier "Writer"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "HashMap"
; ";"
block_comment "/**\n * Translates a value using a lookup table.\n *\n * @since"...
class_declaration
modifiers
public "public"
class "class"
identifier "LookupTranslator"
superclass
extends "extends"
type_identifier "CharSequenceTranslator"
class_body
{ "{"
field_declaration
modifiers
private "private"
final "final"
generic_type
type_identifier "HashMap"
type_arguments
< "<"
type_identifier "String"
, ","
type_identifier "CharSequence"
> ">"
variable_declarator
identifier "lookupMap"
; ";"
field_declaration
modifiers
private "private"
final "final"
integral_type
int "int"
variable_declarator
identifier "shortest"
; ";"
field_declaration
modifiers
private "private"
final "final"
integral_type
int "int"
variable_declarator
identifier "longest"
; ";"
block_comment "/**\n * Define the lookup table to be used in translation"...
constructor_declaration
modifiers
public "public"
identifier "LookupTranslator"
formal_parameters
( "("
spread_parameter
modifiers
final "final"
array_type
type_identifier "CharSequence"
dimensions
[ "["
] "]"
... "..."
variable_declarator
identifier "lookup"
) ")"
constructor_body
{ "{"
expression_statement
assignment_expression
identifier "lookupMap"
= "="
object_creation_expression
new "new"
generic_type
type_identifier "HashMap"
type_arguments
< "<"
type_identifier "String"
, ","
type_identifier "CharSequence"
> ">"
argument_list
( "("
) ")"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "_shortest"
= "="
field_access
identifier "Integer"
. "."
identifier "MAX_VALUE"
; ";"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "_longest"
= "="
decimal_integer_literal "0"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "lookup"
!= "!="
null_literal "null"
) ")"
block
{ "{"
enhanced_for_statement
for "for"
( "("
modifiers
final "final"
array_type
type_identifier "CharSequence"
dimensions
[ "["
] "]"
identifier "seq"
: ":"
identifier "lookup"
) ")"
block
{ "{"
expression_statement
method_invocation
field_access
this "this"
. "."
identifier "lookupMap"
. "."
identifier "put"
argument_list
( "("
method_invocation
array_access
identifier "seq"
[ "["
decimal_integer_literal "0"
] "]"
. "."
identifier "toString"
argument_list
( "("
) ")"
, ","
array_access
identifier "seq"
[ "["
decimal_integer_literal "1"
] "]"
) ")"
; ";"
local_variable_declaration
modifiers
final "final"
integral_type
int "int"
variable_declarator
identifier "sz"
= "="
method_invocation
array_access
identifier "seq"
[ "["
decimal_integer_literal "0"
] "]"
. "."
identifier "length"
argument_list
( "("
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "sz"
< "<"
identifier "_shortest"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "_shortest"
= "="
identifier "sz"
; ";"
} "}"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "sz"
> ">"
identifier "_longest"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "_longest"
= "="
identifier "sz"
; ";"
} "}"
} "}"
} "}"
expression_statement
assignment_expression
identifier "shortest"
= "="
identifier "_shortest"
; ";"
expression_statement
assignment_expression
identifier "longest"
= "="
identifier "_longest"
; ";"
} "}"
block_comment "/**\n * {@inheritDoc}\n */"
method_declaration
modifiers
marker_annotation
@ "@"
identifier "Override"
public "public"
integral_type
int "int"
identifier "translate"
formal_parameters (+21 nodes collapsed)
throws
throws "throws"
type_identifier "IOException"
block
{ "{"
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "max"
= "="
identifier "longest"
; ";"
if_statement (+36 nodes collapsed)
line_comment "// descend so as to get a greedy algorithm"
for_statement
for "for"
( "("
local_variable_declaration
integral_type
int "int"
variable_declarator
identifier "i"
= "="
identifier "max"
; ";"
binary_expression
identifier "i"
>= ">="
identifier "shortest"
; ";"
update_expression
identifier "i"
-- "--"
) ")"
block
{ "{"
local_variable_declaration (+21 nodes collapsed)
local_variable_declaration
modifiers
final "final"
type_identifier "CharSequence"
variable_declarator
identifier "result"
= "="
method_invocation
identifier "lookupMap"
. "."
identifier "get"
argument_list
( "("
method_invocation
identifier "subSeq"
. "."
identifier "toString"
argument_list
( "("
) ")"
) ")"
; ";"
if_statement (+32 nodes collapsed)
} "}"
return_statement
return "return"
decimal_integer_literal "0"
; ";"
} "}"
} "}"