public abstract class Options
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected boolean |
immutable
If true, this Options object is (theoretically) immutable.
|
protected java.util.List<java.lang.String> |
optionList
The list of options strings associated with this Option.
|
Constructor and Description |
---|
Options()
Default constructor.
|
Options(java.lang.String... options)
Construct a new immutable Options object using the passed-in strings as
the options.
|
Modifier and Type | Method and Description |
---|---|
java.util.List<java.lang.String> |
getOptions()
Return the options string list associated with this object, if any.
|
boolean |
isImmutable() |
java.util.List<java.lang.String> |
processFields(java.lang.String optionSpecsString,
java.lang.Object... opts)
Process command method options according to a simple getopts-like options
specifier string.
|
abstract java.util.List<java.lang.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.
|
void |
setImmutable(boolean immutable) |
void |
setOptions(java.lang.String... options)
Set the options string list associated with this options object.
|
protected java.util.List<java.lang.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.
public Options()
public Options(java.lang.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.public void setOptions(java.lang.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 listpublic void setImmutable(boolean immutable)
public boolean isImmutable()
public java.util.List<java.lang.String> getOptions()
public java.util.List<java.lang.String> processFields(@Nonnull java.lang.String optionSpecsString, @Nullable java.lang.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 optionSpecsString 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.
optionSpecsString
- non-null options specifier string as specified aboveopts
- non-null options to be processedOptionsException
- if any errors occurred during options processing.public abstract java.util.List<java.lang.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.