Make at least 1 of the maps in FarmingWorld truly immutable
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.timetracking.farming;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -42,7 +43,7 @@ import net.runelite.client.plugins.timetracking.Tab;
|
||||
class FarmingWorld
|
||||
{
|
||||
@Getter
|
||||
private Map<Integer, FarmingRegion> regions = new HashMap<>();
|
||||
private final ImmutableMap<Integer, FarmingRegion> regions;
|
||||
|
||||
@Getter
|
||||
private Map<Tab, Set<FarmingPatch>> tabs = new HashMap<>();
|
||||
@@ -54,58 +55,60 @@ class FarmingWorld
|
||||
|
||||
FarmingWorld()
|
||||
{
|
||||
ImmutableMap.Builder<Integer, FarmingRegion> regionBuilder = ImmutableMap.builderWithExpectedSize(40);
|
||||
|
||||
// Some of these patches get updated in multiple regions.
|
||||
// It may be worth it to add a specialization for these patches
|
||||
add(new FarmingRegion("Al Kharid", 13106,
|
||||
add(regionBuilder, new FarmingRegion("Al Kharid", 13106,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.CACTUS)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Ardougne", 10290,
|
||||
add(regionBuilder, new FarmingRegion("Ardougne", 10290,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.BUSH)
|
||||
));
|
||||
add(new FarmingRegion("Ardougne", 10548,
|
||||
add(regionBuilder, new FarmingRegion("Ardougne", 10548,
|
||||
new FarmingPatch("North", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("South", Varbits.FARMING_4772, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4773, PatchImplementation.FLOWER),
|
||||
new FarmingPatch("", Varbits.FARMING_4774, PatchImplementation.HERB)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Brimhaven", 11058,
|
||||
add(regionBuilder, new FarmingRegion("Brimhaven", 11058,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.FRUIT_TREE),
|
||||
new FarmingPatch("", Varbits.FARMING_4772, PatchImplementation.SPIRIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Catherby", 11062,
|
||||
add(regionBuilder, new FarmingRegion("Catherby", 11062,
|
||||
new FarmingPatch("North", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("South", Varbits.FARMING_4772, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4773, PatchImplementation.FLOWER),
|
||||
new FarmingPatch("", Varbits.FARMING_4774, PatchImplementation.HERB)
|
||||
));
|
||||
add(new FarmingRegion("Catherby", 11317,
|
||||
add(regionBuilder, new FarmingRegion("Catherby", 11317,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.FRUIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Champions' Guild", 12596,
|
||||
add(regionBuilder, new FarmingRegion("Champions' Guild", 12596,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.BUSH)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Draynor Manor", 12340,
|
||||
add(regionBuilder, new FarmingRegion("Draynor Manor", 12340,
|
||||
new FarmingPatch("Belladonna", Varbits.FARMING_4771, PatchImplementation.BELLADONNA)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Entrana", 11060,
|
||||
add(regionBuilder, new FarmingRegion("Entrana", 11060,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.HOPS)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Etceteria", 10300,
|
||||
add(regionBuilder, new FarmingRegion("Etceteria", 10300,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.BUSH),
|
||||
new FarmingPatch("", Varbits.FARMING_4772, PatchImplementation.SPIRIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Falador", 11828,
|
||||
add(regionBuilder, new FarmingRegion("Falador", 11828,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.TREE)
|
||||
));
|
||||
add(new FarmingRegion("Falador", 12083,
|
||||
add(regionBuilder, new FarmingRegion("Falador", 12083,
|
||||
new FarmingPatch("North West", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("South East", Varbits.FARMING_4772, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4773, PatchImplementation.FLOWER),
|
||||
@@ -119,36 +122,36 @@ class FarmingWorld
|
||||
}
|
||||
});
|
||||
|
||||
add(new FarmingRegion("Fossil Island", 14651,
|
||||
add(regionBuilder, new FarmingRegion("Fossil Island", 14651,
|
||||
new FarmingPatch("East", Varbits.FARMING_4771, PatchImplementation.HARDWOOD_TREE),
|
||||
new FarmingPatch("Middle", Varbits.FARMING_4772, PatchImplementation.HARDWOOD_TREE),
|
||||
new FarmingPatch("West", Varbits.FARMING_4773, PatchImplementation.HARDWOOD_TREE)
|
||||
), 14907);
|
||||
add(new FarmingRegion("Seaweed", 15008,
|
||||
add(regionBuilder, new FarmingRegion("Seaweed", 15008,
|
||||
new FarmingPatch("North", Varbits.FARMING_4771, PatchImplementation.SEAWEED),
|
||||
new FarmingPatch("South", Varbits.FARMING_4772, PatchImplementation.SEAWEED)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Gnome Stronghold", 9781,
|
||||
add(regionBuilder, new FarmingRegion("Gnome Stronghold", 9781,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.TREE),
|
||||
new FarmingPatch("", Varbits.FARMING_4772, PatchImplementation.FRUIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Harmony", 15148,
|
||||
add(regionBuilder, new FarmingRegion("Harmony", 15148,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4772, PatchImplementation.HERB)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Kourend", 6967,
|
||||
add(regionBuilder, new FarmingRegion("Kourend", 6967,
|
||||
new FarmingPatch("North East", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("South West", Varbits.FARMING_4772, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4773, PatchImplementation.FLOWER),
|
||||
new FarmingPatch("", Varbits.FARMING_4774, PatchImplementation.HERB)
|
||||
));
|
||||
add(new FarmingRegion("Kourend", 6711,
|
||||
add(regionBuilder, new FarmingRegion("Kourend", 6711,
|
||||
new FarmingPatch("", Varbits.FARMING_7904, PatchImplementation.SPIRIT_TREE)
|
||||
));
|
||||
add(new FarmingRegion("Kourend", 7223,
|
||||
add(regionBuilder, new FarmingRegion("Kourend", 7223,
|
||||
new FarmingPatch("East 1", Varbits.GRAPES_4953, PatchImplementation.GRAPES),
|
||||
new FarmingPatch("East 2", Varbits.GRAPES_4954, PatchImplementation.GRAPES),
|
||||
new FarmingPatch("East 3", Varbits.GRAPES_4955, PatchImplementation.GRAPES),
|
||||
@@ -163,21 +166,21 @@ class FarmingWorld
|
||||
new FarmingPatch("West 6", Varbits.GRAPES_4964, PatchImplementation.GRAPES)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Lletya", 9265,
|
||||
add(regionBuilder, new FarmingRegion("Lletya", 9265,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.FRUIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Lumbridge", 12851,
|
||||
add(regionBuilder, new FarmingRegion("Lumbridge", 12851,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.HOPS)
|
||||
));
|
||||
add(new FarmingRegion("Lumbridge", 12594,
|
||||
add(regionBuilder, new FarmingRegion("Lumbridge", 12594,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Morytania", 13622,
|
||||
add(regionBuilder, new FarmingRegion("Morytania", 13622,
|
||||
new FarmingPatch("Mushroom", Varbits.FARMING_4771, PatchImplementation.MUSHROOM)
|
||||
));
|
||||
add(new FarmingRegion("Morytania", 14391,
|
||||
add(regionBuilder, new FarmingRegion("Morytania", 14391,
|
||||
new FarmingPatch("North West", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("South East", Varbits.FARMING_4772, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4773, PatchImplementation.FLOWER),
|
||||
@@ -185,51 +188,51 @@ class FarmingWorld
|
||||
));
|
||||
|
||||
|
||||
add(new FarmingRegion("Port Sarim", 12082,
|
||||
add(regionBuilder, new FarmingRegion("Port Sarim", 12082,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.SPIRIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Rimmington", 11570,
|
||||
add(regionBuilder, new FarmingRegion("Rimmington", 11570,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.BUSH)
|
||||
), 11826);
|
||||
|
||||
add(new FarmingRegion("Seers' Village", 10551,
|
||||
add(regionBuilder, new FarmingRegion("Seers' Village", 10551,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.HOPS)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Tai Bwo Wannai", 11056,
|
||||
add(regionBuilder, new FarmingRegion("Tai Bwo Wannai", 11056,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.CALQUAT)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Taverley", 11573,
|
||||
add(regionBuilder, new FarmingRegion("Taverley", 11573,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Tree Gnome Village", 9777,
|
||||
add(regionBuilder, new FarmingRegion("Tree Gnome Village", 9777,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.FRUIT_TREE)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Troll Stronghold", 11321,
|
||||
add(regionBuilder, new FarmingRegion("Troll Stronghold", 11321,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.HERB)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Varrock", 12854,
|
||||
add(regionBuilder, new FarmingRegion("Varrock", 12854,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.TREE)
|
||||
), 12853);
|
||||
|
||||
add(new FarmingRegion("Yanille", 10288,
|
||||
add(regionBuilder, new FarmingRegion("Yanille", 10288,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.HOPS)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Weiss", 11325,
|
||||
add(regionBuilder, new FarmingRegion("Weiss", 11325,
|
||||
new FarmingPatch("", Varbits.FARMING_4771, PatchImplementation.HERB)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Farming Guild", 5021,
|
||||
add(regionBuilder, new FarmingRegion("Farming Guild", 5021,
|
||||
new FarmingPatch("Hespori", Varbits.FARMING_7908, PatchImplementation.HESPORI)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Farming Guild", 4922,
|
||||
add(regionBuilder, new FarmingRegion("Farming Guild", 4922,
|
||||
new FarmingPatch("", Varbits.FARMING_7905, PatchImplementation.TREE),
|
||||
new FarmingPatch("", Varbits.FARMING_4775, PatchImplementation.HERB),
|
||||
new FarmingPatch("", Varbits.FARMING_4772, PatchImplementation.BUSH),
|
||||
@@ -244,7 +247,7 @@ class FarmingWorld
|
||||
new FarmingPatch("", Varbits.FARMING_7907, PatchImplementation.REDWOOD)
|
||||
));
|
||||
|
||||
add(new FarmingRegion("Prifddinas", 13151,
|
||||
add(regionBuilder, new FarmingRegion("Prifddinas", 13151,
|
||||
new FarmingPatch("North", Varbits.FARMING_4771, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("South", Varbits.FARMING_4772, PatchImplementation.ALLOTMENT),
|
||||
new FarmingPatch("", Varbits.FARMING_4773, PatchImplementation.FLOWER),
|
||||
@@ -252,7 +255,8 @@ class FarmingWorld
|
||||
));
|
||||
|
||||
// Finalize
|
||||
this.regions = Collections.unmodifiableMap(regions);
|
||||
this.regions = regionBuilder.build();
|
||||
|
||||
Map<Tab, Set<FarmingPatch>> umtabs = new TreeMap<>();
|
||||
for (Map.Entry<Tab, Set<FarmingPatch>> e : tabs.entrySet())
|
||||
{
|
||||
@@ -261,12 +265,12 @@ class FarmingWorld
|
||||
this.tabs = Collections.unmodifiableMap(umtabs);
|
||||
}
|
||||
|
||||
private void add(FarmingRegion r, int... extraRegions)
|
||||
private void add(ImmutableMap.Builder<Integer, FarmingRegion> builder, FarmingRegion r, int... extraRegions)
|
||||
{
|
||||
regions.put(r.getRegionID(), r);
|
||||
builder.put(r.getRegionID(), r);
|
||||
for (int er : extraRegions)
|
||||
{
|
||||
regions.put(er, r);
|
||||
builder.put(er, r);
|
||||
}
|
||||
for (FarmingPatch p : r.getPatches())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user