[ 
https://issues.apache.org/jira/browse/TINKERPOP-2061?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16646774#comment-16646774
 ] 

ASF GitHub Bot commented on TINKERPOP-2061:
-------------------------------------------

dkuppitz commented on a change in pull request #961: TINKERPOP-2061 Added 
with() option for traversal configuration
URL: https://github.com/apache/tinkerpop/pull/961#discussion_r224530299
 
 

 ##########
 File path: 
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
 ##########
 @@ -93,6 +96,39 @@ private Symbols() {
 
     /////////////////////////////
 
+    /**
+     * Provides a configuration to a traversal in the form of a key which is 
the same as {@code with(key, true)}. The
+     * key of the configuration must be graph provider specific and therefore 
a configuration could be supplied that
+     * is not known to be valid until execution.
+     *
+     * @param key the key of the configuration to apply to a traversal
+     * @return a new traversal source with the included configuration
+     * @since 3.4.0
+     */
+    public default TraversalSource with(final String key) {
+        return with(key, true);
+    }
+
+    /**
+     * Provides a configuration to a traversal in the form of a key value 
pair. The  key of the configuration must be
+     * graph provider specific and therefore a configuration could be supplied 
that is not known to be valid until
+     * execution. This is a handy shortcut for building an {@link 
OptionsStrategy} manually and then add with
+     * {@link #withStrategies(TraversalStrategy[])}.
+     *
+     * @param key the key of the configuration to apply to a traversal
+     * @param value the value of the configuration to apply to a traversal
+     * @return a new traversal source with the included configuration
+     * @since 3.4.0
+     */
+    public default TraversalSource with(final String key, final Object value) {
+        final Optional<OptionsStrategy> opt = 
getStrategies().getStrategy(OptionsStrategy.class);
+        final OptionsStrategy strategy = opt.orElse(OptionsStrategy.EMPTY);
+        final OptionsStrategy.Builder builder = OptionsStrategy.build();
+        strategy.getOptions().forEach(builder::with);
+        builder.with(key, value);
+        return withStrategies(builder.create());
+    }
 
 Review comment:
   Perhaps a little bit more elegant:
   ```java
       public default TraversalSource with(final String key, final Object 
value) {
           final OptionsStrategy.Builder builder = OptionsStrategy.build();
           getStrategies().getStrategy(OptionsStrategy.class)
                   .ifPresent(optionsStrategy -> 
optionsStrategy.getOptions().forEach(builder::with));
           builder.with(key, value);
           return withStrategies(builder.create());
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Add with() configuration as global to a traversal
> -------------------------------------------------
>
>                 Key: TINKERPOP-2061
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2061
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 3.4.0
>            Reporter: stephen mallette
>            Assignee: stephen mallette
>            Priority: Major
>
> Provide a for {{with(String)}} and {{with(String,Object)}} at the 
> configuration of the {{TraversalSource}} - basically a shorthand for using 
> {{OptionsStrategy}} manually and {{withStrategies()}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to