merged TypedWorldIconCollector with NameFilteredWorldIconCollector

master
Stefan Dollase 2016-07-03 21:36:31 +02:00
parent 835fb3fbe6
commit a75626cc9c
4 changed files with 23 additions and 59 deletions

View File

@ -3,7 +3,7 @@ package amidst.mojangapi.world.filter;
import amidst.documentation.Immutable;
import amidst.mojangapi.world.World;
import amidst.mojangapi.world.coordinates.CoordinatesInWorld;
import amidst.mojangapi.world.icon.WorldIcon;
import amidst.mojangapi.world.icon.producer.NameFilteredWorldIconCollector;
import amidst.mojangapi.world.icon.producer.WorldIconCollector;
import amidst.mojangapi.world.icon.producer.WorldIconProducer;
import amidst.mojangapi.world.icon.type.DefaultWorldIconTypes;
@ -61,7 +61,7 @@ public class WorldFilter_Structure extends WorldFilter {
case DESERT:
case IGLOO:
case WITCH:
return new TypedWorldIconCollector(structure);
return new NameFilteredWorldIconCollector(structure.getName());
case STRONGHOLD:
case VILLAGE:
case OCEAN_MONUMENT:
@ -71,19 +71,4 @@ public class WorldFilter_Structure extends WorldFilter {
throw new IllegalArgumentException("Unsupported structure type: " + structure.getName());
}
}
private static class TypedWorldIconCollector extends WorldIconCollector {
private final DefaultWorldIconTypes acceptedStructure;
TypedWorldIconCollector(DefaultWorldIconTypes acceptedStructure) {
this.acceptedStructure = acceptedStructure;
}
@Override
public void accept(WorldIcon worldIcon) {
if (worldIcon.getName().equals(acceptedStructure.getName())) {
super.accept(worldIcon);
}
}
}
}

View File

@ -0,0 +1,20 @@
package amidst.mojangapi.world.icon.producer;
import amidst.documentation.NotThreadSafe;
import amidst.mojangapi.world.icon.WorldIcon;
@NotThreadSafe
public class NameFilteredWorldIconCollector extends WorldIconCollector {
private final String name;
public NameFilteredWorldIconCollector(String name) {
this.name = name;
}
@Override
public void accept(WorldIcon worldIcon) {
if (worldIcon.getName().equals(name)) {
super.accept(worldIcon);
}
}
}

View File

@ -1,41 +0,0 @@
package amidst.mojangapi.mocking;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import amidst.documentation.NotThreadSafe;
import amidst.mojangapi.world.icon.WorldIcon;
@NotThreadSafe
public class NameFilteredWorldIconCollector implements Consumer<WorldIcon> {
private List<WorldIcon> worldIcons;
private final String name;
public NameFilteredWorldIconCollector(String name) {
this.name = name;
}
@Override
public void accept(WorldIcon worldIcon) {
if (worldIcon.getName().equals(name)) {
initListIfNecessary();
worldIcons.add(worldIcon);
}
}
private void initListIfNecessary() {
if (worldIcons == null) {
worldIcons = new LinkedList<WorldIcon>();
}
}
public List<WorldIcon> get() {
if (worldIcons == null) {
return Collections.emptyList();
} else {
return worldIcons;
}
}
}

View File

@ -9,10 +9,10 @@ import amidst.documentation.GsonConstructor;
import amidst.documentation.Immutable;
import amidst.logging.Log;
import amidst.mojangapi.mocking.FragmentCornerWalker;
import amidst.mojangapi.mocking.NameFilteredWorldIconCollector;
import amidst.mojangapi.world.World;
import amidst.mojangapi.world.coordinates.CoordinatesInWorld;
import amidst.mojangapi.world.icon.WorldIcon;
import amidst.mojangapi.world.icon.producer.NameFilteredWorldIconCollector;
import amidst.mojangapi.world.icon.producer.WorldIconProducer;
@Immutable