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

com.g2forge.alexandria.java.resource.SimpleThreadResource Maven / Gradle / Ivy

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

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

public class SimpleThreadResource implements ICloseableResource {
	protected boolean valid;

	protected T value;

	public void close(T value) {
		if (!valid || (this.value != value)) 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 - 2024 Weber Informatics LLC | Privacy Policy