Skip to content

Commit

Permalink
Merge pull request #22 from jamessimone/summer-24-updates
Browse files Browse the repository at this point in the history
Summer 24 updates
  • Loading branch information
ipavlic authored Jul 3, 2024
2 parents 3443e69 + b4740bc commit 3679dd9
Show file tree
Hide file tree
Showing 67 changed files with 270 additions and 277 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ salesforce.schema
.sfdx/
.sf/
IlluminatedCloud/*
.vscode
71 changes: 35 additions & 36 deletions force-app/main/default/classes/collection/DecimalCollection.cls
Original file line number Diff line number Diff line change
@@ -1,84 +1,83 @@
public class DecimalCollection {
private List<Decimal> decimals;
private List<Decimal> nonNulls;
private static final Decimal MAX_DECIMAL_VALUE {
get {
MAX_DECIMAL_VALUE = MAX_DECIMAL_VALUE ?? Math.pow(2, 63) - 1;
return MAX_DECIMAL_VALUE;
}
set;
}

private static final Decimal MIN_DECIMAL_VALUE {
get {
MIN_DECIMAL_VALUE = MIN_DECIMAL_VALUE ?? MAX_DECIMAL_VALUE * -1;
return MIN_DECIMAL_VALUE;
}
set;
}

private final List<Decimal> decimals;

public static DecimalCollection of(Iterable<Decimal> decimals) {
return new DecimalCollection(decimals);
}

private DecimalCollection(Iterable<Decimal> decimals) {
this.decimals = new List<Decimal>();
nonNulls = new List<Decimal>();
Iterator<Decimal> iter = decimals.iterator();
while (iter.hasNext()) {
Decimal d = iter.next();
for (Decimal d : decimals) {
this.decimals.add(d);
if (d != null) {
nonNulls.add(d);
}
}
}

public List<Decimal> asList() {
return new List<Decimal>(decimals);
return new List<Decimal>(this.decimals);
}

public Set<Decimal> asSet() {
return new Set<Decimal>(decimals);
return new Set<Decimal>(this.decimals);
}

public OptionalDecimal sum() {
if (nonNulls.isEmpty()) {
return OptionalDecimal.empty();
}
Decimal sum = 0;
for (Decimal d : nonNulls) {
sum += d;
Decimal sum;
for (Decimal d : this.decimals) {
if (d != null) {
sum = (sum ?? 0) + (d ?? 0);
}
}
return OptionalDecimal.of(sum);
}

public OptionalDecimal max() {
if (nonNulls.isEmpty()) {
return OptionalDecimal.empty();
}
Decimal max = nonNulls.get(0);
for (Integer i = 1; i < nonNulls.size(); i++) {
Decimal d = nonNulls[i];
if (d > max) {
Decimal max;
for (Decimal d : this.decimals) {
if ((d ?? MIN_DECIMAL_VALUE) > (max ?? MIN_DECIMAL_VALUE)) {
max = d;
}
}
return OptionalDecimal.of(max);
}

public OptionalDecimal min() {
if (nonNulls.isEmpty()) {
return OptionalDecimal.empty();
}
Decimal min = nonNulls.get(0);
for (Integer i = 1; i < nonNulls.size(); i++) {
Decimal d = nonNulls[i];
if (d < min) {
Decimal min ;
for (Decimal d : this.decimals) {
if ((d ?? MAX_DECIMAL_VALUE) < (min ?? MAX_DECIMAL_VALUE)) {
min = d;
}
}
return OptionalDecimal.of(min);
}

public OptionalDecimal average(Integer scale) {
OptionalDecimal s = sum();
return s.isPresent() ? OptionalDecimal.of(s.get().divide(nonNulls.size(), scale)) : OptionalDecimal.empty();
return this.average(scale, System.RoundingMode.HALF_EVEN);
}

public OptionalDecimal average(Integer scale, System.RoundingMode roundingMode) {
OptionalDecimal s = sum();
return s.isPresent() ? OptionalDecimal.of(s.get().divide(nonNulls.size(), scale, roundingMode)) : OptionalDecimal.empty();
OptionalDecimal s = this.sum();
return s.isPresent() ? OptionalDecimal.of(s.get().divide(this.decimals.size(), scale, roundingMode)) : s;
}

public DecimalCollection filter(DecimalPredicate predicate) {
List<Decimal> filtered = new List<Decimal>();
for (Decimal d : decimals) {
for (Decimal d : this.decimals) {
if (predicate.call(d)) {
filtered.add(d);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
68 changes: 34 additions & 34 deletions force-app/main/default/classes/collection/DoubleCollection.cls
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
public class DoubleCollection {
private List<Double> doubles;
private List<Double> nonNulls;
private static final Double MAX_DOUBLE_VALUE {
get {
MAX_DOUBLE_VALUE = MAX_DOUBLE_VALUE ?? Math.pow(2, 63) - 1;
return MAX_DOUBLE_VALUE;
}
set;
}

private static final Double MIN_DOUBLE_VALUE {
get {
MIN_DOUBLE_VALUE = MIN_DOUBLE_VALUE ?? MAX_DOUBLE_VALUE * -1;
return MIN_DOUBLE_VALUE;
}
set;
}

private final List<Double> doubles;

public static DoubleCollection of(Iterable<Double> doubles) {
return new DoubleCollection(doubles);
}

private DoubleCollection(Iterable<Double> doubles) {
this.doubles = new List<Double>();
nonNulls = new List<Double>();
Iterator<Double> iter = doubles.iterator();
while (iter.hasNext()) {
Double d = iter.next();
for (Double d : doubles) {
this.doubles.add(d);
if (d != null) {
nonNulls.add(d);
}
}
}

public List<Double> asList() {
return new List<Double>(doubles);
return new List<Double>(this.doubles);
}

public Set<Double> asSet() {
return new Set<Double>(doubles);
return new Set<Double>(this.doubles);
}

public OptionalDouble sum() {
if (nonNulls.isEmpty()) {
return OptionalDouble.empty();
}
Double sum = 0;
for (Double d : nonNulls) {
sum += d;
Double sum;
for (Double d : this.doubles) {
if (d != null) {
sum = (sum ?? 0) + (d ?? 0);
}
}
return OptionalDouble.of(sum);
}

public OptionalDouble max() {
if (nonNulls.isEmpty()) {
return OptionalDouble.empty();
}
Double max = nonNulls.get(0);
for (Integer i = 1; i < nonNulls.size(); i++) {
Double d = nonNulls[i];
if (d > max) {
Double max;
for (Double d : this.doubles) {
if ((d ?? MIN_DOUBLE_VALUE) > (max ?? MIN_DOUBLE_VALUE)) {
max = d;
}
}
return OptionalDouble.of(max);
}

public OptionalDouble min() {
if (nonNulls.isEmpty()) {
return OptionalDouble.empty();
}
Double min = nonNulls.get(0);
for (Integer i = 1; i < nonNulls.size(); i++) {
Double d = nonNulls[i];
if (d < min) {
Double min ;
for (Double d : this.doubles) {
if ((d ?? MAX_DOUBLE_VALUE) < (min ?? MAX_DOUBLE_VALUE)) {
min = d;
}
}
return OptionalDouble.of(min);
}

public OptionalDouble average() {
OptionalDouble s = sum();
return s.isPresent() ? OptionalDouble.of(s.get() / nonNulls.size()) : OptionalDouble.empty();
OptionalDouble s = this.sum();
return s.isPresent() ? OptionalDouble.of(s.get() / this.doubles.size()) : s;
}

public DoubleCollection filter(DoublePredicate predicate) {
List<Double> filtered = new List<Double>();
for (Double d : doubles) {
for (Double d : this.doubles) {
if (predicate.call(d)) {
filtered.add(d);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public with sharing class ObjectCollection {

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

public Set<Object> asSet(Type setType) {
Set<Object> typedObjects = (Set<Object>) setType.newInstance();
typedObjects.addAll(objects);
typedObjects.addAll(this.objects);
return typedObjects;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<apiVersion>61.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit 3679dd9

Please sign in to comment.