Use Optional from java.util, not Guava
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 23 Feb 2015 05:34:46 +0000 (06:34 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 23 Feb 2015 05:34:46 +0000 (06:34 +0100)
src/main/java/net/pterodactylus/irc/DefaultConnection.java
src/main/java/net/pterodactylus/irc/event/ChannelLeft.java
src/main/java/net/pterodactylus/irc/event/KickedFromChannel.java
src/main/java/net/pterodactylus/xdcc/core/Core.java

index cca6aed..8fe4c4b 100644 (file)
@@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -63,7 +64,6 @@ import net.pterodactylus.irc.util.RandomNickname;
 import net.pterodactylus.xdcc.util.io.BandwidthCountingInputStream;
 import net.pterodactylus.xdcc.util.io.BandwidthCountingOutputStream;
 
-import com.google.common.base.Optional;
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
 import com.google.common.io.Closeables;
@@ -107,13 +107,13 @@ public class DefaultConnection extends AbstractExecutionThreadService implements
        private String nickname = null;
 
        /** The username. */
-       private Optional<String> username = Optional.absent();
+       private Optional<String> username = Optional.empty();
 
        /** The real name. */
-       private Optional<String> realName = Optional.absent();
+       private Optional<String> realName = Optional.empty();
 
        /** The optional password for the connection. */
-       private Optional<String> password = Optional.absent();
+       private Optional<String> password = Optional.empty();
 
        /** The connection handler. */
        private ConnectionHandler connectionHandler;
@@ -167,19 +167,19 @@ public class DefaultConnection extends AbstractExecutionThreadService implements
 
        @Override
        public Connection username(String username) {
-               this.username = Optional.fromNullable(username);
+               this.username = Optional.ofNullable(username);
                return this;
        }
 
        @Override
        public Connection realName(String realName) {
-               this.realName = Optional.fromNullable(realName);
+               this.realName = Optional.ofNullable(realName);
                return this;
        }
 
        @Override
        public Connection password(String password) {
-               this.password = Optional.fromNullable(password);
+               this.password = Optional.ofNullable(password);
                return this;
        }
 
@@ -367,7 +367,7 @@ public class DefaultConnection extends AbstractExecutionThreadService implements
        //
 
        /**
-        * Returns an item from the list, or {@link Optional#absent()} if the list is
+        * Returns an item from the list, or {@link Optional#empty()} if the list is
         * shorter than required for the given index.
         *
         * @param list
@@ -377,13 +377,13 @@ public class DefaultConnection extends AbstractExecutionThreadService implements
         * @param <T>
         *              The type of the list items
         * @return This list item wrapped in an {@link Optional}, or {@link
-        *         Optional#absent()} if the list is not long enough
+        *         Optional#empty()} if the list is not long enough
         */
        private static <T> Optional<T> getOptional(List<T> list, int index) {
                if (index < list.size()) {
-                       return Optional.fromNullable(list.get(index));
+                       return Optional.ofNullable(list.get(index));
                }
-               return Optional.absent();
+               return Optional.empty();
        }
 
        /** Handles input and output for the connection. */
index 00b088a..3d99a7f 100644 (file)
 
 package net.pterodactylus.irc.event;
 
+import java.util.Optional;
+
 import net.pterodactylus.irc.Connection;
 import net.pterodactylus.irc.Source;
 
-import com.google.common.base.Optional;
-
 /**
  * Event that notifies a listener that a client has left a channel.
  *
index 54b4f67..58c1ca2 100644 (file)
@@ -1,10 +1,10 @@
 package net.pterodactylus.irc.event;
 
+import java.util.Optional;
+
 import net.pterodactylus.irc.Connection;
 import net.pterodactylus.irc.Source;
 
-import com.google.common.base.Optional;
-
 /**
  * Event that signals that a client was kicked from a channel.
  *
index 99c5ab6..bfad867 100644 (file)
@@ -747,7 +747,7 @@ public class Core extends AbstractExecutionThreadService {
                                        "Kicked from %s by %s: %s",
                                        kickedFromChannel.channel(),
                                        kickedFromChannel.kicker(),
-                                       kickedFromChannel.reason().or("<unknown>")
+                                       kickedFromChannel.reason().orElse("<unknown>")
                        )));
                }
        }