From d152c2b9115f7bc3b5411667b5b2c54a04b3f907 Mon Sep 17 00:00:00 2001 From: hanna Date: Sun, 17 May 2009 14:54:25 +0000 Subject: [PATCH] New GATKArgumentCollection caused a subtle bug with argument grouping and the help system. Fixed. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@738 348d0f76-0448-11de-a6fe-93d51630548a --- .../utils/cmdLine/ArgumentDefinitions.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java index e578c8e16..f336fbcfc 100755 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentDefinitions.java @@ -56,6 +56,18 @@ class ArgumentDefinitions implements Iterable { argumentDefinitions.add( definition ); } + // Find an existing argument definition group with this name. + // If one exists, merge this group into the other. + Iterator definitionGroupIterator = argumentDefinitionGroups.iterator(); + while( definitionGroupIterator.hasNext() ) { + ArgumentDefinitionGroup candidate = definitionGroupIterator.next(); + if( candidate.groupNameMatches(argumentDefinitionGroup) ) { + argumentDefinitionGroup = argumentDefinitionGroup.mergeInto(candidate); + definitionGroupIterator.remove(); + } + } + + // Otherwise, add the new group. argumentDefinitionGroups.add( argumentDefinitionGroup ); } @@ -179,6 +191,34 @@ class ArgumentDefinitionGroup implements Iterable { this.argumentDefinitions = Collections.unmodifiableCollection( argumentDefinitions ); } + /** + * Does the name of this argument group match the name of another? + */ + public boolean groupNameMatches( ArgumentDefinitionGroup other ) { + if( this.groupName == null && other.groupName == null ) + return true; + if( this.groupName == null && other.groupName != null ) + return false; + return this.groupName.equals(other.groupName); + } + + /** + * Merges another argument group into this argument group. Return a new + * group since argument groups are supposed to be immutable. Asserts that + * both argument groups have the same name. + */ + public ArgumentDefinitionGroup mergeInto( ArgumentDefinitionGroup other ) { + if( !groupNameMatches(other) ) + throw new StingException("Unable to merge two argument groups with differing names."); + + // Create a merged definition group. + Collection mergedDefinitions = new ArrayList(); + mergedDefinitions.addAll(this.argumentDefinitions); + mergedDefinitions.addAll(other.argumentDefinitions); + + return new ArgumentDefinitionGroup(groupName,mergedDefinitions); + } + /** * Iterate over the arguments in an argument definition group. * @return