Skip to content

Commit

Permalink
Cleanup redundant specification of type parameters (#320)
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strickroth <[email protected]>
  • Loading branch information
csware authored Feb 2, 2024
1 parent 3c86741 commit cd61b17
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/CssTokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void lex() {
sb.setLength(0);
if (pos == cssLimit) { return; }

tokenTypes = new ArrayList<TokenType>();
tokenTypes = new ArrayList<>();

@SuppressWarnings("hiding") // final
String css = this.css;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface Handler<T> {
void handle(T x);

/** A handler that does nothing given any input. */
public static final Handler<Object> DO_NOTHING = new Handler<Object>() {
public static final Handler<Object> DO_NOTHING = new Handler<>() {
public void handle(Object x) {
// Really, do nothing.
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/owasp/html/HtmlChangeReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public HtmlChangeReporter(
HtmlStreamEventReceiver renderer,
HtmlChangeListener<? super T> listener, @Nullable T context) {
this.output = new OutputChannel(renderer);
this.input = new InputChannel<T>(output, listener, context);
this.input = new InputChannel<>(output, listener, context);
}

/**
Expand Down Expand Up @@ -149,7 +149,7 @@ public void text(String textChunk) {
private static final class OutputChannel implements HtmlStreamEventReceiver {
private final HtmlStreamEventReceiver renderer;
String expectedElementName;
Set<String> expectedAttrNames = new LinkedHashSet<String>();
Set<String> expectedAttrNames = new LinkedHashSet<>();

OutputChannel(HtmlStreamEventReceiver renderer) {
this.renderer = renderer;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/HtmlElementTables.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public enum TextContentModelBit {
}

static final Comparator<int[]> COMPARE_BY_ZEROTH =
new Comparator<int[]>() {
new Comparator<>() {
public int compare(int[] a, int[] b) {
return Integer.compare(a[0], b[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/HtmlEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ final class HtmlEntities {

final Map<String, String> entityNameToCodePointMap = Collections.unmodifiableMap(builder);

ENTITY_TRIE = new Trie<String>(entityNameToCodePointMap);
ENTITY_TRIE = new Trie<>(entityNameToCodePointMap);
LONGEST_ENTITY_NAME = longestEntityName;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/HtmlPolicyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ public String apply(String elementName, List<String> attrs) {
relValue = DEFAULT_RELS_ON_TARGETTED_LINKS_STR;
} else {
StringBuilder sb = new StringBuilder();
Set<String> present = new HashSet<String>();
Set<String> present = new HashSet<>();
if (relIndex >= 0) {
// Preserve values that are not explicitly skipped.
String rels = attrs.get(relIndex);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/owasp/html/Joinable.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static abstract class JoinHelper<T, SJ extends Joinable<SJ>> {
final T zeroValue;
final T identityValue;
private Map<JoinStrategy<SJ>, Set<SJ>> requireSpecialJoining;
private Set<T> uniq = new LinkedHashSet<T>();
private Set<T> uniq = new LinkedHashSet<>();

JoinHelper(
Class<T> baseType,
Expand Down Expand Up @@ -74,11 +74,11 @@ void unroll(T x) {
JoinStrategy<SJ> strategy = sj.getJoinStrategy();

if (requireSpecialJoining == null) {
requireSpecialJoining = new LinkedHashMap<Joinable.JoinStrategy<SJ>, Set<SJ>>();
requireSpecialJoining = new LinkedHashMap<>();
}
Set<SJ> toJoinTogether = requireSpecialJoining.get(strategy);
if (toJoinTogether == null) {
toJoinTogether = new LinkedHashSet<SJ>();
toJoinTogether = new LinkedHashSet<>();
requireSpecialJoining.put(strategy, toJoinTogether);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/PolicyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public <CTX> HtmlSanitizer.Policy apply(
if (listener == null) {
return apply(out);
} else {
HtmlChangeReporter<CTX> r = new HtmlChangeReporter<CTX>(
HtmlChangeReporter<CTX> r = new HtmlChangeReporter<>(
out, listener, context);
r.setPolicy(apply(r.getWrappedRenderer()));
return r.getWrappedPolicy();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/owasp/html/Trie.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ private Trie(
char ch = elements.get(i).getKey().charAt(depth);
if (ch != lastCh) {
childMap[childIndex] = lastCh;
children[childIndex++] = new Trie<T>(
children[childIndex++] = new Trie<>(
elements, depth + 1, childStart, i);
childStart = i;
lastCh = ch;
}
}
childMap[childIndex] = lastCh;
children[childIndex++] = new Trie<T>(elements, depth + 1, childStart, end);
children[childIndex++] = new Trie<>(elements, depth + 1, childStart, end);
}

/** Does this node correspond to a complete string in the input set. */
Expand Down Expand Up @@ -151,8 +151,8 @@ public boolean contains(char ch) {

private static <U> List<Map.Entry<String, U>> sortedUniqEntries(
Map<String, U> m) {
return new ArrayList<Map.Entry<String, U>>(
new TreeMap<String, U>(m).entrySet());
return new ArrayList<>(
new TreeMap<>(m).entrySet());
}

private static final char[] ZERO_CHARS = new char[0];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/owasp/html/examples/UrlTextExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class UrlTextExample {

/** An event receiver that emits the domain of a link or image after it. */
static class AppendDomainAfterText extends HtmlStreamEventReceiverWrapper {
private final List<String> pendingText = new ArrayList<String>();
private final List<String> pendingText = new ArrayList<>();

AppendDomainAfterText(HtmlStreamEventReceiver underlying) {
super(underlying);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/owasp/html/Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private static String sanitize(String html) {
StringBuilder sb = new StringBuilder(html.length());

final HtmlStreamRenderer renderer = HtmlStreamRenderer.create(
sb, new Handler<String>() {
sb, new Handler<>() {

public void handle(String x) {
throw new AssertionError(x);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/owasp/html/HtmlChangeReporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static final void testChangeReporting() {
final StringBuilder log = new StringBuilder();
HtmlStreamRenderer renderer = HtmlStreamRenderer.create(
out, Handler.DO_NOTHING);
HtmlChangeListener<Context> listener = new HtmlChangeListener<Context>() {
HtmlChangeListener<Context> listener = new HtmlChangeListener<>() {
public void discardedTag(Context context, String elementName) {
assertSame(testContext, context);
log.append('<').append(elementName).append("> ");
Expand All @@ -63,7 +63,7 @@ public void discardedAttributes(
log.append("> ");
}
};
HtmlChangeReporter<Context> hcr = new HtmlChangeReporter<Context>(
HtmlChangeReporter<Context> hcr = new HtmlChangeReporter<>(
renderer, listener, testContext);

hcr.setPolicy(Sanitizers.FORMATTING.apply(hcr.getWrappedRenderer()));
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/owasp/html/HtmlSanitizerFuzzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public final void testFuzzHtmlParser() throws Exception {
char[] fuzzyHtml1 = new char[length];

final LinkedBlockingQueue<Throwable> failures
= new LinkedBlockingQueue<Throwable>();
= new LinkedBlockingQueue<>();

final int runCount = 1000;
// Use an executor so that any infinite loops do not cause the test runner
// to fail.
ThreadPoolExecutor executor = new ThreadPoolExecutor(
10, 10, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
10, 10, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>());

for (int run = runCount; --run >= 0;) {
for (int i = length; --i >= 0;) { fuzzyHtml0[i] = html.charAt(i); }
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/owasp/html/IntVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void testIntVector() {
Random r = new Random(0xA03B79241106C82FL);

IntVector iv = new IntVector();
LinkedList<Integer> ad = new LinkedList<Integer>();
LinkedList<Integer> ad = new LinkedList<>();

for (int i = 0; i < 200000; ++i) {
switch (r.nextInt(4)) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/owasp/html/PolicyFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static void testAnd() {
final StringBuilder out = new StringBuilder();

// A noisy listener that logs.
HtmlChangeListener<Object> listener = new HtmlChangeListener<Object>() {
HtmlChangeListener<Object> listener = new HtmlChangeListener<>() {

public void discardedTag(Object ctx, String elementName) {
assertEquals(context, ctx);
Expand All @@ -141,7 +141,7 @@ public void discardedAttributes(

};

Handler<IOException> ioHandler = new Handler<IOException>() {
Handler<IOException> ioHandler = new Handler<>() {

public void handle(IOException x) {
log.append("Handled IOException " + x.getMessage() + "\n");
Expand All @@ -150,7 +150,7 @@ public void handle(IOException x) {
};

// Should not be called.
Handler<String> badHtmlHandler = new Handler<String>() {
Handler<String> badHtmlHandler = new Handler<>() {

public void handle(String x) {
throw new AssertionError(x);
Expand Down Expand Up @@ -611,7 +611,7 @@ static final class SubstringFilter implements AttributePolicy {

public String apply(
String elementName, String attributeName, String value) {
List<String> outParts = new ArrayList<String>();
List<String> outParts = new ArrayList<>();
for (String part : value.split(",")) {
part = part.trim();
if (part.contains(substr)) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/owasp/html/SanitizersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static final void testAndOrdering() {
+ "<img src=\"http://example.org\" />oogle</a>";

for (List<PolicyFactory> permutation :
new Permutations<PolicyFactory>(
new Permutations<>(
Sanitizers.BLOCKS,
Sanitizers.IMAGES,
Sanitizers.STYLES,
Expand Down Expand Up @@ -584,7 +584,7 @@ private static class Permutations<T> implements Iterable<List<T>> {
}

public Iterator<List<T>> iterator() {
return new Iterator<List<T>>() {
return new Iterator<>() {
private int i;
private final int limit;
private final BitSet mask;
Expand Down

0 comments on commit cd61b17

Please sign in to comment.