Skip to content

Commit

Permalink
ADDED: Support for fixedMode on FixedLengthRecord
Browse files Browse the repository at this point in the history
ADDED: Sample for using fixedMode=FixedMode.AllowLessChars
FIXED: Method openResource() on FileHelperEngine was closing the resource, resulting on an exception at runtime
Reverted changes on RecordInfo and FileHelperEngine

git-svn-id: https://jfilehelpers.svn.sourceforge.net/svnroot/jfilehelpers@30 e6aea695-393b-0410-bcd1-a96c4ba3c4be
  • Loading branch information
fcoury committed Jun 18, 2008
1 parent 93b7fe6 commit a7663f8
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 339 deletions.
4 changes: 4 additions & 0 deletions .settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,4 @@
#Tue Jun 17 21:37:05 BRT 2008
eclipse.preferences.version=1
org.eclipse.jdt.ui.javadoc=false
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * \r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Felipe Coury &lt;felipe.coury@gmail.com&gt; - ${date}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*\r\n * ${file_name}\r\n *\r\n * Copyright (C) 2007 Felipe Gon\u00E7alves Coury &lt;felipe.coury@gmail.com&gt;\r\n * \r\n * This program is free software; you can redistribute it and/or\r\n * modify it under the terms of the GNU General Public License\r\n * as published by the Free Software Foundation; either version 2\r\n * of the License, or (at your option) any later version.\r\n * \r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU General Public License for more details.\r\n * \r\n * You should have received a copy of the GNU General Public License\r\n * along with this program; if not, write to the Free Software\r\n * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r\n */\r\n${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
5 changes: 5 additions & 0 deletions Resources/samples/tracks-fixed.txt
@@ -0,0 +1,5 @@
01Laura Pausini La Solitudine La Solitudine Pop Arista 1990
02Laura Pausini La Solitudine Se Fue Pop Arista 1990
03Laura Pausini La Solitudine La Gente Pop Arista 1990
04Dixie Chicks Fly Cowboy Take Me Away Pop Arista 03
05Dixie Chicks Fly Cold Day in July Pop Arista 03
@@ -0,0 +1,55 @@
/*
* Customer.java
*
* Copyright (C) 2007 Felipe Gon�alves Coury <felipe.coury@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package org.coury.jfilehelpers.samples.delimited.open;

import java.util.Date;

import org.coury.jfilehelpers.annotations.DelimitedRecord;
import org.coury.jfilehelpers.annotations.FieldConverter;
import org.coury.jfilehelpers.enums.ConverterKind;
import org.coury.jfilehelpers.helpers.StringHelper;

@DelimitedRecord(",")
public class Customer {
private Integer custId;
private String name;
private Integer rating;

@FieldConverter(converter = ConverterKind.Date, format = "dd-MM-yyyy")
private Date addedDate;

public String getName() {
return name;
}


@Override
public String toString() {
String l = System.getProperty("line.separator");
StringBuffer b = new StringBuffer();
b.append("Customer: ").append(l);
b.append(" custId = " + custId).append(l);
b.append(" name = " + name).append(l);
b.append(" rating = " + rating).append(l);
b.append(" addedDate = " + addedDate).append(l);
return StringHelper.toStringBuilder(this, b.toString());
}
}
@@ -0,0 +1,49 @@
/*
* TestDelimited.java
*
* Copyright (C) 2007 Felipe Gon�alves Coury <felipe.coury@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

package org.coury.jfilehelpers.samples.delimited.open;

import java.io.IOException;

import org.coury.jfilehelpers.engines.FileHelperEngine;

public class TestDelimitedIterator {
public static void main(String[] args) throws IOException {
FileHelperEngine<Customer> engine = new FileHelperEngine<Customer>(
Customer.class);

if (args.length < 1) {
engine.openResource("/samples/customers-delimited.txt");
} else {
engine.openFile(args[0]);
}

int count = 0;
for (Customer c : engine) {
if ("Felipe Coury".equals(c.getName())) {
count++;
}

}

engine.close();
System.out.println(count);
}
}
@@ -0,0 +1,44 @@
/*
* TestFixed.java
*
* Copyright (C) 2007 Felipe Gonçalves Coury <felipe.coury@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.coury.jfilehelpers.samples.fixed.lesschars;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.coury.jfilehelpers.engines.FileHelperEngine;

public class TestFixed {
public static void main(String[] args) throws IOException {
FileHelperEngine<Track> engine = new FileHelperEngine<Track>(Track.class);
List<Track> tracks = new ArrayList<Track>();

if (args.length < 1) {
tracks = engine.readResource("/samples/tracks-fixed.txt");
}
else {
tracks = engine.readFile(args[0]);
}

for (Track t : tracks) {
System.out.println(t);
}
}
}
@@ -0,0 +1,31 @@
package org.coury.jfilehelpers.samples.fixed.lesschars;

import org.coury.jfilehelpers.annotations.FieldFixedLength;
import org.coury.jfilehelpers.annotations.FixedLengthRecord;
import org.coury.jfilehelpers.enums.FixedMode;
import org.coury.jfilehelpers.helpers.StringHelper;

@FixedLengthRecord(fixedMode=FixedMode.AllowLessChars)
public class Track {
@FieldFixedLength(2) public int number;
@FieldFixedLength(15) public String performer;
@FieldFixedLength(15) public String album;
@FieldFixedLength(20) public String music;
@FieldFixedLength(10) public String genre;
@FieldFixedLength(15) public String label;
@FieldFixedLength(4) public int year;

@Override
public String toString() {
String l = System.getProperty("line.separator");
StringBuffer b = new StringBuffer();
b.append("Track #").append(number).append("): ").append(l);
b.append(" performer = ").append(performer).append(l);
b.append(" album = ").append(album).append(l);
b.append(" music = ").append(music).append(l);
b.append(" genre = ").append(genre).append(l);
b.append(" label = ").append(label).append(l);
b.append(" year = ").append(year).append(l);
return StringHelper.toStringBuilder(this, b.toString());
}
}
Expand Up @@ -25,7 +25,10 @@
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;


import org.coury.jfilehelpers.enums.FixedMode;

@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface FixedLengthRecord { public @interface FixedLengthRecord {
FixedMode fixedMode() default FixedMode.ExactLength;
} }
2 changes: 1 addition & 1 deletion Source/src/org/coury/jfilehelpers/core/RecordInfo.java
Expand Up @@ -182,7 +182,7 @@ public Object run() {
* @throws IllegalArgumentException * @throws IllegalArgumentException
* @throws IllegalAccessException * @throws IllegalAccessException
*/ */
public String recordToStr(Object record) throws IllegalArgumentException, IllegalAccessException { public String recordToStr(T record) throws IllegalArgumentException, IllegalAccessException {
StringBuffer sb = new StringBuffer(this.sizeHint); StringBuffer sb = new StringBuffer(this.sizeHint);


Object[] values = new Object[fieldCount]; Object[] values = new Object[fieldCount];
Expand Down

0 comments on commit a7663f8

Please sign in to comment.