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

com.github.dreamhead.moco.mount.MountTo Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.mount;

import com.github.dreamhead.moco.ConfigApplier;
import com.github.dreamhead.moco.MocoConfig;
import com.google.common.base.Optional;

import static com.github.dreamhead.moco.util.URLs.toBase;
import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.fromNullable;

public class MountTo implements ConfigApplier {
    private final String target;

    public MountTo(final String target) {
        this.target = toBase(target);
    }

    public Optional extract(final String uri) {
        if (uri.startsWith(this.target) && uri.length() != this.target.length()) {
            return fromNullable(uri.replaceFirst(this.target, ""));
        }

        return absent();
    }

    @Override
    @SuppressWarnings("unchecked")
    public MountTo apply(final MocoConfig config) {
        if (config.isFor(MocoConfig.URI_ID)) {
            return new MountTo((String) config.apply(this.target));
        }

        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy