Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
6c62157865
commit
e43c98f08d
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.http.pathmap;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractPathSpec implements PathSpec
|
||||
{
|
||||
@Override
|
||||
public int compareTo(PathSpec other)
|
||||
{
|
||||
// Grouping (increasing)
|
||||
int diff = getGroup().ordinal() - other.getGroup().ordinal();
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
|
||||
// Spec Length (decreasing)
|
||||
diff = other.getSpecLength() - getSpecLength();
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
|
||||
// Path Spec Name (alphabetical)
|
||||
return getDeclaration().compareTo(other.getDeclaration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
|
||||
return compareTo((AbstractPathSpec)obj) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode()
|
||||
{
|
||||
return Objects.hash(getDeclaration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%s{%s}", getClass().getSimpleName(), Integer.toHexString(hashCode()), getDeclaration());
|
||||
}
|
||||
}
|
|
@ -92,20 +92,4 @@ public interface PathSpec extends Comparable<PathSpec>
|
|||
* @return true if the path matches this path spec, false otherwise
|
||||
*/
|
||||
boolean matches(String path);
|
||||
|
||||
default int compareTo(PathSpec other)
|
||||
{
|
||||
// Grouping (increasing)
|
||||
int diff = getGroup().ordinal() - other.getGroup().ordinal();
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
|
||||
// Spec Length (decreasing)
|
||||
diff = other.getSpecLength() - getSpecLength();
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
|
||||
// Path Spec Name (alphabetical)
|
||||
return getDeclaration().compareTo(other.getDeclaration());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,10 @@
|
|||
|
||||
package org.eclipse.jetty.http.pathmap;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegexPathSpec implements PathSpec
|
||||
public class RegexPathSpec extends AbstractPathSpec
|
||||
{
|
||||
private final String _declaration;
|
||||
private final PathSpecGroup _group;
|
||||
|
@ -194,21 +193,4 @@ public class RegexPathSpec implements PathSpec
|
|||
return getMatcher(path).matches();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
RegexPathSpec that = (RegexPathSpec)o;
|
||||
return compareTo(that) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(_declaration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.http.pathmap;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class ServletPathSpec implements PathSpec
|
||||
public class ServletPathSpec extends AbstractPathSpec
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ServletPathSpec.class);
|
||||
|
||||
|
@ -293,21 +291,4 @@ public class ServletPathSpec implements PathSpec
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
ServletPathSpec that = (ServletPathSpec)o;
|
||||
return compareTo(that) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(_declaration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
*
|
||||
* @see <a href="https://tools.ietf.org/html/rfc6570">URI Templates (Level 1)</a>
|
||||
*/
|
||||
public class UriTemplatePathSpec implements PathSpec
|
||||
public class UriTemplatePathSpec extends AbstractPathSpec
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(UriTemplatePathSpec.class);
|
||||
|
||||
|
@ -287,7 +287,7 @@ public class UriTemplatePathSpec implements PathSpec
|
|||
}
|
||||
else
|
||||
{
|
||||
return PathSpec.super.compareTo(other);
|
||||
return super.compareTo(other);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,21 +421,4 @@ public class UriTemplatePathSpec implements PathSpec
|
|||
{
|
||||
return _variables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
UriTemplatePathSpec that = (UriTemplatePathSpec)o;
|
||||
return compareTo(that) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(_declaration);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue