Skip to content

Commit

Permalink
Restore ObjectCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlic committed Sep 28, 2023
1 parent 9972115 commit 459dc66
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
27 changes: 27 additions & 0 deletions force-app/main/default/classes/collection/ObjectCollection.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public with sharing class ObjectCollection {
private List<Object> objects;

public static ObjectCollection of(Iterable<Object> objects) {
return new ObjectCOllection(objects);
}

private ObjectCollection(Iterable<Object> objects) {
this.objects = new List<Object>();
Iterator<Object> iter = objects.iterator();
while (iter.hasNext()) {
this.objects.add(iter.next());
}
}

public List<Object> asList(Type listType) {
List<Object> typedObjects = (List<Object>) listType.newInstance();
typedObjects.addAll(objects);
return typedObjects;
}

public Set<Object> asSet(Type setType) {
Set<Object> typedObjects = (Set<Object>) setType.newInstance();
typedObjects.addAll(objects);
return typedObjects;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public with sharing class SObjectCollection {
for (SObject record : records) {
mapped.add(fn.call(record));
}
return new ObjectCollection(mapped);
return ObjectCollection.of(mapped);
}

public SObjectCollection mapSome(SObjectPredicate predicate, SObjectToSObjectFunction fn) {
Expand Down

0 comments on commit 459dc66

Please sign in to comment.