X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Fhttp%2Fpathmap%2FPathSpecSet.java;fp=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Fhttp%2Fpathmap%2FPathSpecSet.java;h=1ffb783ee8e5a513660c57f69884b4ee298a0f57;hp=0000000000000000000000000000000000000000;hb=aa5723dbb64ec8efa63909d39ff72364f0a5ee96;hpb=e443f19911df6a30ab07ef70d23970bda671b194
diff --git a/lib/jetty/org/eclipse/jetty/http/pathmap/PathSpecSet.java b/lib/jetty/org/eclipse/jetty/http/pathmap/PathSpecSet.java
new file mode 100644
index 00000000..1ffb783e
--- /dev/null
+++ b/lib/jetty/org/eclipse/jetty/http/pathmap/PathSpecSet.java
@@ -0,0 +1,223 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// 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.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.jetty.util.Predicate;
+
+/**
+ * A Set of PathSpec strings.
+ *
+ * Used by {@link org.eclipse.jetty.util.IncludeExclude} logic
+ */
+public class PathSpecSet implements Set, Predicate
+{
+ private final Set specs = new TreeSet<>();
+
+ @Override
+ public boolean test(String s)
+ {
+ for (PathSpec spec : specs)
+ {
+ if (spec.matches(s))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return specs.isEmpty();
+ }
+
+ @Override
+ public Iterator iterator()
+ {
+ return new Iterator()
+ {
+ private Iterator iter = specs.iterator();
+
+ @Override
+ public boolean hasNext()
+ {
+ return iter.hasNext();
+ }
+
+ @Override
+ public String next()
+ {
+ PathSpec spec = iter.next();
+ if (spec == null)
+ {
+ return null;
+ }
+ return spec.getDeclaration();
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException("Remove not supported by this Iterator");
+ }
+ };
+ }
+
+ @Override
+ public int size()
+ {
+ return specs.size();
+ }
+
+ @Override
+ public boolean contains(Object o)
+ {
+ if (o instanceof PathSpec)
+ {
+ return specs.contains(o);
+ }
+ if (o instanceof String)
+ {
+ return specs.contains(toPathSpec((String)o));
+ }
+ return false;
+ }
+
+ private PathSpec asPathSpec(Object o)
+ {
+ if (o == null)
+ {
+ return null;
+ }
+ if (o instanceof PathSpec)
+ {
+ return (PathSpec)o;
+ }
+ if (o instanceof String)
+ {
+ return toPathSpec((String)o);
+ }
+ return toPathSpec(o.toString());
+ }
+
+ private PathSpec toPathSpec(String rawSpec)
+ {
+ if ((rawSpec == null) || (rawSpec.length() < 1))
+ {
+ throw new RuntimeException("Path Spec String must start with '^', '/', or '*.': got [" + rawSpec + "]");
+ }
+ if (rawSpec.charAt(0) == '^')
+ {
+ return new RegexPathSpec(rawSpec);
+ }
+ else
+ {
+ return new ServletPathSpec(rawSpec);
+ }
+ }
+
+ @Override
+ public Object[] toArray()
+ {
+ return toArray(new String[specs.size()]);
+ }
+
+ @Override
+ public T[] toArray(T[] a)
+ {
+ int i = 0;
+ for (PathSpec spec : specs)
+ {
+ a[i++] = (T)spec.getDeclaration();
+ }
+ return a;
+ }
+
+ @Override
+ public boolean add(String e)
+ {
+ return specs.add(toPathSpec(e));
+ }
+
+ @Override
+ public boolean remove(Object o)
+ {
+ return specs.remove(asPathSpec(o));
+ }
+
+ @Override
+ public boolean containsAll(Collection> coll)
+ {
+ for (Object o : coll)
+ {
+ if (!specs.contains(asPathSpec(o)))
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean addAll(Collection extends String> coll)
+ {
+ boolean ret = false;
+
+ for (String s : coll)
+ {
+ ret |= add(s);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public boolean retainAll(Collection> coll)
+ {
+ List collSpecs = new ArrayList<>();
+ for (Object o : coll)
+ {
+ collSpecs.add(asPathSpec(o));
+ }
+ return specs.retainAll(collSpecs);
+ }
+
+ @Override
+ public boolean removeAll(Collection> coll)
+ {
+ List collSpecs = new ArrayList<>();
+ for (Object o : coll)
+ {
+ collSpecs.add(asPathSpec(o));
+ }
+ return specs.removeAll(collSpecs);
+ }
+
+ @Override
+ public void clear()
+ {
+ specs.clear();
+ }
+}