com.g2forge.alexandria.java.nestedstate.SingleGlobalState Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
package com.g2forge.alexandria.java.nestedstate;
import com.g2forge.alexandria.java.close.ICloseable;
public class SingleGlobalState implements ICloseableNestedState {
protected boolean valid;
protected T value;
public void close(T expected) {
if (!valid || (this.value != expected)) throw new IllegalStateException();
this.value = null;
this.valid = false;
}
@Override
public T get() {
return this.value;
}
@Override
public ICloseable open(T value) {
if (valid || (value != null)) throw new IllegalStateException();
this.value = value;
this.valid = true;
return () -> close(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy