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

Some modernisation. #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ libraryDependencies += "com.github.jgonian" % "commons-ip-math" % s"${version}"

For the latest released `version`, check [the Central Repository](https://maven-badges.herokuapp.com/maven-central/com.github.jgonian/commons-ip-math).

Versions
--------

Starting from version *2.0*, the minimum Java version required has changed to Java 8. This is in
order to support [JPMS](https://en.wikipedia.org/wiki/Java_Platform_Module_System).

* To use version *2.0* or later as a module, a minimum of Java 9 will be required. The module name is `com.github.jgonian.ipmath`.
* To use version *2.0* or later as a traditional classpath library, a minimum of Java 8 will be required.
* To use with Java 1.6 and Java 1.7, your should use latest the latest of the *1.x* versions of this library.


Examples
---------

Expand Down
2 changes: 1 addition & 1 deletion commons-ip-math-gwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.jgonian</groupId>
<artifactId>commons-ip-math-parent</artifactId>
<version>1.33-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>

<artifactId>commons-ip-math-gwt</artifactId>
Expand Down
50 changes: 47 additions & 3 deletions commons-ip-math/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.jgonian</groupId>
<artifactId>commons-ip-math-parent</artifactId>
<version>1.33-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>

<artifactId>commons-ip-math</artifactId>
Expand All @@ -16,13 +16,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>1.7.5</version>
<version>3.14.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -34,6 +34,50 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>8</release>
</configuration>
</execution>
<execution>
<id>compile9</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java</compileSourceRoot>
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.github.jgonian.ipmath;

@SuppressWarnings("serial")
public abstract class AbstractIp<T extends AbstractIp<T, R>, R extends AbstractIpRange<T, R>>
implements SingleInternetResource<T, R> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static java.math.BigInteger.ONE;
import static java.math.BigInteger.ZERO;

@SuppressWarnings("serial")
public abstract class AbstractIpRange<C extends AbstractIp<C, R>, R extends AbstractIpRange<C, R>>
extends AbstractRange<C, R>
implements InternetResourceRange<C, R> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Iterator;
import java.util.List;

@SuppressWarnings("serial")
public abstract class AbstractRange<C extends Rangeable<C, R>, R extends Range<C, R>> implements Range<C, R> {

private final C start;
Expand Down Expand Up @@ -188,7 +189,7 @@ public final boolean equals(Object o) {
if (!(o instanceof AbstractRange)) {
return false;
}
AbstractRange that = (AbstractRange) o;
AbstractRange<?,?> that = (AbstractRange<?,?>) o;
if (!start.equals(that.start)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.github.jgonian.ipmath;

@SuppressWarnings("serial")
public final class AsnRange extends AbstractRange<Asn, AsnRange> implements InternetResourceRange<Asn, AsnRange> {

protected AsnRange(Asn start, Asn end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package com.github.jgonian.ipmath;

import java.math.BigInteger;
import java.util.regex.Pattern;

import static java.math.BigInteger.ONE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static <R extends Range<?, R>> Comparator<R> reverse() {
private SizeComparator() {
}

@SuppressWarnings({"unchecked"})
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public int compare(R left, R right) {
return ((Comparable)left.size()).compareTo(right.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public final boolean equals(Object o) {
if (!(o instanceof SortedRangeSet)) {
return false;
}
SortedRangeSet that = (SortedRangeSet) o;
SortedRangeSet<?, ?> that = (SortedRangeSet<?, ?>) o;
return set.equals(that.set);
}

Expand Down
3 changes: 3 additions & 0 deletions commons-ip-math/src/main/java9/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module com.github.jgonian.ipmath {
exports com.github.jgonian.ipmath;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package com.github.jgonian.ipmath;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -830,7 +830,8 @@ public void shouldRemoveIfOtherIsContainedAndOnStart() {
assertEquals(result, range.exclude(other));
}

@Test
@SuppressWarnings("serial")
@Test
public void shouldRemoveIfOtherIsContained() {
// range |---------| [10, 20]
// other |--| [13, 15]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*/
package com.github.jgonian.ipmath;

import static junit.framework.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static com.github.jgonian.ipmath.Asn.*;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -117,9 +119,9 @@ public void testToString() {

@Test
public void testSize() {
assertEquals(new Long(1), as1.asRange().size());
assertEquals(new Long(ASN_16_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_16_BIT_ASN).size());
assertEquals(new Long(ASN_32_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_32_BIT_ASN).size());
assertEquals(Long.valueOf(1), as1.asRange().size());
assertEquals(Long.valueOf(ASN_16_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_16_BIT_ASN).size());
assertEquals(Long.valueOf(ASN_32_BIT_MAX_VALUE + 1), AsnRange.from(FIRST_ASN).to(Asn.LAST_32_BIT_ASN).size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,28 @@
*/
package com.github.jgonian.ipmath;

import org.junit.Rule;
import static org.junit.Assert.assertThrows;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;

import java.util.Arrays;
import java.util.List;

@RunWith(Parameterized.class)
public class Ipv4ParseInvalidTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

@Parameter(0)
public String input;

@Test
public void test() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid IPv4 address: '" + input + "'");
Ipv4.parse(input);
assertThrows("Invalid IPv4 address: '" + input + "'", IllegalArgumentException.class, () -> {
Ipv4.parse(input);
});
}

@Parameters(name = "{index}: parse({0})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import static com.github.jgonian.ipmath.Ipv4.FIRST_IPV4_ADDRESS;
import static com.github.jgonian.ipmath.Ipv4.LAST_IPV4_ADDRESS;
import static com.github.jgonian.ipmath.Ipv4.MAXIMUM_VALUE;
import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertEquals;

public class Ipv4RangeTest extends AbstractRangeTest<Ipv4, Ipv4Range> {
Expand Down Expand Up @@ -185,8 +185,8 @@ public void testToStringInDecimalNotation() {

@Test
public void testSize() {
assertEquals(new Long(1), ip1.asRange().size());
assertEquals(new Long(MAXIMUM_VALUE + 1), Ipv4Range.from(FIRST_IPV4_ADDRESS).to(LAST_IPV4_ADDRESS).size());
assertEquals(Long.valueOf(1), ip1.asRange().size());
assertEquals(Long.valueOf(MAXIMUM_VALUE + 1), Ipv4Range.from(FIRST_IPV4_ADDRESS).to(LAST_IPV4_ADDRESS).size());
}

@Override
Expand Down
Loading