Skip to content

Commit c7ea4c1

Browse files
committed
Final polish: fix autoboxing, final fields, null-safe getters, lineSeparator
- BondChange: make bondChangeDelta final, remove setter, inline computation - MCSSolution: null-safe getters (return 0/0.0 instead of null) - AtomContainerComparatorBy2DCenter: Double.compare() instead of autoboxing - MinSelection: fix Double.valueOf(int) == double comparison - BondEnergies: diamond operator - TestUtility: make DEBUG field final - Replace System.getProperty("line.separator") with System.lineSeparator() across 7 files All 135 tests pass. Author: Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
1 parent d78ac0f commit c7ea4c1

12 files changed

Lines changed: 24 additions & 36 deletions

File tree

src/main/java/com/bioinceptionlabs/reactionblast/graphics/direct/AtomContainerComparatorBy2DCenter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public int compare(IAtomContainer atCont1, IAtomContainer atCont2) {
4747
Point2d p2 = get2DCenter(atCont2);
4848
if (p1 != null && p2 != null) {
4949
if (p1.x != p2.x) {
50-
return Double.valueOf(p1.x).compareTo(p2.x);
50+
return Double.compare(p1.x, p2.x);
5151
} else {
52-
return Double.valueOf(p1.y).compareTo(p2.y);
52+
return Double.compare(p1.y, p2.y);
5353
}
5454
}
5555
}

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/checks/MinSelection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public boolean isSubAndCompleteMatchFlag() {
186186
}
187187

188188
private boolean isMCSSubgraph(IAtomContainer educt, double mcsSize) throws CDKException {
189-
return Double.valueOf(educt.getAtomCount()) == mcsSize;
189+
return educt.getAtomCount() == (int) mcsSize;
190190
}
191191

192192
/**

src/main/java/com/bioinceptionlabs/reactionblast/mapping/graph/MCSSolution.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public MCSSolution(int queryPosition, int targetPosition,
6060
}
6161

6262
/**
63-
* @return the stereoScore
63+
* @return the stereoScore, or 0 if null
6464
*/
6565
public Integer getStereoScore() {
66-
return stereoScore;
66+
return stereoScore != null ? stereoScore : 0;
6767
}
6868

6969
/**
@@ -74,10 +74,10 @@ public void setStereoScore(Integer stereoScore) {
7474
}
7575

7676
/**
77-
* @return the fragmentSize
77+
* @return the fragmentSize, or 0 if null
7878
*/
7979
public Integer getFragmentSize() {
80-
return fragmentSize;
80+
return fragmentSize != null ? fragmentSize : 0;
8181
}
8282

8383
/**
@@ -88,10 +88,10 @@ public void setFragmentSize(Integer fragmentSize) {
8888
}
8989

9090
/**
91-
* @return the energy
91+
* @return the energy, or 0.0 if null
9292
*/
9393
public Double getEnergy() {
94-
return energy;
94+
return energy != null ? energy : 0.0;
9595
}
9696

9797
/**

src/main/java/com/bioinceptionlabs/reactionblast/mechanism/BondChangeCalculator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
*/
9090
public class BondChangeCalculator extends AbstractChangeCalculator implements IChangeCalculator {
9191

92-
private static final String NEW_LINE = System.getProperty("line.separator");
92+
private static final String NEW_LINE = System.lineSeparator();
9393
private static final long serialVersionUID = 98698690880809981L;
9494
private final static ILoggingTool LOGGER
9595
= createLoggingTool(BondChangeCalculator.class);

src/main/java/com/bioinceptionlabs/reactionblast/mechanism/MappingSolution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class MappingSolution implements Serializable {
3333

34-
private static final String NEW_LINE = System.getProperty("line.separator");
34+
private static final String NEW_LINE = System.lineSeparator();
3535
private static final long serialVersionUID = 1678787866L;
3636

3737
private final IMappingAlgorithm algorithmID;

src/main/java/com/bioinceptionlabs/reactionblast/mechanism/RMatrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*/
4747
public final class RMatrix extends EBIMatrix implements Serializable {
4848

49-
private static final String NEW_LINE = System.getProperty("line.separator");
49+
private static final String NEW_LINE = System.lineSeparator();
5050
private static final long serialVersionUID = 7057060562283378684L;
5151
private static final ILoggingTool LOGGER = createLoggingTool(RMatrix.class);
5252

src/main/java/com/bioinceptionlabs/reactionblast/mechanism/helper/AtomAtomMappingContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AtomAtomMappingContainer extends Object implements Serializable {
4444
private static final ILoggingTool LOGGER
4545
= LoggingToolFactory.createLoggingTool(AtomAtomMappingContainer.class);
4646

47-
private static final String NEW_LINE = System.getProperty("line.separator");
47+
private static final String NEW_LINE = System.lineSeparator();
4848
private static final long serialVersionUID = 17879096958755L;
4949

5050
private List<IAtom> reactantAtomArray = new ArrayList<>();

src/main/java/com/bioinceptionlabs/reactionblast/mechanism/helper/BondChange.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.bioinceptionlabs.reactionblast.mechanism.helper;
2020

2121
import java.io.Serializable;
22-
import static java.lang.System.getProperty;
2322

2423
import org.openscience.cdk.interfaces.IBond;
2524

@@ -30,7 +29,7 @@
3029
*/
3130
public class BondChange implements Serializable {
3231

33-
private static final String NEW_LINE = System.getProperty("line.separator");
32+
private static final String NEW_LINE = System.lineSeparator();
3433
private static final long serialVersionUID = 9890766688070991L;
3534

3635
/**
@@ -94,28 +93,24 @@ public static int convertBondStereo(IBond bond) {
9493

9594
private final IBond reactantBond;
9695
private final IBond productBond;
97-
private float bondChangeDelta;
96+
private final float bondChangeDelta;
9897

9998
/**
10099
*
101100
* @param reactantBond
102101
* @param productBond
103102
*/
104103
public BondChange(IBond reactantBond, IBond productBond) {
105-
this.bondChangeDelta = 0;
106104
this.reactantBond = reactantBond;
107105
this.productBond = productBond;
108106
if (this.reactantBond != null && this.productBond != null) {
109-
float change = convertBondOrder(this.productBond) - convertBondOrder(this.reactantBond);
110-
if (change != 0) {
111-
setBondChangeInformation(change);
112-
} else if (change == 0) {
113-
setBondChangeInformation(0);
114-
}
107+
this.bondChangeDelta = convertBondOrder(this.productBond) - convertBondOrder(this.reactantBond);
115108
} else if (this.reactantBond == null && this.productBond != null) {
116-
setBondChangeInformation(convertBondOrder(this.productBond));
109+
this.bondChangeDelta = convertBondOrder(this.productBond);
117110
} else if (this.reactantBond != null && this.productBond == null) {
118-
setBondChangeInformation(convertBondOrder(this.reactantBond));
111+
this.bondChangeDelta = convertBondOrder(this.reactantBond);
112+
} else {
113+
this.bondChangeDelta = 0;
119114
}
120115
}
121116

@@ -140,13 +135,6 @@ public float getBondChangeDelta() {
140135
return bondChangeDelta;
141136
}
142137

143-
/**
144-
* @param bondChangeDelta the bondChangeDelta to set
145-
*/
146-
private void setBondChangeInformation(float bondChangeInformation) {
147-
this.bondChangeDelta = bondChangeInformation;
148-
}
149-
150138
@Override
151139
public String toString() {
152140
StringBuilder result = new StringBuilder();

src/main/java/com/bioinceptionlabs/reactionblast/tools/TestUtility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class TestUtility {
5555
public static final String MACIE_RXN = "rxn/macie/";
5656
private final static ILoggingTool LOGGER
5757
= createLoggingTool(TestUtility.class);
58-
private static boolean DEBUG = false;
58+
private static final boolean DEBUG = false;
5959

6060
/**
6161
*

src/main/java/com/bioinceptionlabs/reactionblast/tools/rxnfile/MDLV2000Reader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
*/
123123
public class MDLV2000Reader extends DefaultChemObjectReader {
124124

125-
private static final String NEW_LINE = System.getProperty("line.separator");
125+
private static final String NEW_LINE = System.lineSeparator();
126126
BufferedReader input = null;
127127
private static ILoggingTool LOGGER = LoggingToolFactory.createLoggingTool(MDLV2000Reader.class);
128128

0 commit comments

Comments
 (0)