@@ -203,69 +203,20 @@ public void mode(String graph, GraphMode mode) {
203203 this .client .put (joinPath (this .path (), graph , MODE ), null , mode );
204204 }
205205
206- public void mode (String graph , String graphSpace , GraphMode mode ) {
206+ public void mode (String graphSpace , String graph , GraphMode mode ) {
207207 // NOTE: Must provide id for PUT. If you use "graph/mode", "/" will
208208 // be encoded to "%2F". So use "mode" here, although inaccurate.
209209 this .client .put (joinPath (this .path (), graphSpace , graph , MODE ), null , mode );
210210 }
211211
212- public GraphMode mode (String graph , String graphSpace ) {
213- RestResult result = this .client .get (joinPath (this .path (), graphSpace , graph ), MODE );
214- @ SuppressWarnings ("unchecked" )
215- Map <String , String > mode = result .readObject (Map .class );
216- String value = mode .get (MODE );
217- if (value == null ) {
218- throw new InvalidResponseException ("Invalid response, expect 'mode' in response" );
219- }
220- try {
221- return GraphMode .valueOf (value );
222- } catch (IllegalArgumentException e ) {
223- throw new InvalidResponseException ("Invalid GraphMode value '%s'" , value );
224- }
225- }
226-
227-
228- public GraphMode mode (String graph ) {
229- RestResult result = this .client .get (joinPath (this .path (), graph ), MODE );
230- @ SuppressWarnings ("unchecked" )
231- Map <String , String > mode = result .readObject (Map .class );
232- String value = mode .get (MODE );
233- if (value == null ) {
234- throw new InvalidResponseException ("Invalid response, expect 'mode' in response" );
235- }
236- try {
237- return GraphMode .valueOf (value );
238- } catch (IllegalArgumentException e ) {
239- throw new InvalidResponseException ("Invalid GraphMode value '%s'" , value );
240- }
241- }
242-
243- public void readMode (String graph , String graphSpace , GraphReadMode readMode ) {
212+ public void readMode (String graphSpace , String graph , GraphReadMode readMode ) {
244213 this .client .checkApiVersion ("0.59" , "graph read mode" );
245214 // NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", "/"
246215 // will be encoded to "%2F". So use "graph_read_mode" here, although
247216 // inaccurate.
248217 this .client .put (joinPath (this .path (), graphSpace , graph , GRAPH_READ_MODE ), null , readMode );
249218 }
250219
251- public GraphReadMode readMode (String graph , String graphSpace ) {
252- this .client .checkApiVersion ("0.59" , "graph read mode" );
253- RestResult result = this .client .get (joinPath (this .path (), graphSpace , graph ),
254- GRAPH_READ_MODE );
255- @ SuppressWarnings ("unchecked" )
256- Map <String , String > readMode = result .readObject (Map .class );
257- String value = readMode .get (GRAPH_READ_MODE );
258- if (value == null ) {
259- throw new InvalidResponseException ("Invalid response, expect 'graph_read_mode' " +
260- "in response" );
261- }
262- try {
263- return GraphReadMode .valueOf (value );
264- } catch (IllegalArgumentException e ) {
265- throw new InvalidResponseException ("Invalid GraphReadMode value '%s'" , value );
266- }
267- }
268-
269220 public void readMode (String graph , GraphReadMode readMode ) {
270221 this .client .checkApiVersion ("0.59" , "graph read mode" );
271222 // NOTE: Must provide id for PUT. If you use "graph/graph_read_mode", "/"
@@ -274,23 +225,47 @@ public void readMode(String graph, GraphReadMode readMode) {
274225 this .client .put (joinPath (this .path (), graph , GRAPH_READ_MODE ), null , readMode );
275226 }
276227
277- public GraphReadMode readMode (String graph ) {
278- this .client .checkApiVersion ("0.59" , "graph read mode" );
279- RestResult result = this .client .get (joinPath (this .path (), graph ), GRAPH_READ_MODE );
228+ private <T extends Enum <T >> T getEnumMode (String graphSpace , String graph ,
229+ String modeKey , Class <T > enumClass ) {
230+ String path = (graphSpace != null )
231+ ? joinPath (this .path (), graphSpace , graph )
232+ : joinPath (this .path (), graph );
233+
234+ RestResult result = this .client .get (path , modeKey );
280235 @ SuppressWarnings ("unchecked" )
281- Map <String , String > readMode = result .readObject (Map .class );
282- String value = readMode .get (GRAPH_READ_MODE );
236+ Map <String , String > map = result .readObject (Map .class );
237+ String value = map .get (modeKey );
238+
283239 if (value == null ) {
284- throw new InvalidResponseException ("Invalid response, expect 'graph_read_mode' " +
285- " in response" );
240+ throw new InvalidResponseException (
241+ "Invalid response, expect '%s' in response", modeKey );
286242 }
287243 try {
288- return GraphReadMode .valueOf (value );
244+ return Enum .valueOf (enumClass , value );
289245 } catch (IllegalArgumentException e ) {
290- throw new InvalidResponseException ("Invalid GraphReadMode value '%s'" , value );
246+ throw new InvalidResponseException (
247+ "Invalid %s value '%s'" , enumClass .getSimpleName (), value );
291248 }
292249 }
293250
251+ public GraphMode mode (String graphSpace , String graph ) {
252+ return getEnumMode (graphSpace , graph , MODE , GraphMode .class );
253+ }
254+
255+ public GraphMode mode (String graph ) {
256+ return getEnumMode (null , graph , MODE , GraphMode .class );
257+ }
258+
259+ public GraphReadMode readMode (String graphSpace , String graph ) {
260+ this .client .checkApiVersion ("0.59" , "graph read mode" );
261+ return getEnumMode (graphSpace , graph , GRAPH_READ_MODE , GraphReadMode .class );
262+ }
263+
264+ public GraphReadMode readMode (String graph ) {
265+ this .client .checkApiVersion ("0.59" , "graph read mode" );
266+ return getEnumMode (null , graph , GRAPH_READ_MODE , GraphReadMode .class );
267+ }
268+
294269 public String clone (String graph , Map <String , Object > body ) {
295270 RestResult result = this .client .post (joinPath (this .path (), graph ,
296271 "clone" ), body );
0 commit comments