cleanup after review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-05-03 13:53:42 +02:00
parent 45270814d1
commit 6c6646286d
5 changed files with 23 additions and 59 deletions

View File

@ -33,7 +33,6 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.util.IncludeExclude; import org.eclipse.jetty.util.IncludeExclude;
import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.IncludeExcludeSet;
import org.eclipse.jetty.util.InetAddressSet; import org.eclipse.jetty.util.InetAddressSet;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.component.DumpableCollection;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -205,7 +204,7 @@ public class InetAccessHandler extends HandlerWrapper
dumpObjects(out, indent, dumpObjects(out, indent,
new DumpableCollection("included", _addrs.getIncluded()), new DumpableCollection("included", _addrs.getIncluded()),
new DumpableCollection("excluded", _addrs.getExcluded()), new DumpableCollection("excluded", _addrs.getExcluded()),
new DumpableCollection("includedConnectorNames", _names.getIncluded()), new DumpableCollection("includedConnector", _names.getIncluded()),
new DumpableCollection("excludedConnectorNames", _names.getExcluded())); new DumpableCollection("excludedConnector", _names.getExcluded()));
} }
} }

View File

@ -22,7 +22,6 @@ import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier;
/** Utility class to maintain a set of inclusions and exclusions. /** Utility class to maintain a set of inclusions and exclusions.
@ -41,7 +40,7 @@ public class IncludeExcludeSet<T,P> implements Predicate<P>
private final Predicate<P> _includePredicate; private final Predicate<P> _includePredicate;
private final Set<T> _excludes; private final Set<T> _excludes;
private final Predicate<P> _excludePredicate; private final Predicate<P> _excludePredicate;
private static class SetContainsPredicate<T> implements Predicate<T> private static class SetContainsPredicate<T> implements Predicate<T>
{ {
private final Set<T> set; private final Set<T> set;
@ -222,36 +221,4 @@ public class IncludeExcludeSet<T,P> implements Predicate<P>
{ {
return _includes.isEmpty() && _excludes.isEmpty(); return _includes.isEmpty() && _excludes.isEmpty();
} }
/**
* Combine the results of two {@link IncludeExcludeSet}s with an "or"-like operation.
* Item x must be included by xSet OR item y must be included ySet.
* Neither x nor y may be excluded for either respective set.
* If a sets inclusions are empty, then all items are considered to be included.
*
* @param xSet The set that param x is tested against
* @param x An item to test against xSet
* @param ySet The set that param y is tested against
* @param ySupplier A supplier of an item to test against ySet, that is executed only of x is not excluded from xSet
* @param <XS> The type of xSet items
* @param <XP> The type of xSet predicates
* @param <YS> The type of ySet items
* @param <YP> The type of ySet predicates
* @return True only if the items are included and not excluded from their respected sets
*/
public static <XS, XP, YS, YP> boolean or(IncludeExcludeSet<XS, XP> xSet, XP x, IncludeExcludeSet<YS,YP> ySet, Supplier<YP> ySupplier)
{
Boolean xb = xSet.isIncludedAndNotExcluded(x);
if (Boolean.FALSE==xb)
return false;
YP y = ySupplier.get();
Boolean yb = ySet.isIncludedAndNotExcluded(y);
if (Boolean.FALSE==yb)
return false;
return Boolean.TRUE.equals(xb)
|| Boolean.TRUE.equals(yb)
|| !xSet.hasIncludes() && !ySet.hasIncludes();
}
} }

View File

@ -227,13 +227,4 @@ public interface Dumpable
dumpObjects(out, nextIndent, item); dumpObjects(out, nextIndent, item);
} }
} }
static Dumpable labelled(String label, Object o)
{
return (out, indent) ->
{
out.append(label).append(':');
Dumpable.dumpObjects(out,indent,o);
};
}
} }

View File

@ -18,14 +18,14 @@
package org.eclipse.jetty.util.component; package org.eclipse.jetty.util.component;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
public class DumpableTest public class DumpableTest
{ {
@Test @Test
@ -50,13 +50,4 @@ public class DumpableTest
assertThat(dump, Matchers.containsString("two")); assertThat(dump, Matchers.containsString("two"));
assertThat(dump, Matchers.containsString("three")); assertThat(dump, Matchers.containsString("three"));
} }
@Test
public void testDumpableLabelled() throws Exception
{
String dump = Dumpable.labelled("label", "Item").dump();
assertThat(dump, Matchers.containsString("label:"));
assertThat(dump, Matchers.containsString("Item"));
}
} }

View File

@ -36,6 +36,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier;
import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.util.ArrayTernaryTrie; import org.eclipse.jetty.util.ArrayTernaryTrie;
@ -686,7 +687,7 @@ public class ClasspathPattern extends AbstractSet<String>
{ {
try try
{ {
return IncludeExcludeSet.or(_packageOrNamePatterns, clazz.getName(), _locations, ()->TypeUtil.getLocationOfClass(clazz)); return combine(_packageOrNamePatterns, clazz.getName(), _locations, ()->TypeUtil.getLocationOfClass(clazz));
} }
catch (Exception e) catch (Exception e)
{ {
@ -704,7 +705,7 @@ public class ClasspathPattern extends AbstractSet<String>
// Treat path elements as packages for name matching // Treat path elements as packages for name matching
name=name.replace("/","."); name=name.replace("/",".");
return IncludeExcludeSet.or(_packageOrNamePatterns, name, _locations, ()-> return combine(_packageOrNamePatterns, name, _locations, ()->
{ {
try try
{ {
@ -717,5 +718,20 @@ public class ClasspathPattern extends AbstractSet<String>
} }
}); });
} }
private static boolean combine(IncludeExcludeSet<Entry, String> names, String name, IncludeExcludeSet<Entry, URI> locations, Supplier<URI> location)
{
Boolean byName = names.isIncludedAndNotExcluded(name);
if (Boolean.FALSE==byName)
return false;
Boolean byLocation = locations.isIncludedAndNotExcluded(location.get());
if (Boolean.FALSE==byLocation)
return false;
return Boolean.TRUE.equals(byName)
|| Boolean.TRUE.equals(byLocation)
|| !(names.hasIncludes() || locations.hasIncludes());
}
} }