2010-04-20 07:00:08 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010 The Broad Institute
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2010-04-20 07:00:08 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
2010-04-20 23:26:32 +08:00
|
|
|
* files (the "Software"), to deal in the Software without
|
2010-04-20 07:00:08 +08:00
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
|
* conditions:
|
2010-04-20 23:26:32 +08:00
|
|
|
*
|
2010-04-20 07:00:08 +08:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
2010-04-20 23:26:32 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
2010-04-20 07:00:08 +08:00
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.broadinstitute.sting.commandline;
|
2009-12-08 03:23:12 +08:00
|
|
|
|
2010-09-12 23:07:38 +08:00
|
|
|
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
2009-12-08 03:23:12 +08:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2011-07-18 08:29:58 +08:00
|
|
|
import java.util.Collections;
|
2009-12-08 03:23:12 +08:00
|
|
|
import java.util.Iterator;
|
2011-07-18 08:29:58 +08:00
|
|
|
import java.util.List;
|
2009-12-08 03:23:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A group of argument definitions.
|
|
|
|
|
*/
|
|
|
|
|
public class ArgumentDefinitionGroup implements Iterable<ArgumentDefinition> {
|
|
|
|
|
/**
|
|
|
|
|
* Name of this group.
|
|
|
|
|
*/
|
|
|
|
|
public final String groupName;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The argument definitions associated with this group.
|
|
|
|
|
*/
|
|
|
|
|
public final List<ArgumentDefinition> argumentDefinitions;
|
|
|
|
|
|
|
|
|
|
public ArgumentDefinitionGroup( String groupName, List<ArgumentDefinition> argumentDefinitions ) {
|
|
|
|
|
this.groupName = groupName;
|
|
|
|
|
this.argumentDefinitions = Collections.unmodifiableList( 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 merge( ArgumentDefinitionGroup other ) {
|
|
|
|
|
if( !groupNameMatches(other) )
|
2010-09-12 23:07:38 +08:00
|
|
|
throw new ReviewedStingException("Unable to merge two argument groups with differing names.");
|
2009-12-08 03:23:12 +08:00
|
|
|
|
|
|
|
|
// Create a merged definition group.
|
|
|
|
|
List<ArgumentDefinition> mergedDefinitions = new ArrayList<ArgumentDefinition>();
|
|
|
|
|
mergedDefinitions.addAll(this.argumentDefinitions);
|
|
|
|
|
mergedDefinitions.addAll(other.argumentDefinitions);
|
|
|
|
|
|
|
|
|
|
return new ArgumentDefinitionGroup(groupName,mergedDefinitions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Iterate over the arguments in an argument definition group.
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Iterator<ArgumentDefinition> iterator() {
|
|
|
|
|
return argumentDefinitions.iterator();
|
|
|
|
|
}
|
2010-08-05 10:26:46 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reports whether all the arguments in this group are hidden.
|
|
|
|
|
* @return True if all are hidden, false if some or none are hidden.
|
|
|
|
|
*/
|
|
|
|
|
public boolean allHidden() {
|
|
|
|
|
for(ArgumentDefinition argumentDefinition: argumentDefinitions) {
|
|
|
|
|
if(!argumentDefinition.isHidden)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-12-08 03:23:12 +08:00
|
|
|
}
|