<commit_before>/*
 * Copyright 2015 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.linecorp.armeria.server;

final class PrefixPathMapping extends AbstractPathMapping {

    private final String prefix;
    private final boolean stripPrefix;
    private final String strVal;

    PrefixPathMapping(String prefix, boolean stripPrefix) {
        prefix = ExactPathMapping.ensureAbsolutePath(prefix, "prefix");
        if (!prefix.endsWith("/")) {
            prefix += '/';
        }

        this.prefix = prefix;
        this.stripPrefix = stripPrefix;
        strVal = "prefix: " + prefix;
    }

    @Override
    protected String doApply(String path) {
        if (!path.startsWith(prefix)) {
            return null;
        }

        return stripPrefix ? path.substring(prefix.length() - 1) : path;
    }

    @Override
    public int hashCode() {
        return strVal.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof PrefixPathMapping &&
               (this == obj || prefix.equals(((PrefixPathMapping) obj).prefix));

    }

    @Override
    public String toString() {
        return strVal;
    }
}<commit_msg>Fix PrefixPathMapping.equals()<commit_after>/*
 * Copyright 2015 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.linecorp.armeria.server;

final class PrefixPathMapping extends AbstractPathMapping {

    private final String prefix;
    private final boolean stripPrefix;
    private final String strVal;

    PrefixPathMapping(String prefix, boolean stripPrefix) {
        prefix = ExactPathMapping.ensureAbsolutePath(prefix, "prefix");
        if (!prefix.endsWith("/")) {
            prefix += '/';
        }

        this.prefix = prefix;
        this.stripPrefix = stripPrefix;
        strVal = "prefix: " + prefix + " (stripPrefix: " + stripPrefix + ')';
    }

    @Override
    protected String doApply(String path) {
        if (!path.startsWith(prefix)) {
            return null;
        }

        return stripPrefix ? path.substring(prefix.length() - 1) : path;
    }

    @Override
    public int hashCode() {
        return stripPrefix ? prefix.hashCode() : -prefix.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof PrefixPathMapping)) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        final PrefixPathMapping that = (PrefixPathMapping) obj;
        return stripPrefix == that.stripPrefix && prefix.equals(that.prefix);
    }

    @Override
    public String toString() {
        return strVal;
    }
}
{'fraction_non_alphanumeric': 0.09175531914893617, 'fraction_numerical': 0.0047872340425531915, 'mean_word_length': 2.690873405299313, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '137987', 'n_tokens_mistral': 991, 'n_tokens_neox': 954, 'n_words': 345}