Skip to content

Commit

Permalink
Check earlier if mod is null when creating infobooks, Closes #189
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 27, 2024
1 parent 6e82eaa commit a0e0110
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
125 changes: 123 additions & 2 deletions src/main/java/org/cyclops/cyclopscore/infobook/InfoBook.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package org.cyclops.cyclopscore.infobook;

import com.google.common.collect.Maps;
import lombok.Data;
import org.apache.commons.lang3.tuple.Pair;
import org.cyclops.cyclopscore.datastructure.EvictingStack;
import org.cyclops.cyclopscore.init.ModBase;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;

/**
* Default implementation for an {@link IInfoBook}.
*
* @author rubensworks
*/
@Data
public class InfoBook implements IInfoBook {

private final ModBase mod;
Expand All @@ -27,6 +27,12 @@ public class InfoBook implements IInfoBook {

private final Map<String, InfoSection> sections = Maps.newHashMap();

public InfoBook(ModBase mod, int pagesPerView, String baseUrl) {
this.mod = Objects.requireNonNull(mod);
this.pagesPerView = pagesPerView;
this.baseUrl = baseUrl;
}

@Override
public void addSection(String sectionName, InfoSection section) {
sections.put(sectionName, section);
Expand All @@ -41,4 +47,119 @@ public InfoSection getSection(String sectionName) {
public void putIndex(InfoSectionTagIndex tagIndex) {
this.tagIndex = tagIndex;
}

public ModBase getMod() {
return this.mod;
}

public int getPagesPerView() {
return this.pagesPerView;
}

public String getBaseUrl() {
return this.baseUrl;
}

public EvictingStack<InfoSection.Location> getHistory() {
return this.history;
}

public int getCurrentPage() {
return this.currentPage;
}

public InfoSection getCurrentSection() {
return this.currentSection;
}

public InfoSectionTagIndex getTagIndex() {
return this.tagIndex;
}

public Map<String, Pair<InfoSection, Integer>> getConfigLinks() {
return this.configLinks;
}

public Map<String, InfoSection> getSections() {
return this.sections;
}

public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}

public void setCurrentSection(InfoSection currentSection) {
this.currentSection = currentSection;
}

public void setTagIndex(InfoSectionTagIndex tagIndex) {
this.tagIndex = tagIndex;
}

public void setConfigLinks(Map<String, Pair<InfoSection, Integer>> configLinks) {
this.configLinks = configLinks;
}

public boolean equals(final Object o) {
if (o == this) return true;
if (!(o instanceof InfoBook)) return false;
final InfoBook other = (InfoBook) o;
if (!other.canEqual((Object) this)) return false;
final Object this$mod = this.getMod();
final Object other$mod = other.getMod();
if (this$mod == null ? other$mod != null : !this$mod.equals(other$mod)) return false;
if (this.getPagesPerView() != other.getPagesPerView()) return false;
final Object this$baseUrl = this.getBaseUrl();
final Object other$baseUrl = other.getBaseUrl();
if (this$baseUrl == null ? other$baseUrl != null : !this$baseUrl.equals(other$baseUrl)) return false;
final Object this$history = this.getHistory();
final Object other$history = other.getHistory();
if (this$history == null ? other$history != null : !this$history.equals(other$history)) return false;
if (this.getCurrentPage() != other.getCurrentPage()) return false;
final Object this$currentSection = this.getCurrentSection();
final Object other$currentSection = other.getCurrentSection();
if (this$currentSection == null ? other$currentSection != null : !this$currentSection.equals(other$currentSection))
return false;
final Object this$tagIndex = this.getTagIndex();
final Object other$tagIndex = other.getTagIndex();
if (this$tagIndex == null ? other$tagIndex != null : !this$tagIndex.equals(other$tagIndex)) return false;
final Object this$configLinks = this.getConfigLinks();
final Object other$configLinks = other.getConfigLinks();
if (this$configLinks == null ? other$configLinks != null : !this$configLinks.equals(other$configLinks))
return false;
final Object this$sections = this.getSections();
final Object other$sections = other.getSections();
if (this$sections == null ? other$sections != null : !this$sections.equals(other$sections)) return false;
return true;
}

protected boolean canEqual(final Object other) {
return other instanceof InfoBook;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $mod = this.getMod();
result = result * PRIME + ($mod == null ? 43 : $mod.hashCode());
result = result * PRIME + this.getPagesPerView();
final Object $baseUrl = this.getBaseUrl();
result = result * PRIME + ($baseUrl == null ? 43 : $baseUrl.hashCode());
final Object $history = this.getHistory();
result = result * PRIME + ($history == null ? 43 : $history.hashCode());
result = result * PRIME + this.getCurrentPage();
final Object $currentSection = this.getCurrentSection();
result = result * PRIME + ($currentSection == null ? 43 : $currentSection.hashCode());
final Object $tagIndex = this.getTagIndex();
result = result * PRIME + ($tagIndex == null ? 43 : $tagIndex.hashCode());
final Object $configLinks = this.getConfigLinks();
result = result * PRIME + ($configLinks == null ? 43 : $configLinks.hashCode());
final Object $sections = this.getSections();
result = result * PRIME + ($sections == null ? 43 : $sections.hashCode());
return result;
}

public String toString() {
return "InfoBook(mod=" + this.getMod() + ", pagesPerView=" + this.getPagesPerView() + ", baseUrl=" + this.getBaseUrl() + ", history=" + this.getHistory() + ", currentPage=" + this.getCurrentPage() + ", currentSection=" + this.getCurrentSection() + ", tagIndex=" + this.getTagIndex() + ", configLinks=" + this.getConfigLinks() + ", sections=" + this.getSections() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ protected static InfoSection buildSection(IInfoBook infoBook, InfoSection parent
if (tagString.contains(":")) {
String[] split = tagString.split(":");
modRecipe = ModBase.get(split[0]);
if (modRecipe == null) {
throw new IllegalArgumentException("The mod " + split[0] + " could not be found as ModBase.");
}
tagString = split[1];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void registerInfoBook(IInfoBook infoBook, String path) {
@Override
public void registerSection(ModBase<?> mod, IInfoBook infoBook, String parentSection, String sectionPath) {
synchronized (sectionInjections) {
sectionInjections.add(new SectionInjection(mod, infoBook, parentSection, sectionPath));
sectionInjections.add(new SectionInjection(Objects.requireNonNull(mod), infoBook, parentSection, sectionPath));
}
}

Expand Down

0 comments on commit a0e0110

Please sign in to comment.