Skip to content

Commit

Permalink
Refactor Guava's Optional usage in favor of JDK8's
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo committed Aug 24, 2024
1 parent 5415c29 commit 6a0b26a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.maven.util;

import com.google.common.base.Optional;
import japicmp.util.ModifierHelper;
import javassist.ClassPool;
import javassist.CtClass;
Expand All @@ -12,13 +11,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class CtClassBuilder {
private static final String DEFAULT_CLASS_NAME = "japicmp.Test";
private String name = DEFAULT_CLASS_NAME;
private int modifier = Modifier.PUBLIC;
private final List<String> annotations = new ArrayList<>();
private Optional<CtClass> superclass = Optional.absent();
private Optional<CtClass> superclass = Optional.empty();
private final List<CtClass> interfaces = new ArrayList<>();

public CtClassBuilder name(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package japicmp.maven.util;

import com.google.common.base.Optional;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;

import java.util.Optional;

public class CtInterfaceBuilder {
private String name = "japicmp.Test";
private Optional<CtClass> superInterfaceOptional = Optional.absent();
private Optional<CtClass> superInterfaceOptional = Optional.empty();

public CtInterfaceBuilder name(String name) {
this.name = name;
Expand All @@ -29,7 +30,7 @@ public static CtInterfaceBuilder create() {
}

public CtInterfaceBuilder withSuperInterface(CtClass superInterface) {
this.superInterfaceOptional = Optional.fromNullable(superInterface);
this.superInterfaceOptional = Optional.ofNullable(superInterface);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test.service;

import com.google.common.base.Optional;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -9,6 +8,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
Expand All @@ -30,6 +30,6 @@ private Optional<String> findLineThatContains(List<String> lines, String str) {
return Optional.of(line);
}
}
return Optional.absent();
return Optional.empty();
}
}
4 changes: 2 additions & 2 deletions japicmp/src/test/java/japicmp/util/CtClassBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.util;

import com.google.common.base.Optional;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.Modifier;
Expand All @@ -13,13 +12,14 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class CtClassBuilder {
public static final String DEFAULT_CLASS_NAME = "japicmp.Test";
private String name = DEFAULT_CLASS_NAME;
private int modifier = Modifier.PUBLIC;
private final Map<String, CtElement[]> annotations = new HashMap<>();
private Optional<CtClass> superclass = Optional.absent();
private Optional<CtClass> superclass = Optional.empty();
private final List<CtClass> interfaces = new ArrayList<>();

public CtClassBuilder name(String name) {
Expand Down
7 changes: 4 additions & 3 deletions japicmp/src/test/java/japicmp/util/CtInterfaceBuilder.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package japicmp.util;

import com.google.common.base.Optional;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;

import java.util.Optional;

public class CtInterfaceBuilder {
private String name = "japicmp.Test";
private Optional<CtClass> superInterfaceOptional = Optional.absent();
private Optional<CtClass> superInterfaceOptional = Optional.empty();

public CtInterfaceBuilder name(String name) {
this.name = name;
Expand All @@ -29,7 +30,7 @@ public static CtInterfaceBuilder create() {
}

public CtInterfaceBuilder withSuperInterface(CtClass superInterface) {
this.superInterfaceOptional = Optional.fromNullable(superInterface);
this.superInterfaceOptional = Optional.ofNullable(superInterface);
return this;
}
}

0 comments on commit 6a0b26a

Please sign in to comment.