forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdentifier.java
More file actions
54 lines (44 loc) · 1.51 KB
/
Copy pathIdentifier.java
File metadata and controls
54 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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<String> 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]);
}
}