Skip to content

Commit ac37156

Browse files
author
Allan Shoup
committed
Converted System.exit to throw exceptions, cleaned up leaked resources, removed unnecessary casts.
1 parent 3eb67fc commit ac37156

File tree

60 files changed

+267
-453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+267
-453
lines changed

src/main/java/org/scify/jedai/blockbuilding/AbstractBlockBuilding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public int getTotalNoOfEntities() {
107107
if (entityProfilesD2 == null) {
108108
return noOfEntitiesD1;
109109
}
110-
return noOfEntitiesD1 + noOfEntitiesD2;
110+
return Math.addExact(noOfEntitiesD1, noOfEntitiesD2);
111111
}
112112

113113
protected void indexEntities(Map<String, TIntList> index, List<EntityProfile> entities) {

src/main/java/org/scify/jedai/blockprocessing/AbstractBlockProcessing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ protected void printOriginalStatistics(List<AbstractBlock> inputBlocks) {
3636
}
3737

3838
Log.info("Original blocks\t:\t" + inputBlocks.size());
39-
Log.info("Original comparisons\t:\t" + ((long)comparisons));
39+
Log.info("Original comparisons\t:\t" + comparisons);
4040
}
4141
}

src/main/java/org/scify/jedai/blockprocessing/blockcleaning/BlockFiltering.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ protected void getBilateralLimits(List<AbstractBlock> blocks) {
105105
});
106106

107107
for (int i = 0; i < limitsD1.length; i++) {
108-
limitsD1[i] = (int) Math.round(ratio * limitsD1[i]);
108+
limitsD1[i] = Math.round(ratio * limitsD1[i]);
109109
}
110110
for (int i = 0; i < limitsD2.length; i++) {
111-
limitsD2[i] = (int) Math.round(ratio * limitsD2[i]);
111+
limitsD2[i] = Math.round(ratio * limitsD2[i]);
112112
}
113113
}
114114

@@ -193,7 +193,7 @@ protected void getUnilateralLimits(List<AbstractBlock> blocks) {
193193
});
194194

195195
for (int i = 0; i < limitsD1.length; i++) {
196-
limitsD1[i] = (int) Math.round(ratio * limitsD1[i]);
196+
limitsD1[i] = Math.round(ratio * limitsD1[i]);
197197
}
198198
}
199199

src/main/java/org/scify/jedai/blockprocessing/blockcleaning/SizeBasedBlockPurging.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private int getMaxBlockSize(List<AbstractBlock> blocks) {
6363
entities.addAll(uBlock.getEntities());
6464
});
6565

66-
return (int) Math.round(entities.size()*purgingFactor);
66+
return Math.round(entities.size()*purgingFactor);
6767
}
6868

6969
private int getMaxInnerBlockSize(List<AbstractBlock> blocks) {
@@ -76,7 +76,7 @@ private int getMaxInnerBlockSize(List<AbstractBlock> blocks) {
7676
d2Entities.addAll(bBlock.getIndex2Entities());
7777
});
7878

79-
return (int) Math.round(Math.min(d1Entities.size(), d2Entities.size())*purgingFactor);
79+
return Math.round(Math.min(d1Entities.size(), d2Entities.size())*purgingFactor);
8080
}
8181

8282
@Override

src/main/java/org/scify/jedai/blockprocessing/comparisoncleaning/CanopyClustering.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.scify.jedai.blockprocessing.comparisoncleaning;
1717

18-
import com.esotericsoftware.minlog.Log;
1918
import org.scify.jedai.datamodel.AbstractBlock;
2019
import org.scify.jedai.utilities.enumerations.WeightingScheme;
2120
import gnu.trove.iterator.TIntIterator;
@@ -56,8 +55,8 @@ public CanopyClustering(float inThr, float outThr, WeightingScheme scheme) {
5655
exclusiveThreshold = outThr;
5756
inclusiveThreshold = inThr;
5857
if (exclusiveThreshold < inclusiveThreshold) {
59-
Log.error(getMethodName(), "The " + getParameterName(1) + " cannot be smaller than the " + getParameterName(0));
60-
System.exit(-1);
58+
throw new IllegalStateException(
59+
"The " + getParameterName(1) + " cannot be smaller than the " + getParameterName(0));
6160
}
6261
}
6362

src/main/java/org/scify/jedai/blockprocessing/comparisoncleaning/ExtendedCanopyClustering.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.scify.jedai.blockprocessing.comparisoncleaning;
1717

18-
import com.esotericsoftware.minlog.Log;
1918
import org.scify.jedai.datamodel.AbstractBlock;
2019
import org.scify.jedai.datamodel.Comparison;
2120
import org.scify.jedai.utilities.enumerations.WeightingScheme;
@@ -60,8 +59,7 @@ public ExtendedCanopyClustering(int inThr, int outThr, WeightingScheme scheme) {
6059
exclusiveThreshold = outThr;
6160
inclusiveThreshold = inThr;
6261
if (inclusiveThreshold < exclusiveThreshold) {
63-
Log.error(getMethodName(), "The Exclusive Threshold cannot be larger than the Inclusive one.");
64-
System.exit(-1);
62+
throw new IllegalStateException("The Exclusive Threshold cannot be larger than the Inclusive one.");
6563
}
6664
}
6765

@@ -133,7 +131,7 @@ protected List<AbstractBlock> pruneEdges() {
133131

134132
excludedEntities = new TIntHashSet();
135133
nearestEntities = new HashSet[noOfEntities];
136-
topKEdges = new PriorityQueue<>((int) (2 * inclusiveThreshold), new IncComparisonWeightComparator());
134+
topKEdges = new PriorityQueue<>(2 * inclusiveThreshold, new IncComparisonWeightComparator());
137135
if (weightingScheme.equals(WeightingScheme.ARCS)) {
138136
while (iterator.hasNext()) {
139137
int currentId = iterator.next();

src/main/java/org/scify/jedai/configuration/randomsearch/AbstractRandomSearchConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public abstract class AbstractRandomSearchConfiguration implements IRandomSearch
2727

2828
protected final static Random RANDOM_GEN = new Random();
2929

30-
protected final List selectedRandomValues;
30+
protected final List<Object> selectedRandomValues;
3131

3232
public AbstractRandomSearchConfiguration() {
33-
selectedRandomValues = new ArrayList();
33+
selectedRandomValues = new ArrayList<>();
3434
}
3535

3636
@Override

src/main/java/org/scify/jedai/datamodel/Comparison.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public int getEntityId2() {
6565
/**
6666
* Returns the measure of the weight or similarity between two entities.
6767
* Higher utility measures correspond to greater weight or stronger similarity.
68-
* @return
6968
*/
7069
public float getUtilityMeasure() {
7170
return utilityMeasure;

src/main/java/org/scify/jedai/datamodel/GomoryHuTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public SimpleGraph<Integer, DefaultEdge> MinCutTree() {
9090

9191
final Set<V> sourcePartition = minSourceSinkCut.getSourcePartition();
9292
// float flowValue = minSourceSinkCut.getCutWeight();
93-
DefaultWeightedEdge e = (DefaultWeightedEdge) returnGraphClone.addEdge(vertex, predecessor);
93+
DefaultWeightedEdge e = returnGraphClone.addEdge(vertex, predecessor);
9494
returnGraph.addEdge(Integer.parseInt(vertex + ""), Integer.parseInt(predecessor + ""));
9595
returnGraphClone.setEdgeWeight(e, flowValue);
9696

src/main/java/org/scify/jedai/datamodel/SimilarityPairs.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
*/
1616
package org.scify.jedai.datamodel;
1717

18-
import com.esotericsoftware.minlog.Log;
1918
import java.io.Serializable;
20-
2119
import java.util.List;
2220
import org.scify.jedai.utilities.IConstants;
2321

@@ -64,10 +62,9 @@ private long countComparisons(List<AbstractBlock> blocks) {
6462
comparisons += block.getNoOfComparisons();
6563
}
6664

67-
if (MAX_COMPARISONS < comparisons) {
68-
Log.error("Very high number of comparisons to be executed! "
69-
+ "Maximum allowed number is : " + MAX_COMPARISONS);
70-
System.exit(-1);
65+
if (comparisons > MAX_COMPARISONS) {
66+
throw new IllegalStateException("Very high number of comparisons to be executed. "
67+
+ "Maximum allowed number is : " + MAX_COMPARISONS);
7168
}
7269
return comparisons;
7370
}

0 commit comments

Comments
 (0)