Skip to content

Commit

Permalink
Merge pull request #29 from Over-Run/checkutil
Browse files Browse the repository at this point in the history
[Core] Remove CheckUtil::checkNotNull
  • Loading branch information
squid233 authored Aug 9, 2023
2 parents 229c299 + 40e1b3c commit 3a9f875
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 47 deletions.
39 changes: 0 additions & 39 deletions modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,4 @@ public static void checkNotNullptr(MemorySegment segment, Supplier<String> messa
public static void checkNotNullptr(MemorySegment segment, String message) throws IllegalStateException {
if (MemoryUtil.isNullptr(segment)) throw new IllegalStateException(message);
}

/**
* Checks whether the given object is not {@code null}.
*
* @param o the object.
* @throws IllegalStateException if <i>{@code object}</i> is {@code null}.
* @see #checkNotNull(Object, Supplier)
* @see #checkNotNull(Object, String)
*/
public static void checkNotNull(Object o) throws IllegalStateException {
checkNotNull(o, "condition == false");
}

/**
* Checks whether the given object is not {@code null}. The message of the exception is wrapped in a supplier
* to avoid side effect.
*
* @param o the object.
* @param messageSupplier the message supplier of the exception.
* @throws IllegalStateException if <i>{@code object}</i> is {@code null}.
* @see #checkNotNull(Object)
* @see #checkNotNull(Object, String)
*/
public static void checkNotNull(Object o, Supplier<String> messageSupplier) throws IllegalStateException {
if (o == null) throw new IllegalStateException(messageSupplier.get());
}

/**
* Checks whether the given object is not {@code null}.
*
* @param o the object.
* @param message the message of the exception.
* @throws IllegalStateException if <i>{@code object}</i> is {@code null}.
* @see #checkNotNull(Object)
* @see #checkNotNull(Object, Supplier)
*/
public static void checkNotNull(Object o, String message) throws IllegalStateException {
if (o == null) throw new IllegalStateException(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

/**
* The OpenGL loading function.
*
* <h2>Example</h2>
* {@snippet lang = java:
* // loads OpenGL forward-compatible profile
* import overrungl.util.CheckUtil;
* CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");
* import java.util.Objects;
* Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");
* }
*
* @author squid233
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.util.Objects;

import static java.lang.foreign.ValueLayout.JAVA_INT;

Expand Down Expand Up @@ -105,7 +106,7 @@ private void init(Arena arena) {
}

private void load() {
CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import overrungl.util.CheckUtil;

import java.lang.foreign.MemorySegment;
import java.util.Objects;

/**
* Tests basic GLFW and OpenGL
Expand Down Expand Up @@ -79,7 +80,7 @@ private void init() {
}

private void load() {
CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.util.Objects;

import static java.lang.foreign.ValueLayout.JAVA_INT;

Expand Down Expand Up @@ -91,7 +92,7 @@ private void init() {
}

private void load(Arena arena) {
CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
GL.enable(GL.TEXTURE_2D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.util.Objects;

import static java.lang.foreign.ValueLayout.JAVA_INT;

Expand Down Expand Up @@ -97,7 +98,7 @@ private void init() {
}

private void load(Arena arena) {
CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");

GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.lang.foreign.Arena;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.util.Objects;

/**
* Tests OpenGL 3.3 instanced rendering
Expand Down Expand Up @@ -109,7 +110,7 @@ private void init() {
}

private void load(Arena arena) {
CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");
Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL");

debugProc = GLUtil.setupDebugMessageCallback();
GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);
Expand Down

0 comments on commit 3a9f875

Please sign in to comment.