This repository has been archived on 2022-12-21. You can view files and clone it, but cannot push or open issues or pull requests.
sdm03/src/main/java/com/github/dtschust/zork/parser/strategies/ZorkItemParseStrategy.java

47 lines
1.7 KiB
Java

package com.github.dtschust.zork.parser.strategies;
import com.github.dtschust.zork.ZorkTrigger;
import com.github.dtschust.zork.objects.ZorkItem;
import com.github.dtschust.zork.parser.Property;
import com.github.dtschust.zork.parser.PropertyParseStrategy;
import com.github.dtschust.zork.parser.TriggerPropertyParseStrategy;
import java.util.List;
import java.util.stream.Collectors;
public class ZorkItemParseStrategy implements PropertyParseStrategy<ZorkItem> {
private final TriggerPropertyParseStrategy triggerStrategy;
public ZorkItemParseStrategy(final TriggerPropertyParseStrategy triggerStrategy) {
this.triggerStrategy = triggerStrategy;
}
@Override
public ZorkItem parse(final Property source) {
final List<String> prints = source.subPropertiesByName("turnon").stream()
.flatMap(e -> e.subPropertyValues("print").stream())
.collect(Collectors.toList());
final List<String> actions = source.subPropertiesByName("turnon").stream()
.flatMap(e -> e.subPropertyValues("action").stream())
.collect(Collectors.toList());
final List<ZorkTrigger> triggers = source.subPropertiesByName("trigger").stream()
.map(triggerStrategy.parse(source))
.collect(Collectors.toList());
/* Get all possible item attributes*/
return new ZorkItem(
source.subPropertyValue("name", ""),
source.subPropertyValue("description", ""),
source.subPropertyValue("status", ""),
source.subPropertyValue("writing", ""),
triggers,
prints,
actions
);
}
}