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

java.util.OptionalInt Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package java.util;

import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
import java.util.function.Supplier;

public final class OptionalInt {
	private static OptionalInt INSTANCE_EMPTY;

	private final boolean isPresent;
	private final int value;

	private OptionalInt(boolean isPresent, int value) {
		this.isPresent = isPresent;
		this.value = value;
	}

	public static OptionalInt empty() {
		if (INSTANCE_EMPTY == null) {
			INSTANCE_EMPTY = new OptionalInt(false, 0);
		}
		return INSTANCE_EMPTY;
	}

	public static OptionalInt of(int value) {
		return new OptionalInt(true, value);
	}

	native public int getAsInt();

	native public boolean isPresent();

	native public void ifPresent(IntConsumer consumer);

	native public int orElse(int other);

	native public int orElseGet(IntSupplier other);

	native public  int orElseThrow(Supplier exceptionSupplier) throws X;

	native public boolean equals(Object obj);

	native public int hashCode();

	native public String toString();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy