All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dockerjava.api.model.Identifier Maven / Gradle / Ivy

package com.github.dockerjava.api.model;

import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.io.Serializable;
import java.util.Optional;

/**
 * @author magnayn
 */
@EqualsAndHashCode
@ToString
public class Identifier implements Serializable {
    private static final long serialVersionUID = 1L;

    public final Repository repository;

    public final Optional tag;

    public Identifier(Repository repository, String tag) {
        this.repository = repository;

        this.tag = Optional.ofNullable(tag);
    }

    /**
     * Return an identifier that correctly splits up the repository and tag. There can be > 1 ":" fred/jim --> fred/jim, []
     * fred/jim:123 --> fred/jim, 123 fred:123/jim:123 --> fred:123/jim, 123
     *
     *
     * @param identifier
     *            as a string
     * @return parsed identifier.
     */
    public static Identifier fromCompoundString(String identifier) {
        String[] parts = identifier.split("/");
        if (parts.length != 2) {
            String[] rhs = identifier.split(":");
            if (rhs.length != 2) {
                return new Identifier(new Repository(identifier), null);
            } else {
                return new Identifier(new Repository(rhs[0]), rhs[1]);
            }
        }

        String[] rhs = parts[1].split(":");
        if (rhs.length != 2) {
            return new Identifier(new Repository(identifier), null);
        }

        return new Identifier(new Repository(parts[0] + "/" + rhs[0]), rhs[1]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy