@@ -28,11 +28,9 @@ public static ShrinkingDistance of(long... distances) {
2828
2929 @ API (status = MAINTAINED , since = "1.0" )
3030 public static <T > ShrinkingDistance forCollection (Collection <Shrinkable <T >> elements ) {
31- ShrinkingDistance sumDistanceOfElements = elements
32- .stream ()
33- .map (Shrinkable ::distance )
34- .reduce (ShrinkingDistance .MIN , ShrinkingDistance ::plus );
35-
31+ // This is an optimization to avoid creating temporary arrays, which the old streams-based implementation did.
32+ long [] collectedDistances = sumUp (toDistances (elements ));
33+ ShrinkingDistance sumDistanceOfElements = new ShrinkingDistance (collectedDistances );
3634 return ShrinkingDistance .of (elements .size ()).append (sumDistanceOfElements );
3735 }
3836
@@ -41,9 +39,9 @@ public static <T> ShrinkingDistance combine(List<Shrinkable<T>> shrinkables) {
4139 if (shrinkables .isEmpty ()) {
4240 throw new IllegalArgumentException ("At least one shrinkable is required" );
4341 }
44- // This is an optimization to avoid creating many temporary arrays, which the old streams-based implementation did.
45- List < long []> shrinkableDistances = toDistances ( shrinkables );
46- long [] combinedDistances = concatenate (shrinkableDistances );
42+
43+ // This is an optimization to avoid creating temporary arrays, which the old streams-based implementation did.
44+ long [] combinedDistances = concatenate (toDistances ( shrinkables ) );
4745 return new ShrinkingDistance (combinedDistances );
4846 }
4947
@@ -52,7 +50,7 @@ private ShrinkingDistance(long[] distances) {
5250 }
5351
5452 @ Override
55- public boolean equals (Object o ) {
53+ public boolean equals (@ Nullable Object o ) {
5654 if (this == o ) return true ;
5755 if (o == null || getClass () != o .getClass ()) return false ;
5856
@@ -109,7 +107,7 @@ private int compareDimension(ShrinkingDistance other, int i) {
109107
110108 @ API (status = INTERNAL )
111109 public ShrinkingDistance plus (ShrinkingDistance other ) {
112- long [] summedUpDistances = sumUp (distances , other .distances );
110+ long [] summedUpDistances = sumUp (Arrays . asList ( distances , other .distances ) );
113111 return new ShrinkingDistance (summedUpDistances );
114112 }
115113
@@ -120,7 +118,7 @@ public ShrinkingDistance append(ShrinkingDistance other) {
120118 }
121119
122120 @ NotNull
123- private static <T > List <long []> toDistances (List <Shrinkable <T >> shrinkables ) {
121+ private static <T > List <long []> toDistances (Collection <Shrinkable <T >> shrinkables ) {
124122 List <long []> listOfDistances = new ArrayList <>(shrinkables .size ());
125123 for (Shrinkable <?> tShrinkable : shrinkables ) {
126124 long [] longs = tShrinkable .distance ().distances ;
0 commit comments