Skip to content

Commit

Permalink
Replaced Objects.requireNonNullOrElse with custom method due to lack …
Browse files Browse the repository at this point in the history
…of emulation in GWT
  • Loading branch information
matthewhorridge committed May 20, 2024
1 parent c4a5648 commit 784cad3
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 38 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>edu.stanford.protege</groupId>
<artifactId>webprotege-gh-issues</artifactId>
<version>0.0.1</version>
<version>0.9.2</version>

<name>webprotege-gh-issues</name>
<description>webprotege-gh-issues</description>
Expand Down Expand Up @@ -103,7 +103,7 @@
<version>1.0.1</version>
<extensions>true</extensions>
<configuration>
<moduleName>edu.stanford.protege.github.issues</moduleName>
<moduleName>edu.stanford.protege.github.issues.GitHubIssues</moduleName>
</configuration>
</plugin>
</plugins>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/edu/stanford/protege/github/issues/GitHubIssues.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.stanford.protege.github.issues;

import com.google.gwt.core.client.EntryPoint;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-05-18
*/
public class GitHubIssues implements EntryPoint {

@Override
public void onModuleLoad() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public static GitHubComment get(@JsonProperty("id") long id,
@JsonProperty("author_association") GitHubAuthorAssociation authorAssociation) {
return new AutoValue_GitHubComment(
id,
Objects.requireNonNullElse(nodeId, ""),
Objects.requireNonNullElse(url, ""),
Objects.requireNonNullElse(htmlUrl, ""),
Objects.requireNonNullElse(body, ""),
Objects.requireNonNullElse(user, GitHubUser.empty()),
Objects.requireNonNullElse(createdAt, Instant.EPOCH),
Objects.requireNonNullElse(updatedAt, Instant.EPOCH),
Objects.requireNonNullElse(issueUrl, ""),
Objects.requireNonNullElse(authorAssociation, GitHubAuthorAssociation.NONE)
Helper.requireNonNullOrElse(nodeId, ""),
Helper.requireNonNullOrElse(url, ""),
Helper.requireNonNullOrElse(htmlUrl, ""),
Helper.requireNonNullOrElse(body, ""),
Helper.requireNonNullOrElse(user, GitHubUser.empty()),
Helper.requireNonNullOrElse(createdAt, Instant.EPOCH),
Helper.requireNonNullOrElse(updatedAt, Instant.EPOCH),
Helper.requireNonNullOrElse(issueUrl, ""),
Helper.requireNonNullOrElse(authorAssociation, GitHubAuthorAssociation.NONE)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,27 @@ public static GitHubIssue get(@JsonProperty("url") String url,
@JsonProperty("body") String body,
@JsonProperty("reactions") GitHubReactions reactions,
@JsonProperty("state_reason") @Nullable GitHubStateReason stateReason) {
return new AutoValue_GitHubIssue(Objects.requireNonNullElse(url, ""),
return new AutoValue_GitHubIssue(Helper.requireNonNullOrElse(url, ""),
id,
Objects.requireNonNullElse(nodeId, ""),
Helper.requireNonNullOrElse(nodeId, ""),
number,
Objects.requireNonNullElse(title, ""),
Objects.requireNonNullElse(user, GitHubUser.empty()),
Objects.requireNonNullElse(htmlUrl, ""),
Objects.requireNonNullElse(labels, List.of()),
Objects.requireNonNullElse(state, GitHubState.OPEN),
Helper.requireNonNullOrElse(title, ""),
Helper.requireNonNullOrElse(user, GitHubUser.empty()),
Helper.requireNonNullOrElse(htmlUrl, ""),
Helper.requireNonNullOrElse(labels, List.of()),
Helper.requireNonNullOrElse(state, GitHubState.OPEN),
locked,
assignee,
Objects.requireNonNullElse(assignees, List.of()),
Helper.requireNonNullOrElse(assignees, List.of()),
milestone,
comments,
Objects.requireNonNullElse(createdAt, Instant.EPOCH),
Objects.requireNonNullElse(updatedAt, Instant.EPOCH),
Objects.requireNonNullElse(closedAt, Instant.EPOCH),
Helper.requireNonNullOrElse(createdAt, Instant.EPOCH),
Helper.requireNonNullOrElse(updatedAt, Instant.EPOCH),
Helper.requireNonNullOrElse(closedAt, Instant.EPOCH),
closedBy,
Objects.requireNonNullElse(authorAssociation, GitHubAuthorAssociation.NONE),
Objects.requireNonNullElse(activeLockReason, ""),
Objects.requireNonNullElse(body, ""),
Helper.requireNonNullOrElse(authorAssociation, GitHubAuthorAssociation.NONE),
Helper.requireNonNullOrElse(activeLockReason, ""),
Helper.requireNonNullOrElse(body, ""),
reactions,
stateReason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public static GitHubLabel get(@JsonProperty("id") long id,
@JsonProperty("description") @Nullable String description) {
return new AutoValue_GitHubLabel(
id,
Objects.requireNonNullElse(nodeId, ""),
Objects.requireNonNullElse(url, ""),
Objects.requireNonNullElse(name, ""),
Objects.requireNonNullElse(color, ""),
Helper.requireNonNullOrElse(nodeId, ""),
Helper.requireNonNullOrElse(url, ""),
Helper.requireNonNullOrElse(name, ""),
Helper.requireNonNullOrElse(color, ""),
isDefault,
Objects.requireNonNullElse(description, ""));
Helper.requireNonNullOrElse(description, ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ public static GitHubMilestone get(@JsonProperty("url") @Nullable String url,
@JsonProperty("due_on") @Nullable Instant dueOn,
@JsonProperty("closed_at") @Nullable Instant closedAt) {
return new AutoValue_GitHubMilestone(
Objects.requireNonNullElse(url, ""),
Helper.requireNonNullOrElse(url, ""),
id,
Objects.requireNonNullElse(nodeId, ""),
Helper.requireNonNullOrElse(nodeId, ""),
number,
Objects.requireNonNullElse(title, ""),
Objects.requireNonNullElse(description, ""),
Objects.requireNonNullElse(creator, GitHubUser.empty()),
Objects.requireNonNullElse(openIssues, 0),
Helper.requireNonNullOrElse(title, ""),
Helper.requireNonNullOrElse(description, ""),
Helper.requireNonNullOrElse(creator, GitHubUser.empty()),
Helper.requireNonNullOrElse(openIssues, 0),
closedIssues,
Objects.requireNonNullElse(state, GitHubState.OPEN),
Helper.requireNonNullOrElse(state, GitHubState.OPEN),
createdAt,
updatedAt,
dueOn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static GitHubReactions get(@JsonProperty("url") String url,
@JsonProperty("heart") int heart,
@JsonProperty("rocket") int rocket,
@JsonProperty("eyes") int eyes) {
return new AutoValue_GitHubReactions(Objects.requireNonNullElse(url, ""),
return new AutoValue_GitHubReactions(Helper.requireNonNullOrElse(url, ""),
totalCount,
plus1,
minus1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package edu.stanford.protege.github.issues.shared;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-05-19
*
* An emulation of the Objects#requireNonNullOrElse method that is not
* supported in GWT
*/
public class Helper {

@SuppressWarnings("ReplaceNullCheck")
@Nonnull
public static <T> T requireNonNullOrElse(@Nullable T object, @Nonnull T defaultValue) {
if(object == null) {
return defaultValue;
}
else {
return object;
}
}
}

0 comments on commit 784cad3

Please sign in to comment.