mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-14 05:25:07 -05:00
Adapted the filter method to work without list arguments. It's used more this way.
This commit is contained in:
parent
cba9ccd416
commit
277bfb879f
@ -8,6 +8,7 @@
|
|||||||
package com.fsck.k9.helper.configxmlparser;
|
package com.fsck.k9.helper.configxmlparser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
@ -432,67 +433,79 @@ public class AutoconfigInfo implements Parcelable {
|
|||||||
Logic
|
Logic
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// returns a list of available incoming server types
|
// returns a list of server types available in the provided list of servers
|
||||||
public List<ServerType> getAvailableIncomingServerTypes(){
|
// ( could use a set to implement the methods beneath but I don't think it would have extra benefits )
|
||||||
|
public List<ServerType> getAvailableServerTypes(List<? extends Server> servers){
|
||||||
ArrayList<ServerType> types = new ArrayList<ServerType>();
|
ArrayList<ServerType> types = new ArrayList<ServerType>();
|
||||||
// for now there is only support for imap & pop3 so this is a bit overkill
|
// for now there is only support for imap & pop3 so this is a bit overkill
|
||||||
for( Server serv : incomingServer )
|
for( Server serv : servers )
|
||||||
if( !types.contains(serv.type) ) types.add(serv.type);
|
if( !types.contains(serv.type) ) types.add(serv.type);
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a list of available outgoing server types
|
public List<ServerType> getAvailableIncomingServerTypes(){
|
||||||
|
return getAvailableServerTypes(incomingServer);
|
||||||
|
}
|
||||||
|
|
||||||
public List<ServerType> getAvailableOutgoingServerTypes(){
|
public List<ServerType> getAvailableOutgoingServerTypes(){
|
||||||
ArrayList<ServerType> types = new ArrayList<ServerType>();
|
return getAvailableServerTypes(outgoingServer);
|
||||||
// THERE IS ONLY SMTP FOR NOW
|
}
|
||||||
/*for( Server serv : outgoingServer )
|
|
||||||
if( !types.contains(serv.type) ) types.add(serv.type);*/
|
// returns a list of sockettypes available in the provided serverlist
|
||||||
if( outgoingServer.size() > 0 ) types.add(ServerType.SMTP);
|
public List<SocketType> getAvailableSocketTypes(List<? extends Server> servers){
|
||||||
|
ArrayList<SocketType> types = new ArrayList<SocketType>();
|
||||||
|
SocketType tmp;
|
||||||
|
|
||||||
|
for( int i=0; i<servers.size(); ++i){
|
||||||
|
tmp = servers.get(i).socketType;
|
||||||
|
if( !types.contains(tmp) )
|
||||||
|
types.add(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
// filters the list of servers according to the arguments ( list of allowed specifications )
|
// filters the list of servers according to the arguments ( list of allowed specifications )
|
||||||
private <T extends Server> List<T> getFilteredServerList
|
private <T extends Server> List<T> getFilteredServerList
|
||||||
(List<T> serverList, List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes)
|
(List<T> serverList, ServerType serverType, AuthenticationType authenticationType, SocketType socketType)
|
||||||
{
|
{
|
||||||
ArrayList<T> servers = new ArrayList<T>();
|
ArrayList<T> servers = new ArrayList<T>();
|
||||||
ArrayList<T> toBeRemoved = new ArrayList<T>();
|
ArrayList<T> toBeRemoved = new ArrayList<T>();
|
||||||
|
|
||||||
// filter for servertypes
|
// filter for servertypes
|
||||||
if( serverTypes != null && !serverTypes.isEmpty() )
|
if( serverType != null )
|
||||||
for( T serv : serverList )
|
for( T serv : serverList )
|
||||||
if( serverTypes.contains(serv.type))
|
if( serv.type == serverType)
|
||||||
servers.add(serv);
|
servers.add(serv);
|
||||||
|
|
||||||
// filter for autenticationtype
|
// filter for autenticationtype
|
||||||
if( authenticationTypes != null & !authenticationTypes.isEmpty() ){
|
if( authenticationType != null ){
|
||||||
for( T serv : servers )
|
for( T serv : servers )
|
||||||
if( !authenticationTypes.contains(serv.authentication) )
|
if( serv.authentication != authenticationType )
|
||||||
toBeRemoved.add(serv);
|
toBeRemoved.add(serv);
|
||||||
}
|
}
|
||||||
servers.removeAll(toBeRemoved);
|
servers.removeAll(toBeRemoved);
|
||||||
toBeRemoved.clear();
|
toBeRemoved.clear();
|
||||||
|
|
||||||
// filter for sockettype
|
// filter for sockettype
|
||||||
if( socketTypes != null & !socketTypes.isEmpty() )
|
if( socketType != null )
|
||||||
for( T serv : servers )
|
for( T serv : servers )
|
||||||
if( !socketTypes.contains(serv.socketType) )
|
if( serv.socketType != socketType )
|
||||||
toBeRemoved.add(serv);
|
toBeRemoved.add(serv);
|
||||||
servers.removeAll(toBeRemoved);
|
servers.removeAll(toBeRemoved);
|
||||||
|
|
||||||
return servers;
|
return servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public wrappers for the filter method
|
public List<IncomingServer> getIncomingServers
|
||||||
|
(ServerType serverType, AuthenticationType authenticationType, SocketType socketType){
|
||||||
|
return getFilteredServerList(incomingServer, serverType, authenticationType, socketType);
|
||||||
|
}
|
||||||
public List<OutgoingServer> getOutgoingServers
|
public List<OutgoingServer> getOutgoingServers
|
||||||
(List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
|
(ServerType serverType, AuthenticationType authenticationType, SocketType socketType){
|
||||||
return getFilteredServerList(outgoingServer, serverTypes, authenticationTypes, socketTypes);
|
return getFilteredServerList(outgoingServer, serverType, authenticationType, socketType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IncomingServer> getIncomingServers
|
|
||||||
(List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
|
|
||||||
return getFilteredServerList(incomingServer, serverTypes, authenticationTypes, socketTypes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
What's left of the parcelable interface
|
What's left of the parcelable interface
|
||||||
@ -520,3 +533,47 @@ public class AutoconfigInfo implements Parcelable {
|
|||||||
parcel.writeValue(documentation);
|
parcel.writeValue(documentation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* I wrote these first, but for now they are never used
|
||||||
|
|
||||||
|
private <T extends Server> List<T> getFilteredServerList
|
||||||
|
(List<T> serverList, List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes)
|
||||||
|
{
|
||||||
|
ArrayList<T> servers = new ArrayList<T>();
|
||||||
|
ArrayList<T> toBeRemoved = new ArrayList<T>();
|
||||||
|
|
||||||
|
// filter for servertypes
|
||||||
|
if( serverTypes != null && !serverTypes.isEmpty() )
|
||||||
|
for( T serv : serverList )
|
||||||
|
if( serverTypes.contains(serv.type))
|
||||||
|
servers.add(serv);
|
||||||
|
|
||||||
|
// filter for autenticationtype
|
||||||
|
if( authenticationTypes != null && !authenticationTypes.isEmpty() ){
|
||||||
|
for( T serv : servers )
|
||||||
|
if( !authenticationTypes.contains(serv.authentication) )
|
||||||
|
toBeRemoved.add(serv);
|
||||||
|
}
|
||||||
|
servers.removeAll(toBeRemoved);
|
||||||
|
toBeRemoved.clear();
|
||||||
|
|
||||||
|
// filter for sockettype
|
||||||
|
if( socketTypes != null && !socketTypes.isEmpty() )
|
||||||
|
for( T serv : servers )
|
||||||
|
if( !socketTypes.contains(serv.socketType) )
|
||||||
|
toBeRemoved.add(serv);
|
||||||
|
servers.removeAll(toBeRemoved);
|
||||||
|
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OutgoingServer> getOutgoingServers
|
||||||
|
(List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
|
||||||
|
return getFilteredServerList(outgoingServer, serverTypes, authenticationTypes, socketTypes);
|
||||||
|
}
|
||||||
|
public List<IncomingServer> getIncomingServers
|
||||||
|
(List<ServerType> serverTypes, List<AuthenticationType> authenticationTypes, List<SocketType> socketTypes){
|
||||||
|
return getFilteredServerList(incomingServer, serverTypes, authenticationTypes, socketTypes);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user