package lu.jpt.csparqlproject.util; import java.util.HashMap; import java.util.Map; /** * This is a small helper class which will be used on some occasions * to make output easier to read by providing a method to replace known * uris in (tuple) strings with their known prefix. */ public class PrefixManager { /** * Key is the uri, value is its prefix */ private Map prefixTable; public PrefixManager() { this.prefixTable = new HashMap(); } /** * Register a known prefix with its corresponding uri * @param prefix * @param uri */ public void registerPrefix(String prefix, String uri) { this.prefixTable.put(uri, prefix); } /** * Replace all uris within a tuple with their know prefix * This is not efficient, but that is not the point * @param tuple as a string * @return shortened tuple string */ public String applyPrefix(String tuple) { for (Map.Entry entry : this.prefixTable.entrySet()) { tuple = tuple.replace(entry.getKey(), entry.getValue() + ":"); } return tuple; } }