T
- The type of option values.public class OptionKey<T> extends Object implements Serializable
DataStore
, etc).
OptionKey
s are used for aspects that usually do not need to be configured, except in a few specialized cases.
For example most data file formats read by SIS do not require the user to specify the character encoding, since the
encoding it is often given in the file header or in the format specification. However if SIS may have to read plain
text files and the default platform encoding is not suitable, then the user can specify the desired encoding
explicitely using the ENCODING
option.
All options are hints and may be silently ignored. For example most DataStore
s will ignore the
ENCODING
option if irrelevant to their format, or if the encoding is specified in the data file header.
Options are transitive: if a service uses others services for its internal working, the given options may also be given to those dependencies, at implementation choice.
public final class MyOptionKey<T> extends OptionKey<T> { public static final OptionKey<String> MY_OPTION = new MyOptionKey<>("MY_OPTION", String.class); private MyOptionKey(final String name, final Class<T> type) { super(name, type); } }
Defined in the sis-utility
module
Modifier and Type | Field and Description |
---|---|
static OptionKey<ByteBuffer> |
BYTE_BUFFER
The byte buffer to use for input/output operations.
|
static OptionKey<Charset> |
ENCODING
The character encoding of document content.
|
static OptionKey<Object[]> |
OPEN_OPTIONS
Whether a storage object (e.g. a
DataStore ) shall be opened in read,
write, append or other modes. |
static OptionKey<String> |
URL_ENCODING
The encoding of a URL (not the encoding of the document content).
|
Modifier | Constructor and Description |
---|---|
protected |
OptionKey(String name,
Class<T> type)
Creates a new key of the given name for values of the given type.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object object)
Returns
true if the given object is an instance of the same class having the same name and type. |
Class<T> |
getElementType()
Returns the type of values associated to this option key.
|
String |
getName()
Returns the name of this option key.
|
T |
getValueFrom(Map<OptionKey<?>,?> options)
Returns the option value in the given map for this key, or
null if none. |
int |
hashCode()
Returns a hash code value for this object.
|
Map<OptionKey<?>,Object> |
setValueInto(Map<OptionKey<?>,Object> options,
T value)
Sets a value for this option key in the given map, or in a new map if the given map is
null . |
String |
toString()
Returns a string representation of this option key.
|
public static final OptionKey<Charset> ENCODING
<?xml version="1.0" encoding="…"?>
declaration.
If this option is not provided, then the default value is the
platform default
.
public static final OptionKey<String> URL_ENCODING
String
or a URL
to a URI
or a File
. The following rules apply:
Example: Given the "file:Map%20with%20spaces.png"
URL, then:
"UTF-8"
or "ISO-8859-1"
, then:"file:Map%20with%20spaces.png"
;"file:Map with spaces.png"
.null
or is not provided, then:"file:Map%2520with%2520spaces.png"
,
i.e. the percent sign will be encoded as "%25"
;"file:Map%20with%20spaces.png"
.URLDecoder
public static final OptionKey<Object[]> OPEN_OPTIONS
DataStore
) shall be opened in read,
write, append or other modes. The main options that can be provided are:
Value | Meaning |
---|---|
"READ" | Open for reading data from the storage object. |
"WRITE" | Open for modifying existing data in the storage object. |
"APPEND" | Open for appending new data in the storage object. |
"CREATE" | Creates a new storage object (file or database) if it does not exist. |
java.nio.file.OpenOption[]
instead than
Object[]
and the constants listed in the above table are java.nio.file.StandardOpenOption
enumeration values.public static final OptionKey<ByteBuffer> BYTE_BUFFER
DataStore
implementations allow a byte buffer to be specified, thus allowing users to choose the buffer
capacity, whether the buffer is direct, or to recycle existing buffers.
It is user's responsibility to ensure that:
DataStore
instances.public String getName()
public final Class<T> getElementType()
public T getValueFrom(Map<OptionKey<?>,?> options)
null
if none.
This is a convenience method for implementors, which can be used as below:
public <T> T getOption(final OptionKey<T> key) { ArgumentChecks.ensureNonNull("key", key); return key.getValueFrom(options); }
options
- The map where to search for the value, or null
if not yet created.null
if none.public Map<OptionKey<?>,Object> setValueInto(Map<OptionKey<?>,Object> options, T value)
null
.
This is a convenience method for implementors, which can be used as below:
public <T> void setOption(final OptionKey<T> key, final T value) { ArgumentChecks.ensureNonNull("key", key); options = key.setValueInto(options, value); }
options
- The map where to set the value, or null
if not yet created.value
- The new value for the given option, or null
for removing the value.public boolean equals(Object object)
true
if the given object is an instance of the same class having the same name and type.public int hashCode()
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.