package me.loganb1max.minionsplus.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Replacer {

	private Map<String, String> replaceMap = new HashMap<>();

	public static Replacer create() {
		return new Replacer();
	}

	public Replacer add(final String key, final String value) {
		this.replaceMap.put(key, value);
		return this;
	}

	public String replace(String string) {
		for (Map.Entry<String, String> entry : this.replaceMap.entrySet()) {
			string = string.replace(entry.getKey(), entry.getValue());
		}
		return string;
	}

	public List<String> replace(List<String> strings) {
		for (Map.Entry<String, String> entry : this.replaceMap.entrySet()) {
			strings = strings.stream().map(s -> s.replace(entry.getKey(), entry.getValue())).collect(Collectors.toList());
		}
		return strings;
	}

}
