package com.github.dtschust.zork.parser.strategies; import com.github.dtschust.zork.ZorkTrigger; import com.github.dtschust.zork.parser.Property; import com.github.dtschust.zork.parser.PropertyParseStrategy; import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy; import com.github.dtschust.zork.types.ZorkDirection; import com.github.dtschust.zork.objects.ZorkRoom; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class ZorkRoomParseStrategy implements PropertyParseStrategy { private final TriggerPropertyParseStrategy triggerStrategy; public ZorkRoomParseStrategy(final TriggerPropertyParseStrategy triggerStrategy) { this.triggerStrategy = triggerStrategy; } @Override public ZorkRoom parse(final Property source) { // Get all possible Room attributes final String name = source.subPropertyValue("name", ""); final String description = source.subPropertyValue("description", ""); final String type = source.subPropertyValue("type", "regular"); final List triggers = source.subPropertiesByName("trigger").stream() .map(triggerStrategy.parse(source)) .collect(Collectors.toList()); final String status = source.subPropertyValue("status", ""); final List items = source.subPropertyValues("item"); final List creatures = source.subPropertyValues("creature"); final List containers = source.subPropertyValues("container"); final Map borders = source.subPropertiesByName("border").stream() .collect(Collectors.toMap( e -> ZorkDirection.fromLong(e.subPropertyValue("direction")), e -> e.subPropertyValue("name") )); return new ZorkRoom(name, description, type, status, triggers, borders, containers, items, creatures); } }