From 920800afdb03718187ebc014ea4555429ea24ea1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 27 Mar 2014 17:48:11 +0100 Subject: [PATCH] Use Java 1.8, and its Optional. --- pom.xml | 4 ++-- .../java/net/pterodactylus/rhynodge/engine/Engine.java | 8 ++++---- .../net/pterodactylus/rhynodge/states/StateManager.java | 16 ++++++++-------- .../pterodactylus/rhynodge/states/StateManagerTest.java | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 82d5659..514ded5 100644 --- a/pom.xml +++ b/pom.xml @@ -21,8 +21,8 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + 1.8 + 1.8 diff --git a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java index bbca3af..861bfba 100644 --- a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java +++ b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java @@ -17,14 +17,15 @@ package net.pterodactylus.rhynodge.engine; -import static com.google.common.base.Optional.absent; -import static com.google.common.base.Optional.of; import static com.google.common.collect.Maps.newTreeMap; import static java.lang.String.format; +import static java.util.Optional.empty; +import static java.util.Optional.of; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.SortedMap; import net.pterodactylus.rhynodge.Filter; @@ -35,7 +36,6 @@ import net.pterodactylus.rhynodge.states.AbstractState; import net.pterodactylus.rhynodge.states.FailedState; import net.pterodactylus.rhynodge.states.StateManager; -import com.google.common.base.Optional; import com.google.common.util.concurrent.AbstractExecutionThreadService; import org.apache.commons.lang3.tuple.Pair; import org.apache.log4j.Logger; @@ -227,7 +227,7 @@ public class Engine extends AbstractExecutionThreadService { return of(new NextReaction(keyReaction.getKey(), keyReaction.getValue(), nextReactions.firstKey())); } } - return absent(); + return empty(); } private static class NextReaction { diff --git a/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java b/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java index a52e74d..3e08c29 100644 --- a/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java +++ b/src/main/java/net/pterodactylus/rhynodge/states/StateManager.java @@ -17,15 +17,15 @@ package net.pterodactylus.rhynodge.states; -import static com.google.common.base.Optional.absent; -import static com.google.common.base.Optional.fromNullable; +import static java.util.Optional.empty; +import static java.util.Optional.ofNullable; import java.io.File; import java.io.IOException; +import java.util.Optional; import net.pterodactylus.rhynodge.State; -import com.google.common.base.Optional; import org.apache.log4j.Logger; import com.fasterxml.jackson.core.JsonGenerationException; @@ -68,7 +68,7 @@ public class StateManager { * * @param reactionName * The name of the reaction - * @return The loaded state, or {@link Optional#absent()} if the state could not be + * @return The loaded state, or {@link Optional#empty()} if the state could not be * loaded */ public Optional loadLastState(String reactionName) { @@ -80,7 +80,7 @@ public class StateManager { * * @param reactionName * The name of the reaction - * @return The loaded state, or {@link Optional#absent()} if the state could not be + * @return The loaded state, or {@link Optional#empty()} if the state could not be * loaded */ public Optional loadLastSuccessfulState(String reactionName) { @@ -141,14 +141,14 @@ public class StateManager { * @param successful * {@code true} to load the last successful state, {@code false} * to load the last state - * @return The loaded state, or {@link Optional#absent()} if the state could not be + * @return The loaded state, or {@link Optional#empty()} if the state could not be * loaded */ private Optional loadLastState(String reactionName, boolean successful) { File stateFile = stateFile(reactionName, successful ? "success" : "last"); try { State state = objectMapper.readValue(stateFile, AbstractState.class); - return fromNullable(state); + return ofNullable(state); } catch (JsonParseException jpe1) { logger.warn(String.format("State for Reaction “%s” could not be parsed.", reactionName), jpe1); } catch (JsonMappingException jme1) { @@ -156,7 +156,7 @@ public class StateManager { } catch (IOException ioe1) { logger.info(String.format("State for Reaction “%s” could not be found.", reactionName)); } - return absent(); + return empty(); } } diff --git a/src/test/java/net/pterodactylus/rhynodge/states/StateManagerTest.java b/src/test/java/net/pterodactylus/rhynodge/states/StateManagerTest.java index 5837846..6541c11 100644 --- a/src/test/java/net/pterodactylus/rhynodge/states/StateManagerTest.java +++ b/src/test/java/net/pterodactylus/rhynodge/states/StateManagerTest.java @@ -9,11 +9,11 @@ import static org.hamcrest.Matchers.is; import java.io.File; import java.io.IOException; +import java.util.Optional; import net.pterodactylus.rhynodge.State; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Optional; import com.google.common.io.Files; import org.hamcrest.Matchers; import org.junit.BeforeClass; -- 2.7.4