cleanup: never return null

This commit is contained in:
Eric House 2020-08-29 13:38:32 -07:00
parent 34d5ef291c
commit 42575f1380
8 changed files with 20 additions and 26 deletions

View file

@ -797,7 +797,7 @@ public class DBUtils {
public static long[] getRowIDsFor( Context context, String relayID ) public static long[] getRowIDsFor( Context context, String relayID )
{ {
long[] result = null; long[] result = {};
String[] columns = { ROW_ID }; String[] columns = { ROW_ID };
String selection = DBHelper.RELAYID + "='" + relayID + "'"; String selection = DBHelper.RELAYID + "='" + relayID + "'";
initDB( context ); initDB( context );
@ -814,7 +814,7 @@ public class DBUtils {
public static long[] getRowIDsFor( Context context, int gameID ) public static long[] getRowIDsFor( Context context, int gameID )
{ {
long[] result = null; long[] result = {};
String[] columns = { ROW_ID }; String[] columns = { ROW_ID };
String selection = String.format( DBHelper.GAMEID + "=%d", gameID ); String selection = String.format( DBHelper.GAMEID + "=%d", gameID );
initDB( context ); initDB( context );
@ -836,7 +836,7 @@ public class DBUtils {
public static boolean haveGame( Context context, int gameID ) public static boolean haveGame( Context context, int gameID )
{ {
long[] rows = getRowIDsFor( context, gameID ); long[] rows = getRowIDsFor( context, gameID );
return rows != null && 0 < rows.length; return 0 < rows.length;
} }
public static boolean haveGame( Context context, long rowid ) public static boolean haveGame( Context context, long rowid )
@ -1607,7 +1607,7 @@ public class DBUtils {
public static long[] getGroupGames( Context context, long groupID ) public static long[] getGroupGames( Context context, long groupID )
{ {
long[] result = null; long[] result = {};
initDB( context ); initDB( context );
String[] columns = { ROW_ID, DBHelper.HASMSGS }; String[] columns = { ROW_ID, DBHelper.HASMSGS };
String selection = String.format( "%s=%d", DBHelper.GROUPID, groupID ); String selection = String.format( "%s=%d", DBHelper.GROUPID, groupID );

View file

@ -2271,10 +2271,8 @@ public class GamesListDelegate extends ListDelegateBase
if ( null != relayIDs ) { if ( null != relayIDs ) {
for ( String relayID : relayIDs ) { for ( String relayID : relayIDs ) {
long[] rowids = DBUtils.getRowIDsFor( m_activity, relayID ); long[] rowids = DBUtils.getRowIDsFor( m_activity, relayID );
if ( null != rowids ) { for ( long rowid : rowids ) {
for ( long rowid : rowids ) { reloadGame( rowid );
reloadGame( rowid );
}
} }
} }
} }
@ -2289,13 +2287,11 @@ public class GamesListDelegate extends ListDelegateBase
outer: outer:
for ( String relayID : relayIDs ) { for ( String relayID : relayIDs ) {
long[] rowids = DBUtils.getRowIDsFor( m_activity, relayID ); long[] rowids = DBUtils.getRowIDsFor( m_activity, relayID );
if ( null != rowids ) { for ( long rowid : rowids ) {
for ( long rowid : rowids ) { if ( GameUtils.gameDictsHere( m_activity, rowid ) ) {
if ( GameUtils.gameDictsHere( m_activity, rowid ) ) { launchGame( rowid );
launchGame( rowid ); launched = true;
launched = true; break outer;
break outer;
}
} }
} }
} }
@ -2390,7 +2386,7 @@ public class GamesListDelegate extends ListDelegateBase
{ {
boolean handled = false; boolean handled = false;
long[] rowids = DBUtils.getRowIDsFor( m_activity, gameID ); long[] rowids = DBUtils.getRowIDsFor( m_activity, gameID );
if ( null != rowids && 0 < rowids.length ) { if ( 0 < rowids.length ) {
launchGame( rowids[0] ); launchGame( rowids[0] );
handled = true; handled = true;
} }

View file

@ -550,7 +550,7 @@ public class MQTTUtils extends Thread implements IMqttActionListener, MqttCallba
Log.d( TAG, "handleMessage(gameID=%d): got message", gameID ); Log.d( TAG, "handleMessage(gameID=%d): got message", gameID );
MQTTServiceHelper helper = new MQTTServiceHelper( context, from ); MQTTServiceHelper helper = new MQTTServiceHelper( context, from );
long[] rowids = DBUtils.getRowIDsFor( context, gameID ); long[] rowids = DBUtils.getRowIDsFor( context, gameID );
Log.d( TAG, "got %d rows for gameID %d", rowids == null ? 0 : rowids.length, gameID ); Log.d( TAG, "got %d rows for gameID %d", rowids.length, gameID );
if ( 0 == rowids.length ) { if ( 0 == rowids.length ) {
notifyNotHere( context, from.mqtt_devID, gameID ); notifyNotHere( context, from.mqtt_devID, gameID );
} else { } else {

View file

@ -377,7 +377,7 @@ public class NFCUtils {
switch ( typ[0] ) { switch ( typ[0] ) {
case MESSAGE: case MESSAGE:
long[] rowids = DBUtils.getRowIDsFor( context, gameID[0] ); long[] rowids = DBUtils.getRowIDsFor( context, gameID[0] );
if ( null == rowids || 0 == rowids.length ) { if ( 0 == rowids.length ) {
addReplyFor( new byte[]{REPLY_NOGAME}, gameID[0] ); addReplyFor( new byte[]{REPLY_NOGAME}, gameID[0] );
} else { } else {
for ( long rowid : rowids ) { for ( long rowid : rowids ) {

View file

@ -755,11 +755,9 @@ public class RelayService extends XWJIService
String relayID = relayIDs[ii]; String relayID = relayIDs[ii];
BackMoveResult bmr = bmrs[ii]; BackMoveResult bmr = bmrs[ii];
long[] rowids = DBUtils.getRowIDsFor( this, relayID ); long[] rowids = DBUtils.getRowIDsFor( this, relayID );
if ( null != rowids ) { for ( long rowid : rowids ) {
for ( long rowid : rowids ) { GameUtils.postMoveNotification( this, rowid, bmr,
GameUtils.postMoveNotification( this, rowid, bmr, locals.get(ii) );
locals.get(ii) );
}
} }
} }
} }

View file

@ -779,7 +779,7 @@ public class WiDirService extends XWService {
private void makeGame( NetLaunchInfo nli, String senderMac ) private void makeGame( NetLaunchInfo nli, String senderMac )
{ {
long[] rowids = DBUtils.getRowIDsFor( this, nli.gameID() ); long[] rowids = DBUtils.getRowIDsFor( this, nli.gameID() );
if ( null == rowids || 0 == rowids.length ) { if ( 0 == rowids.length ) {
CommsAddrRec addr = nli.makeAddrRec( this ); CommsAddrRec addr = nli.makeAddrRec( this );
long rowid = GameUtils.makeNewMultiGame( this, nli, long rowid = GameUtils.makeNewMultiGame( this, nli,
m_sink, m_sink,

View file

@ -63,7 +63,7 @@ abstract class XWServiceHelper {
{ {
ReceiveResult result; ReceiveResult result;
long[] rowids = DBUtils.getRowIDsFor( mContext, gameID ); long[] rowids = DBUtils.getRowIDsFor( mContext, gameID );
if ( null == rowids || 0 == rowids.length ) { if ( 0 == rowids.length ) {
result = ReceiveResult.GAME_GONE; result = ReceiveResult.GAME_GONE;
} else { } else {
result = ReceiveResult.UNCONSUMED; result = ReceiveResult.UNCONSUMED;

View file

@ -288,7 +288,7 @@ public class DUtilCtxt {
String pauserName, String expl ) String pauserName, String expl )
{ {
long[] rowids = DBUtils.getRowIDsFor( m_context, gameID ); long[] rowids = DBUtils.getRowIDsFor( m_context, gameID );
Log.d( TAG, "got %d games with gameid", null == rowids ? 0 : rowids.length ); Log.d( TAG, "got %d games with gameid", rowids.length );
final boolean isPause = UNPAUSED != pauseType; final boolean isPause = UNPAUSED != pauseType;