Skip to content

Commit

Permalink
review fix: introduce static instances of comparators to improve read…
Browse files Browse the repository at this point in the history
…ability/reuse (not sure this is that much better, but worth a shot)
  • Loading branch information
trautmane committed Dec 15, 2023
1 parent fca74b9 commit 294f9ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions render-app/src/main/java/org/janelia/alignment/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -411,4 +412,7 @@ public static URI convertPathOrUriStringToUri(final String pathOrUriString)
return uri;
}

public static final Comparator<String> NULLS_FIRST_STRING_COMPARATOR =
Comparator.nullsFirst(Comparator.naturalOrder());

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import jakarta.annotation.Nonnull;

import static org.janelia.alignment.match.MontageRelativePosition.LEFT;
import static org.janelia.alignment.match.MontageRelativePosition.TOP;
import static org.janelia.alignment.Utils.NULLS_FIRST_STRING_COMPARATOR;
import static org.janelia.alignment.match.MontageRelativePosition.*;

/**
* Key identifiers for a canvas.
Expand Down Expand Up @@ -170,8 +170,7 @@ public String toJson() {
public static final double[] ZERO_OFFSETS = { 0.0, 0.0 };

private static final Comparator<CanvasId> CANVAS_ID_COMPARATOR = Comparator
.comparing(CanvasId::getGroupId, Comparator.nullsFirst(Comparator.naturalOrder()))
.thenComparing(CanvasId::getId, Comparator.nullsFirst(Comparator.naturalOrder()))
.thenComparing(CanvasId::getRelativePosition, Comparator.nullsFirst(Comparator.naturalOrder()));

.comparing(CanvasId::getGroupId, NULLS_FIRST_STRING_COMPARATOR)
.thenComparing(CanvasId::getId, NULLS_FIRST_STRING_COMPARATOR)
.thenComparing(CanvasId::getRelativePosition, NULLS_FIRST_POSITION_COMPARATOR);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.janelia.alignment.match;

import java.util.Comparator;

import org.janelia.alignment.spec.Bounds;

/**
Expand Down Expand Up @@ -57,4 +59,6 @@ public MontageRelativePosition getOpposite() {
return opposite;
}

public static final Comparator<MontageRelativePosition> NULLS_FIRST_POSITION_COMPARATOR =
Comparator.nullsFirst(Comparator.naturalOrder());
}

0 comments on commit 294f9ce

Please sign in to comment.