简体   繁体   中英

Which Java class should I use to represent Git SSH URLs?

I have a Git URL like git@github.com:boostorg/core.git that I would like to represent in memory.

I cannot use URL and URI because I get format exceptions. I would like to use something more structured than a String .

Does Java provide a good class from this?

As far as I know there is nothing like that in Java. You can write your own mini-class to represent that via String and for validating the URL you can use regular expression like this:

For a String s you can say:

s.matches(".+\@*.+:*\.git");

You can also use other regex to extract important part of the String.

Hope this helps

How about creating your own class and splitting the url into fields?

Something like this:

public class GitUrl{
    private String user;
    private String domain;
    private String path;

    public GitUrl(String user, String domain, String path){
        this.user = user;
        this.domain = domain;
        this.path = path;
    }

    //[...] Getters and Setters

    @Override
    public String toString(){
        return user + "@" + domain +":" + path;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM