Skip to content

Commit

Permalink
minor optimizations and simplifications to JsonNullable (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
bratkartoffel authored Dec 10, 2022
1 parent 8bab929 commit 4485fd1
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/main/java/org/openapitools/jackson/nullable/JsonNullable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import java.io.Serializable;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Consumer;

public class JsonNullable<T> implements Serializable {

private static final long serialVersionUID = 1L;

private static final JsonNullable<?> UNDEFINED = new JsonNullable<Object>(null, false);
private static final JsonNullable<?> UNDEFINED = new JsonNullable<>(null, false);

private T value;
private final T value;

private boolean isPresent;
private final boolean isPresent;

private JsonNullable(T value, boolean isPresent) {
this.value = value;
Expand All @@ -22,8 +23,8 @@ private JsonNullable(T value, boolean isPresent) {
/**
* Create a <code>JsonNullable</code> representing an undefined value (not present).
*
* @param <T>
* @return
* @param <T> a type wildcard
* @return an empty <code>JsonNullable</code> with no value defined
*/
public static <T> JsonNullable<T> undefined() {
@SuppressWarnings("unchecked")
Expand All @@ -39,7 +40,7 @@ public static <T> JsonNullable<T> undefined() {
* @return the <code>JsonNullable</code> with the submitted value present.
*/
public static <T> JsonNullable<T> of(T value) {
return new JsonNullable<T>(value, true);
return new JsonNullable<>(value, true);
}

/**
Expand Down Expand Up @@ -94,21 +95,13 @@ public boolean equals(Object obj) {
}

JsonNullable<?> other = (JsonNullable<?>) obj;
return equals(value, other.value) &&
equals(isPresent, other.isPresent);
}

private static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
return Objects.equals(value, other.value) &&
isPresent == other.isPresent;
}

@Override
public int hashCode() {
int result = 31 + (value == null ? 0 : value.hashCode());
Boolean bool1 = Boolean.TRUE;
bool1.hashCode();
result = 31 * result + (isPresent ? 1231 : 1237);
return result;
return Objects.hash(value, isPresent);
}

@Override
Expand Down

0 comments on commit 4485fd1

Please sign in to comment.