Skip to content

Commit

Permalink
Replace LinkedList with ArrayList
Browse files Browse the repository at this point in the history
  • Loading branch information
Pc authored and Pc committed Jul 31, 2023
1 parent 13c23c1 commit c47bc18
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CacheRecord {
boolean executionStatus;
long executionDuration;

Map<String,LinkedList<CacheRecord>> maintenanceData;
Map<String,List<CacheRecord>> maintenanceData;


// This is to create a new Cache Record when cache is not present.
Expand Down Expand Up @@ -91,20 +91,20 @@ public void setExecutionDuration(long executionDuration) {

public void insertMaintenanceData(CacheRecord record){
if(record != null && maintenanceData != null) {
LinkedList<CacheRecord> list = maintenanceData.get(record.getMaintenanceType());
List<CacheRecord> list = maintenanceData.get(record.getMaintenanceType());
if(list != null) {
list.addFirst(record);
list.add(0,record);
// Maximum storage of 5 Maintenance Records per Cache.
if (list.size() > 5)
list.removeLast();
list.remove(list.size()-1);
}
}
}

public List<CacheRecord> getAllMaintenanceRecordsForSingleCache(){
List<CacheRecord> maintenanceData = new ArrayList<>();

for(Map.Entry<String,LinkedList<CacheRecord>> entry : this.maintenanceData.entrySet()){
for(Map.Entry<String,List<CacheRecord>> entry : this.maintenanceData.entrySet()){
maintenanceData.addAll(entry.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package jenkins.plugins.git.maintenance.Logs;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.*;

public class RecordList {
LinkedList<CacheRecord> maintenanceRecords;
List<CacheRecord> maintenanceRecords;
Set<String> cacheSet;

public RecordList(){
maintenanceRecords = new LinkedList<>();
maintenanceRecords = new ArrayList<>();
cacheSet = new HashSet<>();
}

List<CacheRecord> getMaintenanceRecords(){
return new LinkedList<>(maintenanceRecords);
return new ArrayList<>(maintenanceRecords);
}

void addRecord(CacheRecord cacheRecord){
Expand Down Expand Up @@ -54,7 +50,7 @@ record = itr.next();
}

// Creates a new Cache Entry and adds the data.
maintenanceRecords.addFirst(cacheRecord);
maintenanceRecords.add(0,cacheRecord);
cacheSet.add(repoName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testInsertMaintenanceData(){
record.insertMaintenanceData(incrementalRepackRecord);
record.insertMaintenanceData(looseObjectsRecord);

for(Map.Entry<String, LinkedList<CacheRecord>> entry : record.maintenanceData.entrySet()){
for(Map.Entry<String, List<CacheRecord>> entry : record.maintenanceData.entrySet()){
assertEquals(1,entry.getValue().size());
}
}
Expand Down

0 comments on commit c47bc18

Please sign in to comment.