diff --git a/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/ClientInterfaceImplementation.java b/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/ClientInterfaceImplementation.java index ce272b6967..af51be94e3 100644 --- a/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/ClientInterfaceImplementation.java +++ b/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/ClientInterfaceImplementation.java @@ -1,17 +1,20 @@ package edu.berkeley.boinc.client; +import android.util.Log; + +import org.eclipse.collections.api.block.predicate.Predicate; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.list.MutableList; + import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; import java.util.List; -import android.util.Log; - import edu.berkeley.boinc.rpc.AccountIn; import edu.berkeley.boinc.rpc.AccountManager; import edu.berkeley.boinc.rpc.AccountOut; @@ -287,21 +290,6 @@ public class ClientInterfaceImplementation extends RpcClient { return auth; } - /** - * Sets cc_config.xml entries and triggers activation in BOINC client. - * Used to set debug log flags. - * - * @param ccConfig string of all cc_config flags - */ - public void setCcConfigAndActivate(String ccConfig) { - if (Logging.DEBUG) - Log.d(Logging.TAG, "Monitor.setCcConfig: current cc_config: " + getCcConfig()); - if (Logging.DEBUG) - Log.d(Logging.TAG, "Monitor.setCcConfig: setting new cc_config: " + ccConfig); - setCcConfig(ccConfig); - readCcConfig(); - } - /** * Runs transferOp for a list of given transfers. * E.g. batch pausing of transfers @@ -311,8 +299,8 @@ public class ClientInterfaceImplementation extends RpcClient { * @return success */ - public Boolean transferOperation(ArrayList transfers, int operation) { - Boolean success = true; + boolean transferOperation(List transfers, int operation) { + boolean success = true; for (Transfer transfer : transfers) { success = success && transferOp(operation, transfer.getProjectUrl(), transfer.getName()); if (Logging.DEBUG) Log.d(Logging.TAG, "transfer: " + transfer.getName() + " " + @@ -516,25 +504,22 @@ public class ClientInterfaceImplementation extends RpcClient { // less than desired number of messsages available, adapt lower bound if (lowerBound < 0) lowerBound = 0; - List msgs = getMessages(lowerBound); // returns ever messages with seqNo > lowerBound + + // returns every message with seqNo > lowerBound + MutableList messages = Lists.mutable.ofAll(getMessages(lowerBound)); if (seqNo > 0) { // remove messages that are >= seqNo - Iterator it = msgs.iterator(); - while (it.hasNext()) { - Message tmp = it.next(); - if (tmp.getSeqno() >= seqNo) - it.remove(); - } + messages.removeIf(message -> message.getSeqno() >= seqNo); } - if(!msgs.isEmpty() && Logging.DEBUG) { - Log.d(Logging.TAG, "getEventLogMessages: returning array with " + msgs.size() + if(!messages.isEmpty() && Logging.DEBUG) { + Log.d(Logging.TAG, "getEventLogMessages: returning array with " + messages.size() + " entries. for lowerBound: " + lowerBound + " at 0: " - + msgs.get(0).getSeqno() + " at " + (msgs.size() - 1) + ": " - + msgs.get(msgs.size() - 1).getSeqno()); + + messages.get(0).getSeqno() + " at " + (messages.size() - 1) + ": " + + messages.getLast().getSeqno()); } - return msgs; + return messages; } /** @@ -549,39 +534,24 @@ public class ClientInterfaceImplementation extends RpcClient { if (Logging.DEBUG) Log.d(Logging.TAG, "getAttachableProjects for platform: " + boincPlatformName + " or " + boincAltPlatformName); - List allProjectsList = getAllProjectsList(); // all_projects_list.xml - List attachedProjects = getState().getProjects(); // currently attached projects + // currently attached projects + final ImmutableList attachedProjects = Lists.immutable.ofAll(getState().getProjects()); - List attachableProjects = new ArrayList<>(); // array to be filled and returned + // filter out projects that are already attached + final ImmutableList filteredProjectsList = getAllProjectsList() // all_projects_list.xml + .select(candidate -> attachedProjects + .noneSatisfy(attachedProject -> + attachedProject.getMasterURL().equals(candidate.getUrl()))); - if (allProjectsList == null) - return Collections.emptyList(); - - //filter projects that do not support Android - for (ProjectInfo candidate : allProjectsList) { - // check whether already attached - boolean alreadyAttached = false; - for (Project attachedProject : attachedProjects) { - if (attachedProject.getMasterURL().equals(candidate.getUrl())) { - alreadyAttached = true; - break; - } - } - if (alreadyAttached) - continue; - - // project is not yet attached, check whether it supports CPU architecture - for (String supportedPlatform : candidate.getPlatforms()) { - if (supportedPlatform.contains(boincPlatformName) || - (!boincAltPlatformName.isEmpty() && supportedPlatform.contains(boincAltPlatformName))) { - // project is not yet attached and does support platform - // add to list, if not already in it - if (!attachableProjects.contains(candidate)) - attachableProjects.add(candidate); - break; - } - } - } + final Predicate supportedPlatformPredicate = supportedPlatform -> supportedPlatform.contains(boincPlatformName) || + (!boincAltPlatformName.isEmpty() + && supportedPlatform.contains(boincAltPlatformName)); + final List attachableProjects = filteredProjectsList + //filter out projects that do not support Android + .select(candidate -> Lists.immutable.ofAll(candidate.getPlatforms()) + // project is not yet attached, check whether it supports CPU architecture + .anySatisfy(supportedPlatformPredicate)) + .distinct().toList(); if (Logging.DEBUG) Log.d(Logging.TAG, "getAttachableProjects: number of candidates found: " @@ -604,14 +574,13 @@ public class ClientInterfaceImplementation extends RpcClient { } ProjectInfo getProjectInfo(String url) { - List allProjectsList = getAllProjectsList(); // all_projects_list.xml - for (ProjectInfo tmp : allProjectsList) { - if (tmp.getUrl().equals(url)) - return tmp; - } - if (Logging.ERROR) + // all_projects_list.xml + ProjectInfo projectInfo = getAllProjectsList().detect(tmp -> tmp.getUrl().equals(url)); + + if (projectInfo == null && Logging.ERROR) Log.e(Logging.TAG, "getProjectInfo: could not find info for: " + url); - return null; + + return projectInfo; } boolean setDomainName(String deviceName) { diff --git a/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/Monitor.java b/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/Monitor.java index 2002439e6e..e5550ad20e 100644 --- a/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/Monitor.java +++ b/android/BOINC/app/src/main/java/edu/berkeley/boinc/client/Monitor.java @@ -1036,7 +1036,7 @@ public class Monitor extends Service { @Override public boolean transferOperation(List list, int op) throws RemoteException { - return clientInterface.transferOperation((ArrayList) list, op); + return clientInterface.transferOperation(list, op); } @Override diff --git a/android/BOINC/app/src/main/java/edu/berkeley/boinc/rpc/RpcClient.java b/android/BOINC/app/src/main/java/edu/berkeley/boinc/rpc/RpcClient.java index 44a65d65b1..f5b9ef7194 100644 --- a/android/BOINC/app/src/main/java/edu/berkeley/boinc/rpc/RpcClient.java +++ b/android/BOINC/app/src/main/java/edu/berkeley/boinc/rpc/RpcClient.java @@ -25,6 +25,8 @@ import android.util.Log; import android.util.Xml; import org.apache.commons.lang3.StringUtils; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.list.ImmutableList; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -968,17 +970,17 @@ public class RpcClient { } } - protected synchronized List getAllProjectsList() { + protected synchronized ImmutableList getAllProjectsList() { try { mRequest.setLength(0); mRequest.append(""); sendRequest(mRequest.toString()); - return ProjectInfoParser.parse(receiveReply()); + return Lists.immutable.ofAll(ProjectInfoParser.parse(receiveReply())); } catch (IOException e) { if (Logging.WARNING) Log.w(Logging.TAG, "error in getAllProjectsList()", e); - return Collections.emptyList(); + return Lists.immutable.empty(); } }