001package org.kuali.common.devops.archive.sweep.suppliers;
002
003import static org.apache.commons.lang.StringUtils.removeEnd;
004import static org.apache.commons.lang.StringUtils.removeStart;
005import static org.kuali.common.devops.archive.sweep.Functions.hostnameToKey;
006import static org.kuali.common.util.base.Precondition.checkNotBlank;
007
008import com.google.common.base.Function;
009
010public final class KeyToPathConverter implements Function<String, String> {
011
012        public KeyToPathConverter(String hostname) {
013                this.hostname = checkNotBlank(hostname, "hostname");
014                this.prefix = hostnameToKey().apply(hostname);
015        }
016
017        private final String hostname;
018        private final String prefix;
019
020        @Override
021        public String apply(String key) {
022                return removeEnd(removeStart(key, prefix), "/");
023        }
024
025        public String getHostname() {
026                return hostname;
027        }
028
029        public String getPrefix() {
030                return prefix;
031        }
032
033}