| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright 2011 Google Inc. |
| 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. |
| 15 */ |
| 16 |
| 17 package com.google.ipc.invalidation.util; |
| 18 |
| 19 /** |
| 20 * Container for a single arbitrary value. Useful when a nested callback needs |
| 21 * to modify a primitive type, which is ordinarily not possible as variables |
| 22 * available to nested callbacks need to be declared final. |
| 23 * |
| 24 * @param <T> Type of the value being boxed. |
| 25 * |
| 26 */ |
| 27 public class Box<T> { |
| 28 |
| 29 /** Contents of the box. */ |
| 30 private T value; |
| 31 |
| 32 /** Constructs a box with the given initial {@code value}. */ |
| 33 public Box(T value) { |
| 34 this.value = value; |
| 35 } |
| 36 |
| 37 /** Constructs a Box with {@code null} as the value. */ |
| 38 public Box() { |
| 39 this.value = null; |
| 40 } |
| 41 |
| 42 /** Constructs and returns a {@code Box} that wraps {@code objectValue}. */ |
| 43 public static <T> Box<T> of(T objectValue) { |
| 44 return new Box<T>(objectValue); |
| 45 } |
| 46 |
| 47 public void set(T objectValue) { |
| 48 this.value = objectValue; |
| 49 } |
| 50 |
| 51 public T get() { |
| 52 return value; |
| 53 } |
| 54 |
| 55 @Override |
| 56 public String toString() { |
| 57 return (value == null) ? null : value.toString(); |
| 58 } |
| 59 } |
| OLD | NEW |