package jalview.bin.argparser;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import jalview.bin.argparser.Arg.Opt;
+import jalview.util.FileUtils;
/**
* Helper class to allow easy extraction of information about specific argument
{
protected Map<Arg, ArgValues> m;
- protected ArgValuesMap()
+ private String linkedId;
+
+ protected ArgValuesMap(String linkedId)
{
+ this.linkedId = linkedId;
this.newMap();
}
- protected ArgValuesMap(Map<Arg, ArgValues> map)
+ protected ArgValuesMap(String linkedId, Map<Arg, ArgValues> map)
{
+ this.linkedId = linkedId;
this.m = map;
}
+ public String getLinkedId()
+ {
+ return linkedId;
+ }
+
private Map<Arg, ArgValues> getMap()
{
return m;
{
if (m == null || !m.containsKey(a))
return false;
- return a.hasOption(Opt.STRING) ? getArgValue(a) != null
- : this.getBoolean(a);
+ return a.hasOption(Opt.STRING) ? getArgValue(a) != null : true;
}
public boolean hasValue(Arg a, String val)
// specify an id in the subValues so wouldn't need to be guessed).
ArgValue closestAv = null;
int thisArgIndex = thisAv.getArgIndex();
+ if (!containsArg(a))
+ return null;
ArgValues compareAvs = this.getArgValues(a);
int closestNextIndex = Integer.MAX_VALUE;
for (ArgValue av : compareAvs.getArgValueList())
ArgValues avs = this.getArgValues(a);
return avs == null ? null : avs.getId(id);
}
+
+ /*
+ * This method returns the basename of the first --append or --open value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getBasename()
+ {
+ return getDirBasenameOrExtension(false, false);
+ }
+
+ /*
+ * This method returns the basename of the first --append or --open value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getExtension()
+ {
+ return getDirBasenameOrExtension(false, true);
+ }
+
+ /*
+ * This method returns the dirname of the first --append or --open value.
+ * Used primarily for substitutions in output filenames.
+ */
+ public String getDirname()
+ {
+ return getDirBasenameOrExtension(true, false);
+ }
+
+ public String getDirBasenameOrExtension(boolean dirname,
+ boolean extension)
+ {
+ String filename = null;
+ String appendVal = getValue(Arg.APPEND);
+ String openVal = getValue(Arg.OPEN);
+ if (appendVal != null)
+ filename = appendVal;
+ if (filename == null && openVal != null)
+ filename = openVal;
+ if (filename == null)
+ return null;
+
+ File file = new File(filename);
+ if (dirname)
+ {
+ return FileUtils.getDirname(file);
+ }
+ return extension ? FileUtils.getExtension(file)
+ : FileUtils.getBasename(file);
+ }
+
+ /*
+ * Checks if there is an Arg with Opt
+ */
+ public boolean hasArgWithOption(Opt o)
+ {
+ for (Arg a : getArgKeys())
+ {
+ if (a.hasOption(o))
+ return true;
+ }
+ return false;
+ }
}