CSV import

3 views
Skip to first unread message

sm_zl_kimi

unread,
Mar 29, 2008, 3:23:33 PM3/29/08
to cropplann...@googlegroups.com
I write five function in CSV.
 
//read csv file and return ArrayList<CPSPlanting>
//flow: call importRecord() to open csv file.read the head line which contains the column name.
//call propNumFromPropName() to get the propNum and save it in a arraylist.
//call setCropsAndVarieties() to set values to a CPSCrop object.
//save the CPSCrop object into a arraylist and read the next line
//return arraylist which contains CPSCrops.
public ArrayList<CPSCrop> importCropsAndVarieties( String fileName )
 
//same as importCropsAndVarieties
public ArrayList<CPSPlanting> importCropPlan( String fileName ) 
 
//open read csv file.
private String[] importRecord(CSV csv,CsvReader reader,ArrayList<Integer> propNumArray,int recordType) throws IOException
 
//set the value of CPSCrop object by INDEX
private void setCropsAndVarieties(CPSCrop crop,final int INDEX,String value)
 
private void setPlanting(CPSPlanting plant,final int INDEX,String value)
 
I also build a column map,map column name into INDEX,just like the HSQLColumnMap in CPS-HSQL
 
way to use(example):
          CSV csv = new CSV();
          ArrayList<CPSCrop> crops = csv.importCropsAndVarieties("ExportedCropsAndVars.csv");
          ArrayList<CPSPlanting> plants = csv.importCropPlan("ExportedCropPlan - tomorrow.csv");
CSV.java
CSVColumnMap.java

sm_zl_kimi

unread,
Mar 30, 2008, 4:05:28 AM3/30/08
to cropplann...@googlegroups.com
any comments?

2008/3/30, sm_zl_kimi <smzl...@gmail.com>:

Clayton Carter

unread,
Mar 30, 2008, 7:11:01 AM3/30/08
to cropplann...@googlegroups.com
First glance, it looks good. I'll need a few days before I can get
some time to pull it into Netbeans and mesh it w/ the rest of the code
(add an import menu, etc). Otherwise, AWESOME! So quick...

Clayton


On Sun, Mar 30, 2008 at 4:05 AM, sm_zl_kimi <smzl...@gmail.com> wrote:
> any comments?
>

sm_zl_kimi

unread,
Mar 30, 2008, 7:45:35 AM3/30/08
to cropplann...@googlegroups.com
thanks,but I feel not well about  "setCropsAndVarieties" "setPlanting"
 


 
2008/3/30, Clayton Carter <croppl...@gmail.com>:

Clayton Carter

unread,
Mar 30, 2008, 8:25:15 PM3/30/08
to cropplann...@googlegroups.com
Yes, well, that's not exactly what I had in mind either, but I didn't
want to complain about someone who had just volunteered free, working
code. :) Is there anything about it in particular you would like to
improve? Or is there any particular feedback or critique you'd like
from me?

Let me do some looking into the code in CPSRecord. The documentation
is horrible (my fault), but I believe that there's a mechanism by
which we can explicitly set a property w/ just a value and the
property number. As I recall, though, that would bypass any special
processing that is done by all of the setXXX() methods. (Although --
off the top of my head, again -- I can't remember if any of the setXXX
methods do any special processing.)

I do appreciate the code, though!

Clayton

sm_zl_kimi

unread,
Mar 31, 2008, 2:36:30 AM3/31/08
to cropplann...@googlegroups.com
I am not that familiar with this project so the two 'setxxx' functions
looked ugly. after you rewrite these,I will check out and see.or
you can give me some advice about how to rewrite.
2008/3/31, Clayton Carter <croppl...@gmail.com>:

Clayton Carter

unread,
Mar 31, 2008, 10:12:42 PM3/31/08
to cropplann...@googlegroups.com
OK, I double checked some code just now:

CPSPlanting and CPSCrop both inherit from CPSRecord, which defines two methods:

public <T> void set( int prop, T value ) { set( prop, value, false ); }
public <T> void set( int prop, T value, boolean force ) { set(
getDatum( prop ), value, force ); }

You could use these methods to skip the calls to the setXXX methods
which you created and think are ugly.

For instance, instead of this:

setCropsAndVarieties(crop,propNumArray.get(i),reader.getValues()[i]);

you could do this:

crop.set( propNumArray.get(i), reader.getValues()[i] );

How's that?

Clayton

sm_zl_kimi

unread,
Apr 1, 2008, 3:58:57 AM4/1/08
to cropplann...@googlegroups.com
oh,I don't know we had that function. if only I knew : )
I will send you the patch thursday. cause I have a little work to do today.

2008/4/1, Clayton Carter <croppl...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages