Page 1 of 1

About Question enthuware.ocpjp.v7.2.1584 :

Posted: Mon Dec 23, 2013 2:30 pm
by caa4444
It says the correct answer is ..\..\..\..\index.html, but shouldn't it just be ..\index.html?

My thinking:
Path 1 simplifies
c:\\personal\\.\\photos\\..\\readme.txt -> c:\\personal\\photos\\..\\readme.txt
c:\\personal\\photos\\..\\readme.txt -> c:\\personal\\readme.txt

or is it different because Path 1 isn't simplified?

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Mon Dec 23, 2013 2:58 pm
by admin
Yes, relativize doesn't canolicalize/simplify the paths.
Try it out.
HTH,
Paul.

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Mon Dec 23, 2013 3:04 pm
by caa4444
ok. thanks for the help!

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Thu Mar 16, 2017 8:05 am
by rolandlensink
I think the answer is ok ... relativize() does not normalize the path and the answer seems to be logical.

But when I do p1.resolve(p1.relativize(p2)).normalize() ... the answer is c:\index.html ... what is not a logical answer ...

When I first normalize p1 and then do the same ... the answer is c:\personal\index.html (what should be the logical answer)

So, I think your explanation about the answer c:\ is not correct ...

If you do a relativize without first normalizing, there are 4 '..\' it means it goes 4 levels up is the directory tree (and there is still one in p1), so this means that you go up to the root ...
There are 2 '..\' too much, because of not normalizing the path ...

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Thu Mar 16, 2017 8:40 am
by admin
I am not sure I understand your point. Can you please the paste the complete and exact the statement from the explanation that you think is incorrect?

Also, please paste the complete code that you are trying out.

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Thu Mar 16, 2017 9:31 am
by rolandlensink
Maybe I do something wrong, but my point is that the explanation you give at the question is not correct.
I used the following code:
Path p4 = Paths.get("C:\\personal\\.\\photos\\..\\readme.txt");
Path p5 = Paths.get("C:\\personal\\index.html");
Path p6= p4.relativize(p5);
System.out.println(p6);
System.out.println(p4.resolve(p6));
System.out.println(p4.resolve(p4.relativize(p5)).normalize());

System.out.println("");
Path p14 = p4.normalize();
Path p16= p14.relativize(p5);
System.out.println(p14);
System.out.println(p16);
System.out.println(p14.resolve(p16));
System.out.println(p14.resolve(p16).normalize());
My point is, that you first have to normalize the path(s) before relativizing ....

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Thu Mar 16, 2017 9:14 pm
by admin
I am still not clear on which part of the explanation you think is wrong. Where does the explanation claim that you have to or don't have to normalize?

There is no requirement imposed by the API that you have to normalize. You can relativize and resolve without normalizing also. Of course, the results in both the cases may be different. That depends on what your original path is composed of.

The only thing that is promised by the API (as mentioned in the explanation also) is, "for any two normalized paths p and q, where q does not have a root component, p.relativize(p.resolve(q)).equals(q)". Thus, if your paths are not normalized, the results may vary.

The explanation is only talking about how to work out the results of applying resolve and/or relativize methods.

Paul.

Re: About Question enthuware.ocpjp.v7.2.1584 :

Posted: Mon Mar 20, 2017 2:58 pm
by runnerdave
try this version if you are in linux or mac:

Code: Select all

//linux version
		Path p12 = Paths.get("/c/personal/./photos/../readme.txt");
		Path p13 = Paths.get("/c/personal/index.html"); 
		Path p14 = p12.relativize(p13); 
		System.out.println(p14);