Skip to content

Commit

Permalink
Change HashMap to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
RaydanOMGr committed Oct 26, 2024
1 parent 0cdb4ae commit e638e07
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PresetsScreen extends Screen {
private int guiLeft, guiTop;
Expand All @@ -40,7 +40,7 @@ public class PresetsScreen extends Screen {
boolean isLocked = false;
boolean editing = false;

HashMap<Point, Color> savedPixelMap = null;
Map<Point, Color> savedPixelMap = null;
List<PresetButton> presetButtons;
Button createEditButton;
private Screen parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class Preset {
private String name;
private final ResourceLocation id;
private final HashMap<Point, Color> content;
private final Map<Point, Color> content;

public Preset(String name, ResourceLocation id, HashMap<Point, Color> content) {
public Preset(String name, ResourceLocation id, Map<Point, Color> content) {
this.name = name;
this.id = id;
this.content = content;
Expand All @@ -36,7 +37,7 @@ public ResourceLocation getResourceLocation() {
);
}

public HashMap<Point, Color> getContent() {
public Map<Point, Color> getContent() {
// return a copy so that the original content can't be modified
return new HashMap<>(this.content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class PresetManager {
private static final PresetManager INSTANCE = new PresetManager();
Gson gson = new GsonBuilder()
.registerTypeAdapter(HashMap.class, new PointColorMapSerializer())
.registerTypeAdapter(Map.class, new PointColorMapSerializer())
.registerTypeAdapter(ResourceLocation.class, new ResourceLocationSerializer())
.setPrettyPrinting()
.create();
Expand Down Expand Up @@ -175,17 +175,17 @@ private int addPreset(Preset preset, int number) {
return this.presets.size() - 1;
}

public int createPreset(String name, HashMap<Point, Color> content) {
public int createPreset(String name, Map<Point, Color> content) {
return this.createPreset(name, content, new ResourceLocation(GlowingEyes.MOD_ID, "preset_" + sanitizeForId(name)));
}

public int createPreset(String name, HashMap<Point, Color> content, ResourceLocation id) {
public int createPreset(String name, Map<Point, Color> content, ResourceLocation id) {
int minX = 0;
int minY = 0;
int maxX = 15;
int maxY = 15;

HashMap<Point, Color> contentCopy = new HashMap<>(content);
Map<Point, Color> contentCopy = new HashMap<>(content);
// check if the content has pixels outside range x 0, y 0 - x 16, y 16
for(Point point : contentCopy.keySet()) {
if(point.x < minX || point.x > maxX || point.y < minY || point.y > maxY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class GlowingEyesImpl implements IGlowingEyes {
private boolean toggledOn = true;
private HashMap<Point, Color> glowingEyesMap = new HashMap<>();
private Map<Point, Color> glowingEyesMap = new HashMap<>();

@Override
public HashMap<Point, Color> getGlowingEyesMap() {
public Map<Point, Color> getGlowingEyesMap() {
return this.glowingEyesMap;
}

@Override
public void setGlowingEyesMap(HashMap<Point, Color> glowingEyesMap) {
public void setGlowingEyesMap(Map<Point, Color> glowingEyesMap) {
this.glowingEyesMap = glowingEyesMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import javax.annotation.Nonnull;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class GlowingEyesImpl implements IGlowingEyes {
private boolean toggledOn = true;
private HashMap<Point, Color> glowingEyesMap = new HashMap<>();
private Map<Point, Color> glowingEyesMap = new HashMap<>();

@Nonnull
@Override
public HashMap<Point, Color> getGlowingEyesMap() {
public Map<Point, Color> getGlowingEyesMap() {
return this.glowingEyesMap;
}

@Override
public void setGlowingEyesMap(@Nonnull HashMap<Point, Color> glowingEyesMap) {
public void setGlowingEyesMap(@Nonnull Map<Point, Color> glowingEyesMap) {
this.glowingEyesMap = glowingEyesMap;
}

Expand Down

0 comments on commit e638e07

Please sign in to comment.