forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBind.java
More file actions
77 lines (64 loc) · 1.65 KB
/
Copy pathBind.java
File metadata and controls
77 lines (64 loc) · 1.65 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.github.dockerjava.api.model;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
public class Bind {
private String path;
private Volume volume;
private boolean readOnly = false;
public Bind(String path, Volume volume) {
this(path, volume, false);
}
public Bind(String path, Volume volume, boolean readOnly) {
this.path = path;
this.volume = volume;
this.readOnly = readOnly;
}
public String getPath() {
return path;
}
public Volume getVolume() {
return volume;
}
public boolean isReadOnly() {
return readOnly;
}
public static Bind parse(String serialized) {
try {
String[] parts = serialized.split(":");
switch (parts.length) {
case 2: {
return new Bind(parts[0], Volume.parse(parts[1]));
}
case 3: {
if ("rw".equals(parts[3].toLowerCase()))
return new Bind(parts[0], Volume.parse(parts[1]), true);
else
throw new RuntimeException("Error parsing Bind '"
+ serialized + "'");
}
default: {
throw new RuntimeException("Error parsing Bind '" + serialized
+ "'");
}
}
} catch (Exception e) {
throw new RuntimeException("Error parsing Bind '" + serialized
+ "'");
}
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Bind) {
Bind other = (Bind) obj;
return new EqualsBuilder().append(path, other.getPath())
.append(volume, other.getVolume())
.append(readOnly, other.isReadOnly()).isEquals();
} else
return super.equals(obj);
}
@Override
public int hashCode() {
return new HashCodeBuilder().append(path).append(volume)
.append(readOnly).toHashCode();
}
}