
org.opentripplanner.framework.lang.Box Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
The newest version!
package org.opentripplanner.framework.lang;
import java.util.Objects;
import javax.annotation.Nullable;
/**
* A box around a mutable value reference. This can be used inside a lambda or passed into
* a function.
* @param the type of the wrapped value.
*/
public class Box {
private T value;
private Box(T value) {
this.value = value;
}
public Box() {
this(null);
}
public static Box empty() {
return new Box<>();
}
public static Box of(T value) {
return new Box<>(value);
}
@Nullable
public T get() {
return value;
}
public void set(@Nullable T value) {
this.value = value;
}
public boolean isEmpty() {
return value == null;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Box> box = (Box>) o;
return Objects.equals(value, box.value);
}
@Override
public int hashCode() {
return Objects.hash(value);
}
@Override
public String toString() {
return "[" + value + ']';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy