Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Relativize question

 
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given



Why does it print ..\Java.class and not .\Java.class
 
Paul Statham
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen that yes, in fact it even has this in the API

For example, if this path is "/a/b" and the given path is "/a/x" then the resulting relative path may be "../x"



I just don't understand why it would be .. and not .

All dealings with relative paths in the past have had . to mean current directory and .. as one level up

Or is it in fact saying for example if we just take



This would give

"Relativize: ../Java.class"

Relatively it is one level up from Java.java therefore the path is "../Java.class". Does that make sense?

 
Paul Statham
Ranch Hand
Posts: 60
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have worked it out, I had to break it up into bullet points to understand it though. Here are some of my notes if it helps someone else

Path relativize(Path other)
- This method attempts to construct a relative path that when resolved against this path, yields a path that locates the same file as the given path
- Where this path and the given path do not have a root component, then a relative path can be constructed
- A relative path cannot be constructed if only one of the paths have a root component
- If this path and the given path are equal then an empty path is returned
- /a/b -> /a/b/c/d = c/d
- a/b -> a/b/c/d = c/d
- /a/b/c/d -> a/b = IllegalArgumentException
- /a/b/c/d -> /a/b = ../..
- /a/b -> /a/b = ""
- /a/b -> /a/c = ../c
- /x/d/g/a/b -> /a/b = ../../../../../a/b


 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic