All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.g2forge.alexandria.java.nestedstate.FlagState Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
package com.g2forge.alexandria.java.nestedstate;

import com.g2forge.alexandria.java.close.ICloseable;

public class FlagState implements INestedState {
	protected boolean inside;

	protected void close(boolean expected, boolean previous) {
		if (inside != expected) throw new IllegalStateException();
		this.inside = previous;
	}

	@Override
	public Boolean get() {
		return inside;
	}

	@Override
	public ICloseable open(Boolean value) {
		final boolean previous = inside;
		final boolean expected = this.inside |= value;
		return () -> close(expected, previous);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy