From 60bec11225a49f0560e36ceda732f4fab3cf9e96 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 17 Nov 2014 10:59:03 +0200 Subject: [PATCH] Use assert instead of manual if/exception. --- .../com/nutomic/ensichat/bluetooth/ChatService.scala | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala b/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala index d7cfdd6..b02fc68 100644 --- a/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala +++ b/app/src/main/scala/com/nutomic/ensichat/bluetooth/ChatService.scala @@ -1,6 +1,5 @@ package com.nutomic.ensichat.bluetooth -import java.security.InvalidParameterException import java.util.{Date, UUID} import android.app.Service @@ -9,10 +8,10 @@ import android.content.{BroadcastReceiver, Context, Intent, IntentFilter} import android.os.Handler import android.preference.PreferenceManager import android.util.Log +import com.nutomic.ensichat.R import com.nutomic.ensichat.bluetooth.ChatService.{OnConnectionChangedListener, OnMessageReceivedListener} import com.nutomic.ensichat.messages._ import com.nutomic.ensichat.util.Database -import com.nutomic.ensichat.{BuildConfig, R} import scala.collection.SortedSet import scala.collection.immutable.{HashMap, HashSet, TreeSet} @@ -209,9 +208,7 @@ class ChatService extends Service { * Sends message to the device specified as receiver, */ def send(message: Message): Unit = { - if (BuildConfig.DEBUG && message.sender != localDeviceId) { - throw new InvalidParameterException("Message must be sent from local device") - } + assert(message.sender != localDeviceId, "Message must be sent from local device") connections.apply(message.receiver).send(message) handleNewMessage(message) } @@ -224,9 +221,8 @@ class ChatService extends Service { * Messages must always be sent between local device and a contact. */ private def handleNewMessage(message: Message): Unit = { - if (BuildConfig.DEBUG && message.sender != localDeviceId && message.receiver != localDeviceId) { - throw new InvalidParameterException("Message must be sent or received by local device") - } + assert(message.sender != localDeviceId && message.receiver != localDeviceId, + "Message must be sent or received by local device") Database.addMessage(message) MainHandler.post(new Runnable {