Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shim Java 10 collections APIs #328

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions aggregate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
<packaging>pom</packaging>
<version>20220608.2-SNAPSHOT</version>
<parent>
<relativePath>../parent</relativePath>
<relativePath>..</relativePath>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>parent</artifactId>
<version>20220608.2-SNAPSHOT</version>
</parent>

<modules>
<module>..</module>
<module>../html-types</module>
<module>../parent</module>
<module>../java8-shim</module>
<module>../java10-shim</module>
<module>../owasp-java-html-sanitizer</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion empiricism/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<version>20220608.2-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<relativePath>../parent</relativePath>
<relativePath>..</relativePath>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>parent</artifactId>
<version>20220608.2-SNAPSHOT</version>
Expand Down
2 changes: 1 addition & 1 deletion html-types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<version>20220608.2-SNAPSHOT</version>
<packaging>bundle</packaging>
<parent>
<relativePath>../parent</relativePath>
<relativePath>..</relativePath>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>parent</artifactId>
<version>20220608.2-SNAPSHOT</version>
Expand Down
41 changes: 41 additions & 0 deletions java10-shim/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java10-shim</artifactId>
<packaging>jar</packaging>
<parent>
<relativePath>..</relativePath>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>parent</artifactId>
<version>20220608.2-SNAPSHOT</version>
</parent>

<name>Java 10 Shim</name>
<description>
Provides an implementation of java8-shim that interoperates with
Java >= 10 idioms for immutable collections.
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>10</release>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>java8-shim</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
67 changes: 67 additions & 0 deletions java10-shim/src/main/java/org/owasp/shim/ForJava9AndLater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.owasp.shim;

import java.util.*;

@SuppressWarnings("Since15") // We're compiling two versions to handle @since problems.
final class ForJava9AndLater extends Java8Shim {

@Override public <T> List<T> listOf() {
return List.of();
}

@Override public <T> List<T> listOf(T a) {
return List.of(a);
}

@Override public <T> List<T> listOf(T a, T b) {
return List.of(a, b);
}

@Override public <T> List<T> listOf(T a, T b, T c) {
return List.of(a, b, c);
}

@Override public <T> List<T> listOf(T... els) {
return List.of(els);
}

@Override public <T> List<T> listCopyOf(Collection<? extends T> c) {
return List.copyOf(c);
}

@Override public <K, V> Map<K, V> mapCopyOf(Map<? extends K, ? extends V> m) {
return Map.copyOf(m);
}

@Override public <K, V> Map.Entry<K, V> mapEntry(K key, V value) {
return Map.entry(key, value);
}

@Override public <K, V> Map<K, V> mapOfEntries(Map.Entry<K, V>... entries) {
return Map.ofEntries(entries);
}

@Override public <T> Set<T> setOf() {
return Set.of();
}

@Override public <T> Set<T> setOf(T a) {
return Set.of(a);
}

@Override public <T> Set<T> setOf(T a, T b) {
return Set.of(a, b);
}

@Override public <T> Set<T> setOf(T a, T b, T c) {
return Set.of(a, b, c);
}

@Override public <T> Set<T> setOf(T... els) {
return Set.of(els);
}

@Override public <T> Set<T> setCopyOf(Collection<? extends T> c) {
return Set.copyOf(c);
}
}
38 changes: 38 additions & 0 deletions java8-shim/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java8-shim</artifactId>
<packaging>jar</packaging>
<parent>
<relativePath>..</relativePath>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>parent</artifactId>
<version>20220608.2-SNAPSHOT</version>
</parent>

<name>Java 8 Shim</name>
<description>
Backports @since Java 9 collection factories like List.of onto
Java8 in a way that uses the real ones where available, falls back
to a conforming implementation on Java8 and JIT compiles well.
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading
Loading