2011-10-15 00:06:41 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011, The Broad Institute
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
|
* 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:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-16 03:03:33 +08:00
|
|
|
* Where an argument match originated, via the commandline or a custom provider.
|
2011-10-15 00:06:41 +08:00
|
|
|
*/
|
|
|
|
|
public class ArgumentMatchSource implements Comparable<ArgumentMatchSource> {
|
|
|
|
|
public static final ArgumentMatchSource COMMAND_LINE = new ArgumentMatchSource(ArgumentMatchSourceType.CommandLine, null);
|
|
|
|
|
|
|
|
|
|
private final ArgumentMatchSourceType type;
|
2012-10-16 03:03:33 +08:00
|
|
|
private final String description;
|
2011-10-15 00:06:41 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates an argument match source from the specified file.
|
2012-10-16 03:03:33 +08:00
|
|
|
* @param description Where the arguments originated.
|
2011-10-15 00:06:41 +08:00
|
|
|
*/
|
2012-10-16 03:03:33 +08:00
|
|
|
public ArgumentMatchSource(String description) {
|
|
|
|
|
this(ArgumentMatchSourceType.Provider, description);
|
2011-10-15 00:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 03:03:33 +08:00
|
|
|
private ArgumentMatchSource(ArgumentMatchSourceType type, String description) {
|
|
|
|
|
if (type == ArgumentMatchSourceType.Provider && description == null)
|
|
|
|
|
throw new IllegalArgumentException("An argument match source provider cannot have a null description.");
|
2011-10-15 00:06:41 +08:00
|
|
|
this.type = type;
|
2012-10-16 03:03:33 +08:00
|
|
|
this.description = description;
|
2011-10-15 00:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArgumentMatchSourceType getType() {
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 03:03:33 +08:00
|
|
|
public String getDescription() {
|
|
|
|
|
return description;
|
2011-10-15 00:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
|
if (this == o) return true;
|
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
|
|
|
|
|
|
ArgumentMatchSource that = (ArgumentMatchSource) o;
|
|
|
|
|
|
2012-10-16 03:03:33 +08:00
|
|
|
return (type == that.type) && (description == null ? that.description == null : description.equals(that.description));
|
2011-10-15 00:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int hashCode() {
|
|
|
|
|
int result = type != null ? type.hashCode() : 0;
|
2012-10-16 03:03:33 +08:00
|
|
|
result = 31 * result + (description != null ? description.hashCode() : 0);
|
2011-10-15 00:06:41 +08:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compares two sources, putting the command line first, then files.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int compareTo(ArgumentMatchSource that) {
|
|
|
|
|
int comp = this.type.compareTo(that.type);
|
|
|
|
|
if (comp != 0)
|
|
|
|
|
return comp;
|
|
|
|
|
|
2012-10-16 03:03:33 +08:00
|
|
|
String d1 = this.description;
|
|
|
|
|
String d2 = that.description;
|
2011-10-15 00:06:41 +08:00
|
|
|
|
2012-10-16 03:03:33 +08:00
|
|
|
if ((d1 == null) ^ (d2 == null)) {
|
|
|
|
|
// If one of the descriptions is null and the other is not
|
|
|
|
|
// put the null description first
|
|
|
|
|
return d1 == null ? -1 : 1;
|
2011-10-15 00:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
2012-10-16 03:03:33 +08:00
|
|
|
return d1 == null ? 0 : d1.compareTo(d2);
|
2011-10-15 00:06:41 +08:00
|
|
|
}
|
|
|
|
|
}
|