QuantitationTypeParameterGuesser { protected static PrimitiveType guessPrimitiveType( String name, String description, Object exampleValue ) { String exampleString = null; boolean couldBeDouble = true; boolean couldBeInt = true; if ( exampleValue != null ) { if ( exampleValue instanceof Double ) { return PrimitiveType.DOUBLE; } else if ( exampleValue instanceof Integer ) { return PrimitiveType.INT; } else if ( exampleValue instanceof Boolean ) { return PrimitiveType.BOOLEAN; } else if ( exampleValue instanceof String ) { exampleString = ( String ) exampleValue; } if ( StringUtils.isNotBlank( exampleString ) && !exampleString.equalsIgnoreCase( "null" ) ) { try { Double.parseDouble( exampleString ); } catch ( NumberFormatException e ) { couldBeDouble = false; } try { Integer.parseInt( exampleString ); } catch ( NumberFormatException e ) { couldBeInt = false; } } } for ( PrimitiveType type : QuantitationTypeParameterGuesser.representationDescPatterns.keySet() ) { PrimitiveType guessed; guessed = QuantitationTypeParameterGuesser.checkType( type, name, couldBeDouble, couldBeInt ); if ( guessed != null ) return guessed; guessed = QuantitationTypeParameterGuesser.checkType( type, description, couldBeDouble, couldBeInt ); if ( guessed != null ) return guessed; } if ( !couldBeDouble ) return PrimitiveType.STRING; return PrimitiveType.DOUBLE; }  static void guessQuantitationTypeParameters( QuantitationType qt, String name, String description ); static void guessQuantitationTypeParameters( QuantitationType qt, String name, String description,
            Object exampleValue );  }
@Test public void testPixels() { String a = "B Pixels"; String b = "number of background pixels"; PrimitiveType s = QuantitationTypeParameterGuesser.guessPrimitiveType( a.toLowerCase(), b.toLowerCase(), null ); assertEquals( "got " + s, PrimitiveType.INT, s ); }
@Test public void testPrimitiveType() { String a = "VALUE"; String b = "green_processed_Signal; the signal left after all the Feature extraction processing steps have been completed (e.g. background substraction)"; PrimitiveType s = QuantitationTypeParameterGuesser.guessPrimitiveType( a.toLowerCase(), b.toLowerCase(), 1.0 ); assertEquals( "got " + s, PrimitiveType.DOUBLE, s ); }
@Test public void testPrimitiveTypeDoubleWrong() { String a = "VALUE"; String b = "green_processed_Signal; the signal left after all the Feature extraction processing steps have been completed (e.g. background substraction)"; PrimitiveType s = QuantitationTypeParameterGuesser.guessPrimitiveType( a.toLowerCase(), b.toLowerCase(), "a" ); assertFalse( "got " + s, PrimitiveType.DOUBLE.equals( s ) ); }
@Test public void testPrimitiveTypeInteger() { String a = "B Pixels"; String b = "number of background pixels"; PrimitiveType s = QuantitationTypeParameterGuesser .guessPrimitiveType( a.toLowerCase(), b.toLowerCase(), 12232 ); assertTrue( "got " + s, s.equals( PrimitiveType.INT ) ); }
@Test public void testPrimitiveTypeIntegerWrong() { String a = "B Pixels"; String b = "number of background pixels"; PrimitiveType s = QuantitationTypeParameterGuesser .guessPrimitiveType( a.toLowerCase(), b.toLowerCase(), 12232.00 ); assertTrue( "got " + s, s.equals( PrimitiveType.DOUBLE ) ); }
@Test public void testBadRatio() { String a = "VALUE"; String b = "Log2 ratio (CH_1 Median-CH1_B/CH2_Median-CH2_B)"; PrimitiveType s = QuantitationTypeParameterGuesser .guessPrimitiveType( a.toLowerCase(), b.toLowerCase(), "null" ); assertEquals( "got " + s, PrimitiveType.DOUBLE, s ); }