22
33import com .novoda .sqlite .StringUtil ;
44
5+ import java .util .Locale ;
6+
57public final class Column {
68 private final String name ;
79 private final String type ;
8- private boolean nullable ;
9- private DataAffinity affinity ;
10+ private final boolean nullable ;
11+ private final DataAffinity affinity ;
1012
1113 public Column (String name , String type , boolean nullable ) {
1214 this .name = name ;
1315 this .type = type ;
1416 this .nullable = nullable ;
15- this .affinity = computeAffinity (type );
17+ this .affinity = DataAffinity . fromType (type );
1618 }
1719
1820 public String getName () {
@@ -25,9 +27,10 @@ public String getCamelizedName() {
2527
2628 public String getCamelizedSmallName () {
2729 String camel = StringUtil .camelify (name );
28- if (camel .length () <= 1 )
29- return camel ;
30- return camel .substring (0 ,1 ).toLowerCase ()+camel .substring (1 );
30+ if (camel .length () <= 1 ) {
31+ return "_" + camel ;
32+ }
33+ return "_" + camel .substring (0 , 1 ).toLowerCase (Locale .US ) + camel .substring (1 );
3134 }
3235
3336 public String getType () {
@@ -43,32 +46,8 @@ public DataAffinity getAffinity() {
4346 }
4447
4548 public boolean isBoolean () {
46- return affinity == DataAffinity .NUMERIC && type .toLowerCase ().contains ("bool" );
47- }
48-
49- /*
50- * See http://www.sqlite.org/datatype3.html
51- * section 2.1 Determination of column affinity
52- */
53- private DataAffinity computeAffinity (String type ) {
54- String deftype = type .toLowerCase ();
55- if (deftype .contains ("int" ))
56- return DataAffinity .INTEGER ;
57- if (containsOneOf (deftype , "char" , "clob" , "text" ))
58- return DataAffinity .TEXT ;
59- if (containsOneOf (deftype , "real" , "floa" , "doub" ))
60- return DataAffinity .REAL ;
61- if (containsOneOf (deftype , "blob" ) || deftype .equals ("" ))
62- return DataAffinity .NONE ;
63- return DataAffinity .NUMERIC ;
49+ return affinity == DataAffinity .NUMERIC && type .toLowerCase (Locale .US ).contains ("bool" );
6450 }
6551
66- private boolean containsOneOf (String toCheck , String ... values ) {
67- for (String value : values ) {
68- if (toCheck .contains (value ))
69- return true ;
70- }
71- return false ;
72- }
7352
7453}
0 commit comments