All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jsimpledb.parse.util.StripPrefixFunction Maven / Gradle / Ivy

There is a newer version: 3.6.1
Show newest version

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package org.jsimpledb.parse.util;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;

/**
 * Strips a prefix, which must match any input.
 */
public class StripPrefixFunction implements Function {

    private final String prefix;

    public StripPrefixFunction(String prefix) {
        Preconditions.checkArgument(prefix != null, "null prefix");
        this.prefix = prefix;
    }

    @Override
    public String apply(String string) {
        Preconditions.checkArgument(string != null, "null string");
        if (!string.startsWith(this.prefix))
            throw new IllegalArgumentException("string `" + string + "' does not have prefix `" + this.prefix + "'");
        return string.substring(prefix.length());
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy