changeset 412:2af6736ccb7b

API CHANGE: jvmArgs/jvmArgsAppend/jvmArgsPrepend can not be called multiple times anymore; every subsequent call overwrites the previous value.
author shade
date Wed, 19 Feb 2014 18:39:52 +0400
parents b396331bc871
children ab9be19b4646
files jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestParentOptions.java
diffstat 3 files changed, 14 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java	Wed Feb 19 18:22:23 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java	Wed Feb 19 18:39:52 2014 +0400
@@ -232,7 +232,6 @@
 
     /**
      * Forked JVM arguments.
-     * (can be used multiple times)
      *
      * @param value arguments to add to the run
      * @return builder
@@ -242,7 +241,6 @@
     /**
      * Append forked JVM arguments:
      * These options go after other options.
-     * (can be used multiple times)
      *
      * @param value arguments to add to the run
      * @return builder
@@ -252,7 +250,6 @@
     /**
      * Prepend forked JVM arguments:
      * These options go before any other options.
-     * (can be used multiple times)
      *
      * @param value arguments to add to the run
      * @return builder
@@ -261,6 +258,8 @@
 
     /**
      * Autodetect forked JVM arguments from the parent VM.
+     * Overrides the jvmArgs(...) value.
+     *
      * @return builder
      */
     ChainedOptionsBuilder detectJvmArgs();
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Wed Feb 19 18:22:23 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Wed Feb 19 18:39:52 2014 +0400
@@ -551,28 +551,16 @@
 
     @Override
     public ChainedOptionsBuilder jvmArgs(String... value) {
-        if (jvmArgs.hasValue()) {
-            jvmArgs.get().addAll(Arrays.asList(value));
-        } else {
-            Collection<String> vals = new ArrayList<String>(Arrays.asList(value));
-            jvmArgs = Optional.of(vals);
-        }
+        jvmArgs = Optional.<Collection<String>>of(Arrays.asList(value));
         return this;
     }
 
     @Override
     public Optional<Collection<String>> getJvmArgs() {
-        Collection<String> result = new ArrayList<String>();
-
         if (otherOptions != null) {
-            result.addAll(otherOptions.getJvmArgs().orElse(Collections.<String>emptyList()));
-        }
-        result.addAll(jvmArgs.orElse(Collections.<String>emptyList()));
-
-        if (result.isEmpty()) {
-            return Optional.none();
+            return jvmArgs.orAnother(otherOptions.getJvmArgs().orAnother(Optional.<Collection<String>>none()));
         } else {
-            return Optional.of(result);
+            return jvmArgs.orAnother(Optional.<Collection<String>>none());
         }
     }
 
@@ -582,28 +570,16 @@
 
     @Override
     public ChainedOptionsBuilder jvmArgsAppend(String... value) {
-        if (jvmArgsAppend.hasValue()) {
-            jvmArgsAppend.get().addAll(Arrays.asList(value));
-        } else {
-            Collection<String> vals = new ArrayList<String>(Arrays.asList(value));
-            jvmArgsAppend = Optional.of(vals);
-        }
+        jvmArgsAppend = Optional.<Collection<String>>of(Arrays.asList(value));
         return this;
     }
 
     @Override
     public Optional<Collection<String>> getJvmArgsAppend() {
-        Collection<String> result = new ArrayList<String>();
-
         if (otherOptions != null) {
-            result.addAll(otherOptions.getJvmArgsAppend().orElse(Collections.<String>emptyList()));
-        }
-        result.addAll(jvmArgsAppend.orElse(Collections.<String>emptyList()));
-
-        if (result.isEmpty()) {
-            return Optional.none();
+            return jvmArgsAppend.orAnother(otherOptions.getJvmArgsAppend().orAnother(Optional.<Collection<String>>none()));
         } else {
-            return Optional.of(result);
+            return jvmArgsAppend.orAnother(Optional.<Collection<String>>none());
         }
     }
 
@@ -613,28 +589,16 @@
 
     @Override
     public ChainedOptionsBuilder jvmArgsPrepend(String... value) {
-        if (jvmArgsPrepend.hasValue()) {
-            jvmArgsPrepend.get().addAll(Arrays.asList(value));
-        } else {
-            Collection<String> vals = new ArrayList<String>(Arrays.asList(value));
-            jvmArgsPrepend = Optional.of(vals);
-        }
+        jvmArgsPrepend = Optional.<Collection<String>>of(Arrays.asList(value));
         return this;
     }
 
     @Override
     public Optional<Collection<String>> getJvmArgsPrepend() {
-        Collection<String> result = new ArrayList<String>();
-
         if (otherOptions != null) {
-            result.addAll(otherOptions.getJvmArgsPrepend().orElse(Collections.<String>emptyList()));
-        }
-        result.addAll(jvmArgsPrepend.orElse(Collections.<String>emptyList()));
-
-        if (result.isEmpty()) {
-            return Optional.none();
+            return jvmArgsPrepend.orAnother(otherOptions.getJvmArgsPrepend().orAnother(Optional.<Collection<String>>none()));
         } else {
-            return Optional.of(result);
+            return jvmArgsPrepend.orAnother(Optional.<Collection<String>>none());
         }
     }
 
--- a/jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestParentOptions.java	Wed Feb 19 18:22:23 2014 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/options/TestParentOptions.java	Wed Feb 19 18:39:52 2014 +0400
@@ -203,7 +203,7 @@
     public void testJVMArgs_Merge() throws Exception {
         Options parent = new OptionsBuilder().jvmArgs("opt1", "opt2").build();
         Options builder = new OptionsBuilder().parent(parent).jvmArgs("opt3", "opt4").build();
-        Assert.assertEquals(Arrays.asList("opt1", "opt2", "opt3", "opt4"), builder.getJvmArgs().get());
+        Assert.assertEquals(Arrays.asList("opt3", "opt4"), builder.getJvmArgs().get());
     }
 
     @Test
@@ -224,7 +224,7 @@
     public void testJVMArgsAppend_Merge() throws Exception {
         Options parent = new OptionsBuilder().jvmArgsAppend("opt1", "opt2").build();
         Options builder = new OptionsBuilder().parent(parent).jvmArgsAppend("opt3", "opt4").build();
-        Assert.assertEquals(Arrays.asList("opt1", "opt2", "opt3", "opt4"), builder.getJvmArgsAppend().get());
+        Assert.assertEquals(Arrays.asList("opt3", "opt4"), builder.getJvmArgsAppend().get());
     }
 
     @Test
@@ -245,7 +245,7 @@
     public void testJVMArgsPrepend_Merge() throws Exception {
         Options parent = new OptionsBuilder().jvmArgsPrepend("opt1", "opt2").build();
         Options builder = new OptionsBuilder().parent(parent).jvmArgsPrepend("opt3", "opt4").build();
-        Assert.assertEquals(Arrays.asList("opt1", "opt2", "opt3", "opt4"), builder.getJvmArgsPrepend().get());
+        Assert.assertEquals(Arrays.asList("opt3", "opt4"), builder.getJvmArgsPrepend().get());
     }
 
     @Test