bdsup2sub.utils.optional.Optional Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2011 The Guava Authors, Miklos Juhasz (mjuhasz)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package bdsup2sub.utils.optional;
import java.io.Serializable;
public abstract class Optional implements Serializable {
private static final long serialVersionUID = 0;
public static Optional absent() {
return (Optional) Absent.INSTANCE;
}
public static Optional of(T reference) {
return new Present(checkNotNull(reference));
}
private static T checkNotNull(T reference) {
if (reference == null) {
throw new NullPointerException();
}
return reference;
}
public static Optional fromNullable(T nullableReference) {
return (nullableReference == null)
? Optional.absent()
: new Present(nullableReference);
}
Optional() {
}
public abstract boolean isPresent();
public abstract T get();
public abstract Object orNull();
@Override
public abstract boolean equals(Object object);
@Override
public abstract int hashCode();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy