Skip to content

Commit b9e5816

Browse files
committed
samepath: java as well
1 parent cb59cd6 commit b9e5816

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

+stdlib/+java/samepath.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%% JAVA.SAMEPATH are inputs the same path
2+
3+
function y = samepath(path1, path2)
4+
5+
if stdlib.exists(path1) && stdlib.exists(path2)
6+
j1 = javaPathObject(stdlib.absolute(path1));
7+
j2 = javaPathObject(stdlib.absolute(path2));
8+
9+
y = java.nio.file.Files.isSameFile(j1, j2);
10+
else
11+
y = false;
12+
end
13+
14+
end

+stdlib/samepath.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
path2 {mustBeTextScalar}
1717
end
1818

19+
1920
if stdlib.has_python()
21+
% For this function, Python is over 10x faster than Java
2022
y = stdlib.python.samepath(path1, path2);
23+
elseif stdlib.has_java()
24+
y = stdlib.java.samepath(path1, path2);
2125
elseif isunix()
2226
y = stdlib.sys.samepath(path1, path2);
2327
else
28+
% string comparison is not preferred
2429
y = stdlib.native.samepath(path1, path2);
2530
end
2631

test/TestSame.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
properties (TestParameter)
44
p_same = {...
5+
{".", pwd()}, ...
56
{"..", "./.."}, ...
67
{"..", pwd() + "/.."}, ...
78
{pwd(), pwd() + "/."}}
89

9-
same_fun = {@stdlib.samepath, @stdlib.sys.samepath, @stdlib.python.samepath, @stdlib.native.samepath}
10+
same_fun = {@stdlib.samepath, @stdlib.sys.samepath, @stdlib.java.samepath, @stdlib.python.samepath, @stdlib.native.samepath}
1011
end
1112

1213
methods(TestClassSetup)

0 commit comments

Comments
 (0)