All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lwjgl.system.Configuration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright LWJGL. All rights reserved.
 * License terms: https://www.lwjgl.org/license
 */
package org.lwjgl.system;

import org.lwjgl.system.MemoryUtil.*;

import javax.annotation.*;
import java.io.*;
import java.util.function.*;

/**
 * This class can be used to programmatically set the LWJGL runtime configuration. It is an alternative to using system properties.
 *
 * 

Care must be taken when setting static options. Such options are only read once or cached in {@code static final} fields. They must be * configured through this class before touching any other LWJGL class.

*/ public class Configuration { /** * Takes priority over {@code java.library.path}. It may contain one or more directory paths, separated by {@link File#pathSeparator}. * *

* Property: org.lwjgl.librarypath
*    Usage: Dynamic
*/ public static final Configuration LIBRARY_PATH = new Configuration<>("org.lwjgl.librarypath", StateInit.STRING); /** * Sets the mapping algorithm used to resolve the name of bundled shared libraries. Supported values: * *

    *
  • default - Maps {@code } to {@code }.
  • *
  • legacy - Maps {@code } to {@code is64bit(arch) ? : 32}.
  • *
  • <classpath> - A class that implements the {@link Function Function<String, String>} interface. It will be instantiated using reflection.
  • *
* *

When set programmatically, it can also be a {@link Function Function<String, String>} instance.

* *

* Property: org.lwjgl.system.bundledLibrary.nameMapper
*     Type: String or a {@link Function Function<String, String>} instance
*    Usage: Static

*/ public static final Configuration BUNDLED_LIBRARY_NAME_MAPPER = new Configuration<>("org.lwjgl.system.bundledLibrary.nameMapper", StateInit.STRING); /** * Sets the mapping algorithm used to resolve bundled shared libraries in the classpath/modulepath. Supported values: * *
    *
  • default - Maps {@code } to {@code /}.
  • *
  • legacy - Maps {@code } to {@code }.
  • *
  • <classpath> - A class that implements the {@link Function Function<String, String>} interface. It will be instantiated using reflection.
  • *
* *

When set programmatically, it can also be a {@link Function Function<String, String>} instance.

* *

* Property: org.lwjgl.system.bundledLibrary.nameMapper
*     Type: String or a {@link Function Function<String, String>} instance
*    Usage: Static

*/ public static final Configuration BUNDLED_LIBRARY_PATH_MAPPER = new Configuration<>("org.lwjgl.system.bundledLibrary.pathMapper", StateInit.STRING); /** * Changes the temporary directory name created by LWJGL when extracting shared libraries from JAR files. If this option is not set, it defaults to * lwjgl<user name>. * *

* Property: org.lwjgl.system.SharedLibraryExtractDirectory
*    Usage: Dynamic
*/ public static final Configuration SHARED_LIBRARY_EXTRACT_DIRECTORY = new Configuration<>( "org.lwjgl.system.SharedLibraryExtractDirectory", StateInit.STRING ); /** * Changes the path where LWJGL extracts shared libraries from JAR files. If this option is not set, LWJGL will try the following paths and the first * successful will be used: * *

    *
  • {@code System.getProperty("java.io.tmpdir")}/extractDir/version/
  • *
  • <working directory>/.extractDir/version/
  • *
  • {@code System.getProperty("user.home")}/.extractDir/version/
  • *
  • {@code Files.createTempDirectory("lwjgl", "")}
  • *
* * where: * *

     * extractDir = Configuration.SHARED_LIBRARY_EXTRACT_DIRECTORY
     * version = Version.getVersion().replace(' ', '-')
     * 
* *

* Property: org.lwjgl.system.SharedLibraryExtractPath
*    Usage: Dynamic

*/ public static final Configuration SHARED_LIBRARY_EXTRACT_PATH = new Configuration<>( "org.lwjgl.system.SharedLibraryExtractPath", StateInit.STRING ); /** * EXPERIMENTAL: Emulates {@link System#loadLibrary} behavior in {@link Library#loadNative}. * *

* Property: org.lwjgl.system.EmulateSystemLoadLibrary
*    Usage: Dynamic

*/ public static final Configuration EMULATE_SYSTEM_LOADLIBRARY = new Configuration<>( "org.lwjgl.system.EmulateSystemLoadLibrary", StateInit.BOOLEAN ); /** * Can be used to override the LWJGL library name. It can be an absolute path. * *

* Property: org.lwjgl.libname
*    Usage: Dynamic

*/ public static final Configuration LIBRARY_NAME = new Configuration<>("org.lwjgl.libname", StateInit.STRING); /** * Sets the allocator used for the {@link MemoryUtil} explicit memory management API * ({@link MemoryUtil#memAlloc memAlloc}/{@link MemoryUtil#memFree memFree}/etc). Supported values: * *
    *
  • jemalloc - The allocator provided by the jemalloc library.
  • *
  • rpmalloc - The allocator provided by the rpmalloc library.
    *

    LWJGL calls {@code rpmalloc_initialize} once, when the allocator is * created. It never calls {@code rpmalloc_finalize}. The user is responsible for calling {@code rpmalloc_thread_initialize} and * {@code rpmalloc_thread_finalize} when appropriate.

  • *
  • system - The default system memory allocator
  • *
  • <classpath> - A class that implements the {@link MemoryAllocator MemoryAllocator} interface. It will be instantiated using reflection.
  • *
* *

When set programmatically, it can also be a {@link MemoryAllocator MemoryAllocator} instance.

* *

* Property: org.lwjgl.system.allocator
*     Type: String or a {@link MemoryAllocator} instance
*    Usage: Static

*/ public static final Configuration MEMORY_ALLOCATOR = new Configuration<>("org.lwjgl.system.allocator", StateInit.STRING); /** * Sets the stack size, in kilobytes, that will be used in the default {@link MemoryStack} constructor. This value is also used for the LWJGL-managed, * thread-local, {@link MemoryStack} instances. * *

If this option is not set, it defaults to 64.

* *

* Property: org.lwjgl.system.stackSize
*    Usage: Static

*/ public static final Configuration STACK_SIZE = new Configuration<>("org.lwjgl.system.stackSize", StateInit.INT); /** * Sets the size of arrays cached in thread-local storage to minimize allocations while decoding text. * *

The memory cost for the cache is up to two arrays per thread that does text decoding. When the text length is up to this value, a cached array will * be used. When the text length is longer than this value, a new array buffer will be allocated.

* *

If this option is not set, it defaults to 8192. Setting the value to 0 will disable the array cache.

* *

* Property: org.lwjgl.system.arrayTLCSize
*    Usage: Static

*/ public static final Configuration ARRAY_TLC_SIZE = new Configuration<>("org.lwjgl.system.arrayTLCSize", StateInit.INT); /** * Set to true to disable LWJGL's basic checks. These are trivial checks that LWJGL performs to avoid JVM crashes, very useful during development. * Their performance impact is usually minimal, but they may be disabled for release builds. * *

* Property: org.lwjgl.util.NoChecks
*    Usage: Static

*/ public static final Configuration DISABLE_CHECKS = new Configuration<>("org.lwjgl.util.NoChecks", StateInit.BOOLEAN); /** * Set to true to disable LWJGL's function lookup checks. These checks ensure that required functions are not missing from dynamically loaded shared * libraries. This setting is useful when a trusted incompatible library must be loaded. * *

* Property: org.lwjgl.util.NoFunctionChecks
*    Usage: Dynamic

*/ public static final Configuration DISABLE_FUNCTION_CHECKS = new Configuration<>("org.lwjgl.util.NoFunctionChecks", StateInit.BOOLEAN); /** * Set to true to enable LWJGL's debug mode. Information messages will be printed to the {@link APIUtil#DEBUG_STREAM} and extra runtime checks will * be performed (some potentially expensive, performance-wise). * *

* Property: org.lwjgl.util.Debug
*    Usage: Static

*/ public static final Configuration DEBUG = new Configuration<>("org.lwjgl.util.Debug", StateInit.BOOLEAN); /** * When enabled, ShaderLibraryLoader exceptions will be printed to the {@link #DEBUG_STREAM}. * *

This option requires {@link #DEBUG} to be enabled.

* *

* Property: org.lwjgl.util.DebugLoader
*    Usage: Static

*/ public static final Configuration DEBUG_LOADER = new Configuration<>("org.lwjgl.util.DebugLoader", StateInit.BOOLEAN); /** * Can be set to override the default {@link APIUtil#DEBUG_STREAM}. It must be the name of a class that implements the * {@link Supplier Supplier<PrintStream>} interface. The class will be instantiated using reflection and the result of {@link Supplier#get get} will * become the {@code #DEBUG_STREAM} used by LWJGL. * *

When set programmatically, it can also be a {@link PrintStream} instance.

* *

* Property: org.lwjgl.util.DebugStream
*     Type: String or a {@link PrintStream} instance
*    Usage: Static

*/ public static final Configuration DEBUG_STREAM = new Configuration<>("org.lwjgl.util.DebugStream", StateInit.STRING); /** * Set to true to enable LWJGL's debug mode for the {@link MemoryUtil} explicit memory management API * ({@link MemoryUtil#memAlloc memAlloc}/{@link MemoryUtil#memFree memFree}/etc). All memory allocations through that API will be tracked and leaks * will be reported on JVM exit. The {@code memReport} methods can also be used. * *

When this option is enabled, a stacktrace is generated on every allocation, which may negatively impact performance. If this becomes a serious issue, * the JVM option {@code -XX:MaxJavaStackTraceDepth=d} (where {@code d >= 6}) can be used to reduce the overhead.

* *

* Property: org.lwjgl.util.DebugAllocator
*    Usage: Static

*/ public static final Configuration DEBUG_MEMORY_ALLOCATOR = new Configuration<>("org.lwjgl.util.DebugAllocator", StateInit.BOOLEAN); /** * Set to false to disable tracking of internal memory allocations, in native shared libraries that have been set up to use the LWJGL memory allocator. * *

If this option is not set, it defaults to true.

* *

* Property: org.lwjgl.util.DebugAllocator.internal
*    Usage: Static

*/ public static final Configuration DEBUG_MEMORY_ALLOCATOR_INTERNAL = new Configuration<>("org.lwjgl.util.DebugAllocator.internal", StateInit.BOOLEAN); /** * Set to true to enable LWJGL's debug mode for the {@link MemoryStack}. When using the stack, each frame should be popped in the same method that pushed * it. If this symmetry is broken, this mode will report it immediately. * *

When this option is enabled, a stacktrace is generated on every push or pop to the stack, which may negatively impact performance. If this becomes a * serious issue, the JVM option {@code -XX:MaxJavaStackTraceDepth=d} (where {@code d >= 5}) can be used to reduce the overhead.

* *

* Property: org.lwjgl.util.DebugStack
*    Usage: Static

*/ public static final Configuration DEBUG_STACK = new Configuration<>("org.lwjgl.util.DebugStack", StateInit.BOOLEAN); /** * When enabled, capabilities classes will print an error message when they fail to retrieve a function pointer. * *

Function pointers in such classes are retrieved unconditionally, so this option may generate a lot of output and many false negatives.

* *

This option requires {@link #DEBUG} to be enabled.

* *

* Property: org.lwjgl.util.DebugFunctions
*    Usage: Static

*/ public static final Configuration DEBUG_FUNCTIONS = new Configuration<>("org.lwjgl.util.DebugFunctions", StateInit.BOOLEAN); // -- ASSIMP /** Similar to {@link #LIBRARY_NAME} for the AssImp library (org.lwjgl.assimp.libname). */ public static final Configuration ASSIMP_LIBRARY_NAME = new Configuration<>("org.lwjgl.assimp.libname", StateInit.STRING); // -- BGFX /** Similar to {@link #LIBRARY_NAME} for the BGFX library (org.lwjgl.bgfx.libname). */ public static final Configuration BGFX_LIBRARY_NAME = new Configuration<>("org.lwjgl.bgfx.libname", StateInit.STRING); // -- CUDA /** Similar to {@link #LIBRARY_NAME} for the CUDA Driver library – nvcuda (org.lwjgl.cuda.libname). */ public static final Configuration CUDA_LIBRARY_NAME = new Configuration<>("org.lwjgl.cuda.libname", StateInit.STRING); /** * By default, when LWJGL detects multiple CUDA Toolkits, it will use the toolkit with the greatest version. This option can be used to force a specific * CUDA Toolkit version. * *

* Property: org.lwjgl.cuda.toolkit.version
*    Usage: Static

*/ public static final Configuration CUDA_TOOLKIT_VERSION = new Configuration<>("org.lwjgl.cuda.toolkit.version", StateInit.STRING); /** * By default, LWJGL will try to detect CUDA Toolkits in the default installation folder. This option can be used to load toolkit libraries from a * non-standard installation folder. * *

* Property: org.lwjgl.cuda.toolkit.path
*    Usage: Static

*/ public static final Configuration CUDA_TOOLKIT_PATH = new Configuration<>("org.lwjgl.cuda.toolkit.path", StateInit.STRING); /** Similar to {@link #LIBRARY_NAME} for the CUDA NVRTC library (org.lwjgl.cuda.nvrtc.libname). */ public static final Configuration CUDA_NVRTC_LIBRARY_NAME = new Configuration<>("org.lwjgl.cuda.nvrtc.libname", StateInit.STRING); /** Similar to {@link #LIBRARY_NAME} for the CUDA NVRTC Builtins library (org.lwjgl.cuda.nvrtc-builtins.libname). */ public static final Configuration CUDA_NVRTC_BUILTINS_LIBRARY_NAME = new Configuration<>("org.lwjgl.cuda.nvrtc-builtins.libname", StateInit.STRING); /** * By default, CUDA uses the legacy default stream. To enable per-thread synchronization, set this option to {@code true} before initializing the CUDA * driver. * *

To check if the CUDA driver supports PTDS, call {@code org.lwjgl.cuda.CUDA.isPerThreadDefaultStreamSupported()}

* *

* Property: org.lwjgl.cuda.ptds
*    Usage: Static

*/ public static final Configuration CUDA_API_PER_THREAD_DEFAULT_STREAM = new Configuration<>("org.lwjgl.cuda.ptds", StateInit.BOOLEAN); // -- EGL /** * By default, LWJGL will automatically initialize the EGL library, when it is first accessed. Set this property to disable this behavior. * *

* Property: org.lwjgl.egl.explicitInit
*    Usage: Static

*/ public static final Configuration EGL_EXPLICIT_INIT = new Configuration<>("org.lwjgl.egl.explicitInit", StateInit.BOOLEAN); /** Similar to {@link #LIBRARY_NAME} for the EGL library (org.lwjgl.egl.libname). */ public static final Configuration EGL_LIBRARY_NAME = new Configuration<>("org.lwjgl.egl.libname", StateInit.STRING); /** Similar to {@link #OPENGL_EXTENSION_FILTER} for the EGL library (org.lwjgl.egl.extensionFilter). */ public static final Configuration EGL_EXTENSION_FILTER = new Configuration<>("org.lwjgl.egl.extensionFilter", StateInit.STRING); // -- GLFW /** Similar to {@link #LIBRARY_NAME} for the GLFW library (org.lwjgl.glfw.libname). */ public static final Configuration GLFW_LIBRARY_NAME = new Configuration<>("org.lwjgl.glfw.libname", StateInit.STRING); /** * By default, LWJGL will check if certain GLFW functions are called on the first thread of the process and fail if that is not the case. Set this property * to false to disable this behavior. * *

* Property: org.lwjgl.glfw.checkThread0
*    Usage: Static

*/ public static final Configuration GLFW_CHECK_THREAD0 = new Configuration<>("org.lwjgl.glfw.checkThread0", StateInit.BOOLEAN); // -- JAWT /** Similar to {@link #LIBRARY_NAME} for the jawt library (org.lwjgl.system.jawt.libname). */ public static final Configuration JAWT_LIBRARY_NAME = new Configuration<>("org.lwjgl.system.jawt.libname", StateInit.STRING); // -- JEMALLOC /** Similar to {@link #LIBRARY_NAME} for the jemalloc library (org.lwjgl.system.jemalloc.libname). */ public static final Configuration JEMALLOC_LIBRARY_NAME = new Configuration<>("org.lwjgl.system.jemalloc.libname", StateInit.STRING); // -- LLVM /** Similar to {@link #LIBRARY_NAME} for the LLVM library (org.lwjgl.llvm.libname). */ public static final Configuration LLVM_LIBRARY_NAME = new Configuration<>("org.lwjgl.llvm.libname", StateInit.STRING); /** Similar to {@link #LIBRARY_NAME} for the LLVM/Clang Library (org.lwjgl.llvm.clang.libname). */ public static final Configuration LLVM_CLANG_LIBRARY_NAME = new Configuration<>("org.lwjgl.llvm.clang.libname", StateInit.STRING); /** Similar to {@link #LIBRARY_NAME} for the LLVM/LTO library (org.lwjgl.llvm.clang.libname). */ public static final Configuration LLVM_LTO_LIBRARY_NAME = new Configuration<>("org.lwjgl.llvm.lto.libname", StateInit.STRING); // -- ODBC /** Similar to {@link #LIBRARY_NAME} for the ODBC library (org.lwjgl.odbc.libname). */ public static final Configuration ODBC_LIBRARY_NAME = new Configuration<>("org.lwjgl.odbc.libname", StateInit.STRING); // -- OPENAL /** Similar to {@link #EGL_EXPLICIT_INIT} for the OpenAL library (org.lwjgl.openal.explicitInit). */ public static final Configuration OPENAL_EXPLICIT_INIT = new Configuration<>("org.lwjgl.openal.explicitInit", StateInit.BOOLEAN); /** Similar to {@link #LIBRARY_NAME} for the OpenAL library (org.lwjgl.openal.libname). */ public static final Configuration OPENAL_LIBRARY_NAME = new Configuration<>("org.lwjgl.openal.libname", StateInit.STRING); /** Similar to {@link #OPENGL_EXTENSION_FILTER} for the OpenAL library (org.lwjgl.openal.extensionFilter). */ public static final Configuration OPENAL_EXTENSION_FILTER = new Configuration<>("org.lwjgl.openal.extensionFilter", StateInit.STRING); // -- OPENCL /** Similar to {@link #EGL_EXPLICIT_INIT} for the OpenCL library (org.lwjgl.opencl.explicitInit). */ public static final Configuration OPENCL_EXPLICIT_INIT = new Configuration<>("org.lwjgl.opencl.explicitInit", StateInit.BOOLEAN); /** Similar to {@link #LIBRARY_NAME} for the OpenCL library (org.lwjgl.opencl.libname). */ public static final Configuration OPENCL_LIBRARY_NAME = new Configuration<>("org.lwjgl.opencl.libname", StateInit.STRING); /** Similar to {@link #OPENGL_EXTENSION_FILTER} for the OpenCL library (org.lwjgl.opencl.extensionFilter). */ public static final Configuration OPENCL_EXTENSION_FILTER = new Configuration<>("org.lwjgl.opencl.extensionFilter", StateInit.STRING); // -- OPENGL /** Similar to {@link #EGL_EXPLICIT_INIT} for the OpenGL library (org.lwjgl.opengl.explicitInit). */ public static final Configuration OPENGL_EXPLICIT_INIT = new Configuration<>("org.lwjgl.opengl.explicitInit", StateInit.BOOLEAN); /** Similar to {@link #LIBRARY_NAME} for the OpenGL library (org.lwjgl.opengl.libname). */ public static final Configuration OPENGL_LIBRARY_NAME = new Configuration<>("org.lwjgl.opengl.libname", StateInit.STRING); /** * Can be used to limit the maximum available OpenGL version. This can be useful to ensure that an application has not accidentally used features only * available in a higher OpenGL version. * *

When set programmatically, it can also be an {@link APIUtil.APIVersion} instance.

* *

* Property: org.lwjgl.opengl.maxVersion
*     Type: String (M.n) or an {@link APIUtil.APIVersion} instance
*    Usage: Static

*/ public static final Configuration OPENGL_MAXVERSION = new Configuration<>("org.lwjgl.opengl.maxVersion", StateInit.STRING); /** * Can be used to disable specific extensions. This can be useful to ensure that an application behaves correctly with or without an extension. Supported * values: * *
    *
  • comma-delimited string - A list of extension names to disable.
  • *
  • <classpath> - A class that implements the {@link Predicate Predicate<String>} interface. It will be instantiated using reflection.
  • *
* *

When set programmatically, it can also be:

*
    *
  • a {@link java.util.List List<String>} instance - A list of extension names to disable.
  • *
  • a {@link Predicate}<String> instance - A predicate that accepts an extension name and returns true if it should be disabled.
  • *
*/ public static final Configuration OPENGL_EXTENSION_FILTER = new Configuration<>("org.lwjgl.opengl.extensionFilter", StateInit.STRING); // -- OPENGL ES /** Similar to {@link #EGL_EXPLICIT_INIT} for the OpenGL ES library (org.lwjgl.opengles.explicitInit). */ public static final Configuration OPENGLES_EXPLICIT_INIT = new Configuration<>("org.lwjgl.opengles.explicitInit", StateInit.BOOLEAN); /** Similar to {@link #LIBRARY_NAME} for the OpenGL ES library (org.lwjgl.opengles.libname). */ public static final Configuration OPENGLES_LIBRARY_NAME = new Configuration<>("org.lwjgl.opengles.libname", StateInit.STRING); /** Similar to {@link #OPENGL_MAXVERSION} for the OpenGL ES library (org.lwjgl.opengles.maxVersion). */ public static final Configuration OPENGLES_MAXVERSION = new Configuration<>("org.lwjgl.opengles.maxVersion", StateInit.STRING); /** Similar to {@link #OPENGL_EXTENSION_FILTER} for the OpenGL ES library (org.lwjgl.opengles.extensionFilter). */ public static final Configuration OPENGLES_EXTENSION_FILTER = new Configuration<>("org.lwjgl.opengles.extensionFilter", StateInit.STRING); /** * Defines the API that manages OpenGL ES contexts. Supported values: * *
    *
  • EGL - context management is provided by EGL.
  • *
  • native - context management is provided by the native platform.
    *
* *

If this option is not set, LWJGL will first attempt to use EGL. If EGL is not available, it will attempt to use the native platform API.

* *

* Property: org.lwjgl.opengl.contextAPI
*     Type: String
*    Usage: Dynamic

*/ public static final Configuration OPENGLES_CONTEXT_API = new Configuration<>("org.lwjgl.opengles.contextAPI", StateInit.STRING); // -- OPENVR /** Similar to {@link #LIBRARY_NAME} for the OpenVR library (org.lwjgl.openvr.libname). */ public static final Configuration OPENVR_LIBRARY_NAME = new Configuration<>("org.lwjgl.openvr.libname", StateInit.STRING); // -- OPUS /** Similar to {@link #LIBRARY_NAME} for the Opus library (org.lwjgl.opus.libname). */ public static final Configuration OPUS_LIBRARY_NAME = new Configuration<>("org.lwjgl.opus.libname", StateInit.STRING); // -- SHADERC /** Similar to {@link #LIBRARY_NAME} for the Shaderc libshaderc library (org.lwjgl.shaderc.libname). */ public static final Configuration SHADERC_LIBRARY_NAME = new Configuration<>("org.lwjgl.shaderc.libname", StateInit.STRING); /** Similar to {@link #LIBRARY_NAME} for the Shaderc libshaderc_spvc library (org.lwjgl.shaderc_spvc.libname). */ public static final Configuration SHADERC_SPVC_LIBRARY_NAME = new Configuration<>("org.lwjgl.shaderc.spvc.libname", StateInit.STRING); // -- SPVC /** Similar to {@link #LIBRARY_NAME} for the SPIRV-Cross library (org.lwjgl.spvc.libname). */ public static final Configuration SPVC_LIBRARY_NAME = new Configuration<>("org.lwjgl.spvc.libname", StateInit.STRING); // -- VULKAN /** Similar to {@link #EGL_EXPLICIT_INIT} for the Vulkan library (org.lwjgl.vulkan.explicitInit). */ public static final Configuration VULKAN_EXPLICIT_INIT = new Configuration<>("org.lwjgl.vulkan.explicitInit", StateInit.BOOLEAN); /** Similar to {@link #LIBRARY_NAME} for the Vulkan library (org.lwjgl.vulkan.libname). */ public static final Configuration VULKAN_LIBRARY_NAME = new Configuration<>("org.lwjgl.vulkan.libname", StateInit.STRING); private interface StateInit extends Function { StateInit BOOLEAN = property -> { String value = System.getProperty(property); return value == null ? null : Boolean.parseBoolean(value); }; StateInit INT = Integer::getInteger; StateInit STRING = System::getProperty; } private final String property; @Nullable private T state; Configuration(String property, StateInit init) { this.property = property; this.state = init.apply(property); } public String getProperty() { return property; } /** * Sets the option value. * * @param value the value to set */ public void set(@Nullable T value) { this.state = value; } /** * Returns the option value. * *

If the option value has not been set, null will be returned.

*/ @Nullable public T get() { return state; } /** * Returns the option value. * *

If the option value has not been set, the specified default value will be returned.

* * @param defaultValue the default value */ public T get(T defaultValue) { T state = this.state; if (state == null) { state = defaultValue; } return state; } }