Skip to content

Commit

Permalink
Use ArrayList instead of arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mendhak committed Mar 2, 2024
1 parent f9fbc98 commit 548ccc4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.slf4j.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.Map;

import javax.net.ssl.X509TrustManager;
Expand All @@ -52,24 +53,16 @@ public class CustomUrlJob extends Job {
private UploadEvents.BaseUploadEvent callbackEvent;

private File csvFile;
private CustomUrlRequest[] urlRequests = new CustomUrlRequest[1];
private ArrayList<CustomUrlRequest> urlRequests;

public CustomUrlJob(CustomUrlRequest urlRequest, UploadEvents.BaseUploadEvent callbackEvent) {
super(new Params(1).requireNetwork().persist());

this.callbackEvent = callbackEvent;
this.urlRequests[0] = urlRequest;
}

public CustomUrlJob(CustomUrlRequest[] urlRequests, File csvFile, UploadEvents.BaseUploadEvent callbackEvent) {
public CustomUrlJob(ArrayList<CustomUrlRequest> urlRequests, File csvFile, UploadEvents.BaseUploadEvent callbackEvent) {
super(new Params(1).requireNetwork().persist());

this.callbackEvent = callbackEvent;
this.urlRequests = urlRequests;
this.csvFile = csvFile;
}


@Override
public void onAdded() {
}
Expand All @@ -80,7 +73,7 @@ public void onRun() throws Throwable {
boolean success = true;
Response errorResponse = null;

if(urlRequests != null && urlRequests.length > 0){
if(urlRequests != null && urlRequests.size() > 0){

for (CustomUrlRequest urlRequest : urlRequests) {
LOG.info("HTTP Request - " + urlRequest.getLogURL());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.FileReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -170,7 +171,7 @@ private void sendLocations(SerializableLocation[] locations, File csvFile){
JobManager jobManager = AppSettings.getJobManager();
jobManager.addJobInBackground(
new CustomUrlJob(
requests.toArray(new CustomUrlRequest[requests.size()]),
requests,
csvFile,
new UploadEvents.CustomUrl()));
}
Expand All @@ -179,8 +180,10 @@ private void sendLocations(SerializableLocation[] locations, File csvFile){

public void sendByHttp(String url, String method, String body, String headers, String username, String password){
JobManager jobManager = AppSettings.getJobManager();
jobManager.addJobInBackground(new CustomUrlJob(new CustomUrlRequest(url, method,
body, headers, username, password), new UploadEvents.CustomUrl()));
CustomUrlRequest request = new CustomUrlRequest(url, method,
body, headers, username, password);
ArrayList<CustomUrlRequest> requests = new ArrayList<>(Arrays.asList(request));
jobManager.addJobInBackground(new CustomUrlJob(requests, null, new UploadEvents.CustomUrl()));
}

private String getFormattedTextblock(String textToFormat, SerializableLocation loc) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ public void sendLocations(SerializableLocation[] locations){
}

void sendByHttp(String deviceId, String accountName, SerializableLocation[] locations, String communication, String path, String server, int port) {
ArrayList<CustomUrlRequest> requests = new ArrayList<>();
JobManager jobManager = AppSettings.getJobManager();

for(SerializableLocation loc:locations){
String finalUrl = getUrl(deviceId, accountName, loc, communication, path, server, port, batteryLevel );

JobManager jobManager = AppSettings.getJobManager();
jobManager.addJobInBackground(new CustomUrlJob(new CustomUrlRequest(finalUrl), new UploadEvents.OpenGTS()));
CustomUrlRequest request = new CustomUrlRequest(finalUrl);
requests.add(request);
}

jobManager.addJobInBackground(new CustomUrlJob(requests, null, new UploadEvents.OpenGTS()));
}


Expand Down

0 comments on commit 548ccc4

Please sign in to comment.