Sets the value of the local. It's similar to update but receives an optional value. @param opt optional value to set.
(final Optional<T> opt)
| 139 | * @param opt optional value to set. |
| 140 | */ |
| 141 | public final void set(final Optional<T> opt) { |
| 142 | Optional<?>[] ctx = threadLocal.get(); |
| 143 | |
| 144 | if (ctx == null) |
| 145 | ctx = new Optional<?>[size]; |
| 146 | else { |
| 147 | final Optional<?>[] oldCtx = ctx; |
| 148 | ctx = new Optional<?>[size]; |
| 149 | System.arraycopy(oldCtx, 0, ctx, 0, oldCtx.length); |
| 150 | } |
| 151 | |
| 152 | ctx[position] = opt; |
| 153 | threadLocal.set(ctx); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Gets the current value of the local. |