2727import net .sf .jniinchi .JniInchiException ;
2828import net .sf .jniinchi .JniInchiInput ;
2929
30- import java .text .DecimalFormat ;
3130import java .util .List ;
3231import java .util .StringTokenizer ;
3332
@@ -55,23 +54,11 @@ public JniInChIInputAdapter(List<INCHI_OPTION> options) throws JniInchiException
5554
5655 private static boolean isTimeoutOptions (String op ) {
5756 if (op == null || op .length () < 2 ) return false ;
58- int pos = 0 ;
59- int len = op .length ();
60- if (op .charAt (pos ) == 'W' )
61- pos ++;
62- while (pos < len && Character .isDigit (op .charAt (pos )))
63- pos ++;
64- if (pos < len && (op .charAt (pos ) == '.' || op .charAt (pos ) == ',' ))
65- pos ++;
66- while (pos < len && Character .isDigit (op .charAt (pos )))
67- pos ++;
68- return pos == len ;
69- }
57+ return op .charAt (0 ) == 'W' ;
7058
71- private static boolean isSubSecondTimeout (String op ) {
72- return op .indexOf ('.' ) >= 0 || op .indexOf (',' ) >= 0 ;
7359 }
7460
61+
7562 private static String checkOptions (final String ops ) throws JniInchiException {
7663 if (ops == null ) {
7764 throw new IllegalArgumentException ("Null options" );
@@ -96,18 +83,14 @@ private static String checkOptions(final String ops) throws JniInchiException {
9683 sbOptions .append (" " );
9784 }
9885 } else if (isTimeoutOptions (op )) {
99- // only reformat if we actually have a decimal
100- if (isSubSecondTimeout (op )) {
101- // because the JNI-InChI library is expecting an platform number, format it as such
102- Double time = Double .parseDouble (op .substring (1 ));
103- DecimalFormat format = new DecimalFormat ("#.##" );
104- sbOptions .append (FLAG_CHAR ).append ('W' ).append (format .format (time ));
105- } else {
106- sbOptions .append (FLAG_CHAR ).append (op );
107- }
108- hasUserSpecifiedTimeout = true ;
109- if (tok .hasMoreTokens ()) {
110- sbOptions .append (" " );
86+ final double time = Math .ceil (Double .parseDouble (op .substring (1 )));
87+ // fix #653: safer to use whole seconds, rounded to next bigger integer
88+ if (time >= 0.0 ) {
89+ sbOptions .append (FLAG_CHAR ).append (String .format ("W%.0f" , time ));
90+ hasUserSpecifiedTimeout = true ;
91+ if (tok .hasMoreTokens ()) {
92+ sbOptions .append (" " );
93+ }
11194 }
11295 }
11396 // 1,5 tautomer option
0 commit comments