database design - How to implement reference data Java/DB -


i've got table factors need incorporate java program. @ first thinking of hardcoding number seems pain trying create data structure fit factors. wanted ask around , see if better implement reference data in database, flat file or in java. number change every 6 months , used mathematical computations.

thoughts?

factor list

you have create data structure contain data regardless of how store them. data structure kind of data not have complex. list of values attributes. don't have store them in complex table-like structure.

loading data flat text file quite easy when representing data single list.

public class datatable {      private list<entry> table = new arraylist<entry>();      public double getvalue(sex sex, maritalstatus maritalstatus, ageinterval ageinterval, type type) {         (entry entry : table) {             if (entry.sex == sex && entry.maritalstatus == maritalstatus && entry.ageinterval == ageinterval && entry.type == type) {                 return entry.value;             }         }         throw new illegalargumentexception("unknown value");     }      public void load(string filename) {         try {             bufferedreader reader = new bufferedreader(new inputstreamreader(new fileinputstream(filename)));             string line;             while ((line = reader.readline()) != null) {                 stringtokenizer t = new stringtokenizer(line, ":");                 table.add(new entry(                         sex.valueof(t.nexttoken()),                         maritalstatus.valueof(t.nexttoken()),                         ageinterval.valueof(t.nexttoken()),                         type.valueof(t.nexttoken()),                         double.valueof(t.nexttoken())));             }         } catch (ioexception e) {             throw new illegalstateexception("failed read data file", e);         }     }  }  enum sex {m, f} enum maritalstatus {single, married} enum ageinterval {i16_21, i22_35, i35_55, i55} enum type {gd, ngd} // whatever ...  class entry {     sex sex;     maritalstatus maritalstatus;     ageinterval ageinterval;     type type;     double value;      entry(sex sex, maritalstatus maritalstatus, ageinterval ageinterval, type type, double value) {         this.sex = sex;         this.maritalstatus = maritalstatus;         this.ageinterval = ageinterval;         this.type = type;         this.value = value;     } } 

the data file this:

m:single:i16_21:gd:1.10 f:single:i16_21:gd:1.20 ... 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -