Skip to content

Commit 9bbae7a

Browse files
johnmayegonw
authored andcommitted
Replace usage of Guava Ints utility. Integer.compare helps as well as IntStream
1 parent 90d3209 commit 9bbae7a

File tree

8 files changed

+34
-23
lines changed

8 files changed

+34
-23
lines changed

base/core/src/main/java/org/openscience/cdk/graph/InitialCycles.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.google.common.collect.HashBiMap;
2828
import com.google.common.collect.Multimap;
2929
import com.google.common.collect.TreeMultimap;
30-
import com.google.common.primitives.Ints;
3130

3231
import java.util.BitSet;
3332
import java.util.Collection;
@@ -542,7 +541,14 @@ int length() {
542541

543542
@Override
544543
public int compareTo(Cycle that) {
545-
return Ints.lexicographicalComparator().compare(this.path, that.path);
544+
int len = Math.min(this.path.length, that.path.length);
545+
for (int i = 0; i < len; i++) {
546+
int result = Integer.compare(this.path[i], that.path[i]);
547+
if (result != 0) {
548+
return result;
549+
}
550+
}
551+
return this.path.length - that.path.length;
546552
}
547553
}
548554

base/isomorphism/src/main/java/org/openscience/cdk/isomorphism/AtomMapFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import com.google.common.collect.ArrayListMultimap;
2727
import com.google.common.collect.Multimap;
28-
import com.google.common.primitives.Ints;
2928
import org.openscience.cdk.CDKConstants;
3029
import org.openscience.cdk.ReactionRole;
3130
import org.openscience.cdk.interfaces.IAtom;
@@ -98,8 +97,8 @@ final class AtomMapFilter implements Predicate<int[]> {
9897

9998
if (reactInvMap != null && prodInvMap != null) {
10099
for (Map.Entry<Integer, Collection<Integer>> e : reactInvMap.asMap().entrySet()) {
101-
int[] reacMaps = Ints.toArray(e.getValue());
102-
int[] prodMaps = Ints.toArray(prodInvMap.get(e.getKey()));
100+
int[] reacMaps = e.getValue().stream().mapToInt(i->i).toArray();
101+
int[] prodMaps = prodInvMap.get(e.getKey()).stream().mapToInt(i->i).toArray();
103102
if (prodMaps.length == 0)
104103
continue; // unpaired
105104
mapped.add(new MappedPairs(reacMaps, prodMaps));

base/standard/src/main/java/org/openscience/cdk/graph/invariant/MorganNumbersTools.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
*/
2020
package org.openscience.cdk.graph.invariant;
2121

22-
import com.google.common.primitives.Ints;
2322
import org.openscience.cdk.interfaces.IAtomContainer;
2423
import org.openscience.cdk.interfaces.IBond;
2524

25+
import java.util.Arrays;
26+
2627
/**
2728
* Compute the extended connectivity values (Morgan Numbers) {@cdk.cite MOR65}.
2829
* The tool does not produce the lexicographic smallest labelling on the graph
@@ -75,8 +76,8 @@ public static long[] getMorganNumbers(IAtomContainer molecule) {
7576
for (IBond bond : molecule.bonds()) {
7677
int u = molecule.indexOf(bond.getBegin());
7778
int v = molecule.indexOf(bond.getEnd());
78-
graph[u] = Ints.ensureCapacity(graph[u], degree[u] + 1, INITIAL_DEGREE);
79-
graph[v] = Ints.ensureCapacity(graph[v], degree[v] + 1, INITIAL_DEGREE);
79+
graph[u] = ensureCapacity(graph[u], degree[u] + 1);
80+
graph[v] = ensureCapacity(graph[v], degree[v] + 1);
8081
graph[u][degree[u]++] = v;
8182
graph[v][degree[v]++] = u;
8283
currentInvariants[u] += nonHydrogens[v];
@@ -101,6 +102,10 @@ public static long[] getMorganNumbers(IAtomContainer molecule) {
101102
return currentInvariants;
102103
}
103104

105+
private static int[] ensureCapacity(int[] arr, int cap) {
106+
return cap < arr.length ? arr : Arrays.copyOf(arr, cap);
107+
}
108+
104109
/**
105110
* Makes an array containing the morgan numbers+element symbol of the atoms
106111
* of {@code atomContainer}. This method puts the element symbol before the

display/renderbasic/src/main/java/org/openscience/cdk/renderer/generators/standard/StandardBondGenerator.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
package org.openscience.cdk.renderer.generators.standard;
2727

28-
import com.google.common.primitives.Ints;
2928
import org.openscience.cdk.config.Elements;
30-
import org.openscience.cdk.geometry.GeometryUtil;
3129
import org.openscience.cdk.graph.Cycles;
3230
import org.openscience.cdk.interfaces.IAtom;
3331
import org.openscience.cdk.interfaces.IAtomContainer;
@@ -1724,12 +1722,12 @@ public int compare(IAtomContainer ringa, IAtomContainer ringb) {
17241722
}
17251723

17261724
// order by size 6,5,7,4,3,rest
1727-
int sizeCmp = Ints.compare(sizePreference(ringa.getAtomCount()),
1725+
int sizeCmp = Integer.compare(sizePreference(ringa.getAtomCount()),
17281726
sizePreference(ringb.getAtomCount()));
17291727
if (sizeCmp != 0) return sizeCmp;
17301728

17311729
// now order by number of double bonds
1732-
int piBondCmp = Ints.compare(nDoubleBonds(ringa), nDoubleBonds(ringb));
1730+
int piBondCmp = Integer.compare(nDoubleBonds(ringa), nDoubleBonds(ringb));
17331731
if (piBondCmp != 0) return -piBondCmp;
17341732

17351733
// order by element frequencies, all carbon rings are preferred
@@ -1738,7 +1736,7 @@ public int compare(IAtomContainer ringa, IAtomContainer ringb) {
17381736

17391737
for (Elements element : Arrays.asList(Elements.Carbon, Elements.Nitrogen, Elements.Oxygen, Elements.Sulfur,
17401738
Elements.Phosphorus)) {
1741-
int elemCmp = Ints.compare(freqA[element.number()], freqB[element.number()]);
1739+
int elemCmp = Integer.compare(freqA[element.number()], freqB[element.number()]);
17421740
if (elemCmp != 0) return -elemCmp;
17431741
}
17441742

legacy/src/main/java/org/openscience/cdk/smiles/smarts/SMARTSQueryTool.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.openscience.cdk.smiles.smarts;
2020

2121
import com.google.common.collect.FluentIterable;
22-
import com.google.common.primitives.Ints;
2322
import org.openscience.cdk.aromaticity.Aromaticity;
2423
import org.openscience.cdk.aromaticity.ElectronDonation;
2524
import org.openscience.cdk.exception.CDKException;
@@ -49,6 +48,8 @@
4948
import java.util.Objects;
5049
import java.util.Set;
5150
import java.util.TreeSet;
51+
import java.util.stream.Collectors;
52+
import java.util.stream.IntStream;
5253

5354

5455
/**
@@ -383,6 +384,10 @@ public int countMatches() {
383384
return mappings.size();
384385
}
385386

387+
private static List<Integer> toList(int[] values) {
388+
return IntStream.of(values).boxed().collect(Collectors.toList());
389+
}
390+
386391
/**
387392
* Get the atoms in the target molecule that match the query pattern. Since there may be multiple matches, the
388393
* return value is a List of List objects. Each List object contains the indices of the atoms in the target
@@ -393,7 +398,7 @@ public int countMatches() {
393398
public List<List<Integer>> getMatchingAtoms() {
394399
List<List<Integer>> matched = new ArrayList<List<Integer>>(mappings.size());
395400
for (int[] mapping : mappings)
396-
matched.add(Ints.asList(mapping));
401+
matched.add(toList(mapping));
397402
return matched;
398403
}
399404

@@ -411,7 +416,8 @@ public List<List<Integer>> getUniqueMatchingAtoms() {
411416
BitSet atomSet = new BitSet();
412417
for (int x : mapping)
413418
atomSet.set(x);
414-
if (atomSets.add(atomSet)) matched.add(Ints.asList(mapping));
419+
if (atomSets.add(atomSet))
420+
matched.add(toList(mapping));
415421
}
416422
return matched;
417423
}

legacy/src/main/java/org/openscience/cdk/smiles/smarts/SmartsAtomAtomMapFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import com.google.common.collect.ArrayListMultimap;
2727
import com.google.common.collect.Multimap;
28-
import com.google.common.primitives.Ints;
2928
import org.openscience.cdk.CDKConstants;
3029
import org.openscience.cdk.ReactionRole;
3130
import org.openscience.cdk.interfaces.IAtom;
@@ -99,8 +98,8 @@ final class SmartsAtomAtomMapFilter implements Predicate<int[]> {
9998

10099
if (reactInvMap != null && prodInvMap != null) {
101100
for (Map.Entry<Integer, Collection<Integer>> e : reactInvMap.asMap().entrySet()) {
102-
int[] reacMaps = Ints.toArray(e.getValue());
103-
int[] prodMaps = Ints.toArray(prodInvMap.get(e.getKey()));
101+
int[] reacMaps = e.getValue().stream().mapToInt(i->i).toArray();
102+
int[] prodMaps = prodInvMap.get(e.getKey()).stream().mapToInt(i->i).toArray();
104103
if (prodMaps.length == 0)
105104
continue; // unpaired
106105
mapped.add(new MappedPairs(reacMaps, prodMaps));

storage/smiles/src/test/java/org/openscience/cdk/smiles/SmilesParserTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.Set;
2828

2929
import com.google.common.collect.FluentIterable;
30-
import com.google.common.primitives.Ints;
3130
import org.junit.Assert;
3231
import org.junit.Assume;
3332
import org.junit.Ignore;
@@ -2226,7 +2225,7 @@ public void testNeighboringChirality() throws Exception {
22262225

22272226
@Override
22282227
public int compare(IStereoElement o1, IStereoElement o2) {
2229-
return Ints.compare(mol.indexOf(((ITetrahedralChirality) o1).getChiralAtom()),
2228+
return Integer.compare(mol.indexOf(((ITetrahedralChirality) o1).getChiralAtom()),
22302229
mol.indexOf(((ITetrahedralChirality) o2).getChiralAtom()));
22312230
}
22322231
});

tool/sdg/src/main/java/org/openscience/cdk/layout/NonplanarBonds.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
package org.openscience.cdk.layout;
2626

27-
import com.google.common.primitives.Ints;
2827
import org.openscience.cdk.BondRef;
2928
import org.openscience.cdk.CDKConstants;
3029
import org.openscience.cdk.geometry.GeometryUtil;
@@ -177,7 +176,7 @@ else if (element instanceof IDoubleBondStereochemistry) {
177176

178177
@Override
179178
public int compare(Integer i, Integer j) {
180-
return -Ints.compare(nAdjacentCentres(i), nAdjacentCentres(j));
179+
return -Integer.compare(nAdjacentCentres(i), nAdjacentCentres(j));
181180
}
182181
});
183182

0 commit comments

Comments
 (0)