Mercurial > octave
changeset 31202:434b5a1b9498
isequal.m: Add ability to compare Java objects (bug #62930)
* isequal.m: Add elseif clause to detect Java objects and use built-in Java
"equals" method for comparison. Add BIST test for Java object comparison.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 25 Aug 2022 15:35:25 -0700 |
parents | a8b0acc018a2 |
children | 4c2b83516eb7 |
files | scripts/general/isequal.m |
diffstat | 1 files changed, 15 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/isequal.m Wed Aug 24 08:55:39 2022 -0700 +++ b/scripts/general/isequal.m Thu Aug 25 15:35:25 2022 -0700 @@ -171,6 +171,13 @@ ## function type. Use '==' operator which is overloaded. tf = (x == y); + elseif (isjava (x)) + try + tf = x.equals (y); + catch + error ('isequal: Java object does not implement "equals" function'); + end_try_catch + else error ("isequal: Impossible to reach code. File a bug report."); @@ -544,6 +551,14 @@ %!assert (isequal (sparse (1), sparse (1)), true) %!assert (isequal (sparse (1), sparse (1)), sparse (1), true) +## Java objects +%!test <*62930> +%! int1 = javaObject ("java.lang.Integer", 1.0); +%! int2 = javaObject ("java.lang.Integer", 2.0); +%! assert (isequal (int1, int1)); +%! assert (! isequal (int1, 1.0)); +%! assert (! isequal (int1, int2)); + ## test input validation %!error <Invalid call> isequal () %!error <Invalid call> isequal (1)