Skip to content

Commit

Permalink
Issue #7891 - Improving MatchedResource
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed May 11, 2022
1 parent b8137c5 commit 3085e71
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 92 deletions.
Expand Up @@ -36,7 +36,12 @@ public int compareTo(PathSpec other)
return diff;

// Path Spec Name (alphabetical)
return getDeclaration().compareTo(other.getDeclaration());
diff = getDeclaration().compareTo(other.getDeclaration());
if (diff != 0)
return diff;

// Path Implementation
return getClass().getName().compareTo(other.getClass().getName());
}

@Override
Expand All @@ -55,7 +60,7 @@ public final boolean equals(Object obj)
@Override
public final int hashCode()
{
return Objects.hash(getDeclaration());
return Objects.hash(this.getClass().getSimpleName() + ":" + getDeclaration());
}

@Override
Expand Down
Expand Up @@ -18,34 +18,53 @@

package org.eclipse.jetty.http.pathmap;

import java.util.Map;

public class MatchedResource<E>
{
private final MappedResource<E> mappedResource;
private final E resource;
private final PathSpec pathSpec;
private final MatchedPath matchedPath;

public MatchedResource(MappedResource<E> resource, MatchedPath matchedPath)
public MatchedResource(E resource, PathSpec pathSpec, MatchedPath matchedPath)
{
this.mappedResource = resource;
this.resource = resource;
this.pathSpec = pathSpec;
this.matchedPath = matchedPath;
}

public MappedResource<E> getMappedResource()
public static <E> MatchedResource<E> of(Map.Entry<PathSpec, E> mapping, MatchedPath matchedPath)
{
return this.mappedResource;
return new MatchedResource<>(mapping.getValue(), mapping.getKey(), matchedPath);
}

public PathSpec getPathSpec()
{
return mappedResource.getPathSpec();
return this.pathSpec;
}

public E getResource()
{
return mappedResource.getResource();
return this.resource;
}

/**
* Return the portion of the path that matches a path spec.
*
* @return the path name portion of the match.
*/
public String getPathMatch()
{
return matchedPath.getPathMatch();
}

public MatchedPath getMatchedPath()
/**
* Return the portion of the path that is after the path spec.
*
* @return the path info portion of the match, or null if there is no portion after the {@link #getPathMatch()}
*/
public String getPathInfo()
{
return matchedPath;
return matchedPath.getPathInfo();
}
}

0 comments on commit 3085e71

Please sign in to comment.