/*
 * 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;
    }
}

@@ -1141,24 +1141,64 @@
 : %22 + prefix
+ + %22 (stripPrefix: %22 + stripPrefix + ')'
 ;%0A    %7D%0A%0A   
@@ -1468,19 +1468,54 @@
 turn str
-Val
+ipPrefix ? prefix.hashCode() : -prefix
 .hashCod
@@ -1588,23 +1588,22 @@
         
-return 
+if (!(
 obj inst
@@ -1630,11 +1630,12 @@
 ping
- &&
+)) %7B
 %0A   
@@ -1647,78 +1647,238 @@
     
-   (this == obj %7C%7C prefix.equals(((PrefixPathMapping) obj).prefix)
+return false;%0A        %7D%0A%0A        if (this == obj) %7B%0A            return true;%0A        %7D%0A%0A        final PrefixPathMapping that = (PrefixPathMapping) obj;%0A        return stripPrefix == that.stripPrefix && prefix.equals(that.prefix
 );%0A
-%0A
     

Fix PrefixPathMapping.equals()