11package com .github .dockerjava .api .model ;
22
3+ import static com .github .dockerjava .api .model .AccessMode .ro ;
4+ import static com .github .dockerjava .api .model .AccessMode .rw ;
5+
36import org .apache .commons .lang .builder .EqualsBuilder ;
47import org .apache .commons .lang .builder .HashCodeBuilder ;
58
@@ -14,16 +17,24 @@ public class Bind {
1417
1518 private Volume volume ;
1619
17- private boolean readOnly = false ;
20+ private AccessMode accessMode ;
1821
1922 public Bind (String path , Volume volume ) {
20- this (path , volume , false );
23+ this (path , volume , AccessMode . DEFAULT );
2124 }
2225
23- public Bind (String path , Volume volume , boolean readOnly ) {
26+ public Bind (String path , Volume volume , AccessMode accessMode ) {
2427 this .path = path ;
2528 this .volume = volume ;
26- this .readOnly = readOnly ;
29+ this .accessMode = accessMode ;
30+ }
31+
32+ /**
33+ * @deprecated use {@link #Bind(String, Volume, AccessMode)}
34+ */
35+ @ Deprecated
36+ public Bind (String path , Volume volume , boolean readOnly ) {
37+ this (path , volume , readOnly ? ro : rw );
2738 }
2839
2940 public String getPath () {
@@ -33,9 +44,17 @@ public String getPath() {
3344 public Volume getVolume () {
3445 return volume ;
3546 }
47+
48+ public AccessMode getAccessMode () {
49+ return accessMode ;
50+ }
3651
52+ /**
53+ * @deprecated use {@link #getAccessMode()}
54+ */
55+ @ Deprecated
3756 public boolean isReadOnly () {
38- return readOnly ;
57+ return ro . equals ( accessMode ) ;
3958 }
4059
4160 /**
@@ -53,12 +72,8 @@ public static Bind parse(String serialized) {
5372 return new Bind (parts [0 ], Volume .parse (parts [1 ]));
5473 }
5574 case 3 : {
56- if ("rw" .equals (parts [2 ].toLowerCase ()))
57- return new Bind (parts [0 ], Volume .parse (parts [1 ]), false );
58- else if ("ro" .equals (parts [2 ].toLowerCase ()))
59- return new Bind (parts [0 ], Volume .parse (parts [1 ]), true );
60- else
61- throw new IllegalArgumentException ();
75+ AccessMode accessMode = AccessMode .valueOf (parts [2 ].toLowerCase ());
76+ return new Bind (parts [0 ], Volume .parse (parts [1 ]), accessMode );
6277 }
6378 default : {
6479 throw new IllegalArgumentException ();
@@ -76,15 +91,15 @@ public boolean equals(Object obj) {
7691 Bind other = (Bind ) obj ;
7792 return new EqualsBuilder ().append (path , other .getPath ())
7893 .append (volume , other .getVolume ())
79- .append (readOnly , other .isReadOnly ()).isEquals ();
94+ .append (accessMode , other .getAccessMode ()).isEquals ();
8095 } else
8196 return super .equals (obj );
8297 }
8398
8499 @ Override
85100 public int hashCode () {
86101 return new HashCodeBuilder ().append (path ).append (volume )
87- .append (readOnly ).toHashCode ();
102+ .append (accessMode ).toHashCode ();
88103 }
89104
90105 /**
@@ -97,7 +112,7 @@ public int hashCode() {
97112 */
98113 @ Override
99114 public String toString () {
100- return path + ":" + volume .toString () + ( readOnly ? ":ro" : ":rw" );
115+ return path + ":" + volume .toString () + ":" + accessMode . toString ( );
101116 }
102117
103118}
0 commit comments