cleanup: don't need wrapper around a List<>

This commit is contained in:
Eric House 2019-01-06 16:58:30 -08:00
parent 2a845da9b6
commit 0953772673
3 changed files with 18 additions and 34 deletions

View file

@ -34,6 +34,7 @@ import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
import org.eehouse.android.xw4.DlgDelegate.Action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -55,12 +56,12 @@ public class BTInviteDelegate extends InviteDelegate {
// HashMap: m_stamps is serialized, so can't be abstract type
HashMap<String, Long> stamps = new HashMap<>();
void add( BluetoothDevice dev ) {
String devName = dev.getName();
Log.d( TAG, "add(%s)", devName );
void add( String devAddress, String devName ) {
// If it's already there, update it. Otherwise create new
boolean alreadyHave = false;
if ( null != pairs ) {
if ( null == pairs ) {
pairs = new ArrayList<>();
} else {
for ( TwoStringPair pair : pairs ) {
alreadyHave = pair.str2.equals(devName);
if ( alreadyHave ) {
@ -68,8 +69,9 @@ public class BTInviteDelegate extends InviteDelegate {
}
}
}
if ( !alreadyHave ) {
pairs = TwoStringPair.add( pairs, dev.getAddress(), devName );
pairs.add( new TwoStringPair( devAddress, devName ) );
}
stamps.put( devName, System.currentTimeMillis() );
sort();
@ -80,7 +82,7 @@ public class BTInviteDelegate extends InviteDelegate {
for ( InviterItem item : checked ) {
TwoStringPair pair = (TwoStringPair)item;
stamps.remove( pair.str2 );
TwoStringPair.remove( pairs, pair );
pairs.remove( pair );
}
}
@ -102,8 +104,7 @@ public class BTInviteDelegate extends InviteDelegate {
{
String name = "Faker";
if ( !stamps.containsKey(name) ) {
pairs = TwoStringPair.add( pairs, "00:00:00:00:00:00", name );
stamps.put( name, System.currentTimeMillis() );
add( "00:00:00:00:00:00", name );
}
}
}
@ -247,7 +248,7 @@ public class BTInviteDelegate extends InviteDelegate {
{
DbgUtils.assertOnUIThread();
mPersisted.add( dev );
mPersisted.add( dev.getAddress(), dev.getName() );
store();
updateListAdapter( mPersisted.pairs );

View file

@ -58,41 +58,24 @@ abstract class InviteDelegate extends ListDelegateBase
}
protected static class TwoStringPair implements InviterItem, Serializable {
public String str1;
private String mDev;
public String str2;
public TwoStringPair( String str1, String str2 ) {
this.str1 = str1; this.str2 = str2;
public TwoStringPair( String dev, String str2 ) {
mDev = dev; this.str2 = str2;
}
public static List<TwoStringPair> add( List<TwoStringPair> pairs, String name,
String addr )
{
if ( null == pairs ) {
pairs = new ArrayList<>();
}
pairs.add( new TwoStringPair( name, addr ) );
return pairs;
}
public static void remove( List<TwoStringPair> pairs, InviterItem dead )
{
pairs.remove(dead);
}
public String getDev() { return str1; }
public String getDev() { return mDev; }
public boolean equals( InviterItem item )
{
boolean result = false;
if ( null != item ) {
TwoStringPair pair = (TwoStringPair)item;
result = str1.equals( pair.str1 )
result = mDev.equals( pair.mDev )
&& ((null == str2 && null == pair.str2)
|| str2.equals( pair.str2 ) );
Log.d( TAG, "%s.equals(%s) => %b", str1, pair.str1, result );
Log.d( TAG, "%s.equals(%s) => %b", mDev, pair.mDev, result );
}
return result;
}

View file

@ -81,7 +81,7 @@ public class WiDirInviteDelegate extends InviteDelegate
protected void onChildAdded( View child, InviterItem data )
{
TwoStringPair pair = (TwoStringPair)data;
((TwoStrsItem)child).setStrings( pair.str2, pair.str1 );
((TwoStrsItem)child).setStrings( pair.str2, pair.getDev() );
}
@Override
@ -89,7 +89,7 @@ public class WiDirInviteDelegate extends InviteDelegate
{
for ( int ii = 0; ii < selected.length; ++ii ) {
TwoStringPair pair = (TwoStringPair)selected[ii];
devs[ii] = pair.str1;
devs[ii] = pair.getDev();
}
}