Doing an Enthuware OCP question. Can't understand this at allPath.relativize behaviour when “dot directory” is includedMaking a class follow OCP - Factoring functions into objectsIf I have a full unit test suite for an application, must I still apply the Open/Closed Principle (OCP)?How do you write code that conforms to the OCP?Good examples of OCP in open source librariesUnderstanding the relationship between Liskov and OCPHow we can use OCP with delegation?How to modify the function to satisfy OCP?OCP Java SE 6 Practice Questions - WeatherTest EnumDo OCP and DIP break YAGNI?Solid OCP violation consequences

Does the Milky Way orbit around anything?

Why do Klingons use cloaking devices?

Change the default text editor in Terminal

The Purpose of "Natu"

How do I check that users don't write down their passwords?

Will Jimmy fall off his platform?

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

Isn't "Dave's protocol" good if only the database, and not the code, is leaked?

Did Stalin kill all Soviet officers involved in the Winter War?

PhD: When to quit and move on?

Should I cheat if the majority does it?

Red and White Squares

Taking advantage when the HR forgets to communicate the rules

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Is this standard Japanese employment negotiations, or am I missing something?

n-level Ouroboros Quine

What instances can be solved today by modern solvers (pure LP)?

Way to see all encrypted fields in Salesforce?

What happens if the limit of 4 billion files was exceeded in an ext4 partition?

What is this arch-and-tower near a road?

What is the highest level of accuracy in motion control a Victorian society could achieve?

What's the big deal about the Nazgûl losing their horses?

What is exact meaning of “ich wäre gern”?

Was I wrongfully denied boarding for having a Schengen visa issued from the second country on my itinerary?



Doing an Enthuware OCP question. Can't understand this at all


Path.relativize behaviour when “dot directory” is includedMaking a class follow OCP - Factoring functions into objectsIf I have a full unit test suite for an application, must I still apply the Open/Closed Principle (OCP)?How do you write code that conforms to the OCP?Good examples of OCP in open source librariesUnderstanding the relationship between Liskov and OCPHow we can use OCP with delegation?How to modify the function to satisfy OCP?OCP Java SE 6 Practice Questions - WeatherTest EnumDo OCP and DIP break YAGNI?Solid OCP violation consequences






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















What will the following code fragment print?





Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
Path p2 = Paths.get("c:\personal\index.html");
Path p3 = p1.relativize(p2);
System.out.println(p3);



Apparently the answer is:





........index.html



But I don't see how whatsoever. p1 starts off in c, then into the personal directory. Then the single full stop means the current directory. Then into photos. Then the double full stops means go up a directory so you should be back into photos. Then readme.txt should be in the photos folder. Which would then read as c -> personal -> [current_directory] -> photos -> readme.txt.



That means you should only need three .. before going into index. How is it four?










share|improve this question






















  • Check this answer to a similar question: stackoverflow.com/a/34271865/634412

    – gparis
    Mar 26 at 15:09

















0















What will the following code fragment print?





Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
Path p2 = Paths.get("c:\personal\index.html");
Path p3 = p1.relativize(p2);
System.out.println(p3);



Apparently the answer is:





........index.html



But I don't see how whatsoever. p1 starts off in c, then into the personal directory. Then the single full stop means the current directory. Then into photos. Then the double full stops means go up a directory so you should be back into photos. Then readme.txt should be in the photos folder. Which would then read as c -> personal -> [current_directory] -> photos -> readme.txt.



That means you should only need three .. before going into index. How is it four?










share|improve this question






















  • Check this answer to a similar question: stackoverflow.com/a/34271865/634412

    – gparis
    Mar 26 at 15:09













0












0








0








What will the following code fragment print?





Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
Path p2 = Paths.get("c:\personal\index.html");
Path p3 = p1.relativize(p2);
System.out.println(p3);



Apparently the answer is:





........index.html



But I don't see how whatsoever. p1 starts off in c, then into the personal directory. Then the single full stop means the current directory. Then into photos. Then the double full stops means go up a directory so you should be back into photos. Then readme.txt should be in the photos folder. Which would then read as c -> personal -> [current_directory] -> photos -> readme.txt.



That means you should only need three .. before going into index. How is it four?










share|improve this question














What will the following code fragment print?





Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
Path p2 = Paths.get("c:\personal\index.html");
Path p3 = p1.relativize(p2);
System.out.println(p3);



Apparently the answer is:





........index.html



But I don't see how whatsoever. p1 starts off in c, then into the personal directory. Then the single full stop means the current directory. Then into photos. Then the double full stops means go up a directory so you should be back into photos. Then readme.txt should be in the photos folder. Which would then read as c -> personal -> [current_directory] -> photos -> readme.txt.



That means you should only need three .. before going into index. How is it four?







open-closed-principle






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 19:30









jenny lorinejenny lorine

774 bronze badges




774 bronze badges












  • Check this answer to a similar question: stackoverflow.com/a/34271865/634412

    – gparis
    Mar 26 at 15:09

















  • Check this answer to a similar question: stackoverflow.com/a/34271865/634412

    – gparis
    Mar 26 at 15:09
















Check this answer to a similar question: stackoverflow.com/a/34271865/634412

– gparis
Mar 26 at 15:09





Check this answer to a similar question: stackoverflow.com/a/34271865/634412

– gparis
Mar 26 at 15:09












1 Answer
1






active

oldest

votes


















0














The path segments . and .. in p1, are considered just as another name by relativize, not a special case for the current directory or the parent directory, respectively.



You need to normalize the path to eliminate redundant name elements like . and ..:



Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
Path p1Normalized = p1.normalize();
System.out.println(p1Normalized);

Path p2 = Paths.get("c:\personal\index.html");
Path p3 = p1Normalized.relativize(p2);
System.out.println(p3);


The output is:



c:\personal\readme.txt
..index.html





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345156%2fdoing-an-enthuware-ocp-question-cant-understand-this-at-all%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The path segments . and .. in p1, are considered just as another name by relativize, not a special case for the current directory or the parent directory, respectively.



    You need to normalize the path to eliminate redundant name elements like . and ..:



    Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
    Path p1Normalized = p1.normalize();
    System.out.println(p1Normalized);

    Path p2 = Paths.get("c:\personal\index.html");
    Path p3 = p1Normalized.relativize(p2);
    System.out.println(p3);


    The output is:



    c:\personal\readme.txt
    ..index.html





    share|improve this answer



























      0














      The path segments . and .. in p1, are considered just as another name by relativize, not a special case for the current directory or the parent directory, respectively.



      You need to normalize the path to eliminate redundant name elements like . and ..:



      Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
      Path p1Normalized = p1.normalize();
      System.out.println(p1Normalized);

      Path p2 = Paths.get("c:\personal\index.html");
      Path p3 = p1Normalized.relativize(p2);
      System.out.println(p3);


      The output is:



      c:\personal\readme.txt
      ..index.html





      share|improve this answer

























        0












        0








        0







        The path segments . and .. in p1, are considered just as another name by relativize, not a special case for the current directory or the parent directory, respectively.



        You need to normalize the path to eliminate redundant name elements like . and ..:



        Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
        Path p1Normalized = p1.normalize();
        System.out.println(p1Normalized);

        Path p2 = Paths.get("c:\personal\index.html");
        Path p3 = p1Normalized.relativize(p2);
        System.out.println(p3);


        The output is:



        c:\personal\readme.txt
        ..index.html





        share|improve this answer













        The path segments . and .. in p1, are considered just as another name by relativize, not a special case for the current directory or the parent directory, respectively.



        You need to normalize the path to eliminate redundant name elements like . and ..:



        Path p1 = Paths.get("c:\personal\.\photos\..\readme.txt");
        Path p1Normalized = p1.normalize();
        System.out.println(p1Normalized);

        Path p2 = Paths.get("c:\personal\index.html");
        Path p3 = p1Normalized.relativize(p2);
        System.out.println(p3);


        The output is:



        c:\personal\readme.txt
        ..index.html






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 16:39









        gparisgparis

        1,0329 silver badges26 bronze badges




        1,0329 silver badges26 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345156%2fdoing-an-enthuware-ocp-question-cant-understand-this-at-all%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현