/* package whatever; // don't place package name! */
import java.lang.*;
import java.io.*;
import java.nio.*;
import java.util.function.*;
import java.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class requal
{
{
// Initializing test data.
// Will compare Strings in batch1, batch2 at the same array position.
//
"/mypath/check/10.10/-123.11"
, "/mypath/check/10.10/-123.11"
, "/mypath/check/10.10/-123.11"
, "/mypath/check/10.10/123.11"
, "/mypath/check/10.10/-123.11"
, "/mypath/check/10.11/-123.11"
};
"/mypath/check/10.101/-123.112"
, "/mypath/check/10.101/-123.11"
, "/mypath/check/10.10/-123.112"
, "/mypath/check/10.101/123.112"
, "/mypath/check/10.121/-123.152"
, "/mypath/check/10.12/-123.11"
};
// Regex pattern used for normalization:
// - Basic pattern: decimal point followed by 2 or 3 digits
// - Optional part: 3rd digit of the basic pattern
// - Additional context: Pattern must match at the end of the string or be followed by a non-digit character.
//
Pattern re_p = Pattern.compile("([.][0-9]{2})[0-9]?(?:$|(?![0-9]))");
// Replacer routine for processing the regex match. Returns capture group #1
Function<MatchResult, String> fnReplacer= (MatchResult m)-> { return m.group(1); };
// Processing each test case
// Expected result
// match
// match
// match
// match
// mismatch
// mismatch
//
for ( int i = 0; i < batch1.length; i++ ) {
String norm1
= re_p.
matcher(batch1
[i
]).
replaceAll(fnReplacer
); String norm2
= re_p.
matcher(batch2
[i
]).
replaceAll(fnReplacer
);
if (norm1.equals(norm2)) {
System.
out.
println("Url pair #" + Integer.
toString(i
) + ": match ( '" + norm1
+ "' == '" + norm2
+ "' )"); } else {
System.
out.
println("Url pair #" + Integer.
toString(i
) + ": mismatch ( '" + norm1
+ "' != '" + norm2
+ "' )"); }
}
}
}