2 // ========================================================================
3 // Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.http.pathmap;
22 * The base PathSpec, what all other path specs are based on
24 public abstract class PathSpec implements Comparable<PathSpec>
26 protected String pathSpec;
27 protected PathSpecGroup group;
28 protected int pathDepth;
29 protected int specLength;
32 public int compareTo(PathSpec other)
34 // Grouping (increasing)
35 int diff = this.group.ordinal() - other.group.ordinal();
41 // Spec Length (decreasing)
42 diff = other.specLength - this.specLength;
48 // Path Spec Name (alphabetical)
49 return this.pathSpec.compareTo(other.pathSpec);
53 public boolean equals(Object obj)
63 if (getClass() != obj.getClass())
67 PathSpec other = (PathSpec)obj;
70 if (other.pathSpec != null)
75 else if (!pathSpec.equals(other.pathSpec))
82 public PathSpecGroup getGroup()
88 * Get the number of path elements that this path spec declares.
90 * This is used to determine longest match logic.
92 * @return the depth of the path segments that this spec declares
94 public int getPathDepth()
100 * Return the portion of the path that is after the path spec.
103 * the path to match against
104 * @return the path info portion of the string
106 public abstract String getPathInfo(String path);
109 * Return the portion of the path that matches a path spec.
112 * the path to match against
113 * @return the match, or null if no match at all
115 public abstract String getPathMatch(String path);
118 * The as-provided path spec.
120 * @return the as-provided path spec
122 public String getDeclaration()
128 * Get the relative path.
131 * the base the path is relative to
133 * the additional path
134 * @return the base plus path with pathSpec portion removed
136 public abstract String getRelativePath(String base, String path);
139 public int hashCode()
141 final int prime = 31;
143 result = (prime * result) + ((pathSpec == null)?0:pathSpec.hashCode());
148 * Test to see if the provided path matches this path spec
152 * @return true if the path matches this path spec, false otherwise
154 public abstract boolean matches(String path);
157 public String toString()
159 StringBuilder str = new StringBuilder();
160 str.append(this.getClass().getSimpleName()).append("[\"");
161 str.append(pathSpec);
162 str.append("\",pathDepth=").append(pathDepth);
163 str.append(",group=").append(group);
165 return str.toString();