|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.perforce.p4java.option.Options
public abstract class Options
Abstract P4Java method options superclass. Supplies the very basic plumbing for the method-specific options classes, including the associated generic options processing gubbins.
Field Summary | |
---|---|
protected boolean |
immutable
If true, this Options object is (theoretically) immutable. |
protected List<String> |
optionList
The list of options strings associated with this Option. |
protected static String |
OPTPFX
String used to prefix options for the server. |
Constructor Summary | |
---|---|
Options()
Default constructor. |
|
Options(String... options)
Construct a new immutable Options object using the passed-in strings as the options. |
Method Summary | |
---|---|
protected String |
applyRule(String ruleName,
String serverOptStr,
boolean value)
Apply an optional rule to a boolean option value. |
protected String |
applyRule(String ruleName,
String serverOptStr,
int value)
Apply an optional rule to an integer option value. |
protected String |
applyRule(String ruleName,
String serverOptStr,
long value)
Apply an optional rule to a long option value. |
protected String |
applyRule(String ruleName,
String serverOptStr,
String value)
Apply an optional rule to a string option value. |
List<String> |
getOptions()
Return the options string list associated with this object, if any. |
boolean |
isImmutable()
|
List<String> |
processFields(String optsSpecs,
Object... opts)
Process command method options according to a simple getopts-like options specifier string. |
abstract List<String> |
processOptions(IServer server)
Turn this (specific) options object into a list of strings to be sent to the Perforce server as options for a specific command. |
Options |
setImmutable(boolean immutable)
|
Options |
setOptions(String... options)
Set the options string list associated with this options object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected List<String> optionList
protected boolean immutable
This can be useful for Options objects intended for shared and constant use, and can bypass quite a lot of options evaluation; but note that in general it should only be used when you're certain that options don't change or are not reliant on dynamic circumstances.
Note that immutable is always set when the string constructor is used, which can have surprising implications if this fact is forgotten down the line. Note that subclass implementations are not bound to observe immutability, in which case the class should ensure (by overriding, etc.) that isImmutable() always returns false.
protected static final String OPTPFX
Constructor Detail |
---|
public Options()
public Options(String... options)
WARNING: you should not pass more than one option or argument in each string parameter. Each option or argument should be passed-in as its own separate string parameter, without any spaces between the option and the option value (if any).
The intention here is to provide a way to bypass the various method-specific options setters with a simple mechanism to allow for constructs like this:
new Options("-m10", "-uhreid");where the individual options strings correspond exactly to the Perforce server arguments and are passed to the server as is (unless a callback intervenes). Options passed in like this will normally take precedence over any options set using other mechanisms.
NOTE: setting options this way always bypasses the internal options values, and getter methods against the individual values corresponding to the strings passed in to this constructor will not normally reflect the string's setting. Do not use this constructor unless you know what you're doing and / or you do not also use the field getters and setters.
options
- possibly-null option strings.Method Detail |
---|
public List<String> getOptions()
public Options setOptions(String... options)
WARNING: you should not pass more than one option or argument in each string parameter. Each option or argument should be passed-in as its own separate string parameter, without any spaces between the option and the option value (if any).
The intention here is to provide a way to bypass the various method-specific options setters with a simple mechanism to allow for constructs like this:
opts = new Options(); opts.setOptions("-m10", "-uhreid");where the individual options strings correspond exactly to the Perforce server arguments and are passed to the server as is (unless a callback intervenes). Options passed in like this may take precedence over any options set using other mechanisms.
options
- possibly-null option strings list
public abstract List<String> processOptions(IServer server) throws OptionsException
The method is used by the server object to generate the string-based arguments expected by the Perforce server corresponding to the state of this method-specific options object. Will return an empty list if there are no "interesting" options set or available. May simply return the superclass options string list if is non-null, but that behaviour is neither guaranteed nor required.
Note that this method is not intended to be called directly by users but by the underlying P4Java plumbing; odd results may occur if this method is called in other contexts.
server
- possibly-null IServer representing the Perforce server
the options are to be used against. If this parameter is
null, it is acceptable to throw an OptionsException, but
it is also possible to ignore it and do the best you can
with what you've got...
OptionsException
- if an error occurs in options processing that is
not some species of ConnectionException, RequestException,
AccessException, etc.public List<String> processFields(String optsSpecs, Object... opts) throws OptionsException
optsList = processFields("i:c:cl s:j b:i i:m:gtz", opts.getChangelistId(), opts.getJobId(), opts.isIncludeIntegrations(), opts.getMaxFixes())The format of the optsSpecs string parameter is:
typespec:server-flag[:rulename]where typespec is currently one of:
i -- integer; assumes the corresponding argument is an int; will generally just concatenate the flag and the value. b -- boolean; assumes the corresponding argument is a boolean; will normally only return the corresponding flag if true. s -- string; assumes the corresponding argument is a string; will normally just concatenate the flag and the value if the value is non-null.and server-flag is the flag string associated with this option when sent to the Perforce server, and where the optional rulename is passed to the relevant applyRule method. See the individual applyRule documentation below for rule processing details. Note that use of this method is entirely voluntary, and that it does not always work for non-simple cases. Note also that both the general implementation and the rules section will probably expand a bit over time.
optsSpecs
- non-null options specifier string as specified aboveopts
- non-null options to be processed
OptionsException
- if any errors occurred during options
processing.protected String applyRule(String ruleName, String serverOptStr, int value) throws OptionsException
This version of applyRules implements the rules specified below:
"gtz": don't return anything unless the value is > 0; typically used for things like maxUsers or maxRows. "cl": ignore negative values; convert 0 to the string "default". Typically used for changelists. "clz": ignore non-positive values; typically used for changelists where we let the server infer "default" for IChangelist.DEFAULT rather than spelling it out. "dcn": implements the -dc[n] rule for diff contexts, i.e. if the int value is zero, emit the flag alone; if it's positive, emit the flag with the int value attached; if it's negative, don't emit anything.If the passed-in ruleName is non-null and not recognized, the behaviour is the same as if a null rule name was passed in.
ruleName
- rule name string from the options spec string. If null, no
rule was specified.serverOptStr
- the flag string to be sent to the Perforce server prefixing
this valuevalue
- the integer value itself.
OptionsException
- if any errors occurred during options
processing.protected String applyRule(String ruleName, String serverOptStr, long value) throws OptionsException
This version of applyRules implements the rules specified below:
"gtz": don't return anything unless the value is > 0. "gez": don't return anything unless the value is >= 0.If the passed-in ruleName is non-null and not recognized, the behaviour is the same as if a null rule name was passed in.
ruleName
- rule name string from the options spec string. If null, no
rule was specified.serverOptStr
- the flag string to be sent to the Perforce server prefixing
this valuevalue
- the long value itself.
OptionsException
- if any errors occurred during options
processing.protected String applyRule(String ruleName, String serverOptStr, String value) throws OptionsException
There are currently no rules recognised or implemented in this method.
ruleName
- rule name string from the options spec string. If null, no
rule was specified.serverOptStr
- the flag string to be sent to the Perforce server prefixing
this valuevalue
- the string value itself; may be null.
OptionsException
- if any errors occurred during options
processing.protected String applyRule(String ruleName, String serverOptStr, boolean value) throws OptionsException
There are currently no rules recognised or implemented in this method.
ruleName
- rule name string from the options spec string. If null, no
rule was specified.serverOptStr
- the flag string to be sent to the Perforce server prefixing
this valuevalue
- the boolean value itself.
OptionsException
- if any errors occurred during options
processing.public boolean isImmutable()
public Options setImmutable(boolean immutable)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |