Author: doogie
Date: Sun Jun 29 11:47:15 2008 New Revision: 672660 URL: http://svn.apache.org/viewvc?rev=672660&view=rev Log: Generics, enhanced-for, Number.valueOf. Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile.java ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile2EntityXml.java ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFile.java ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelRecord.java ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile.java Sun Jun 29 11:47:15 2008 @@ -44,7 +44,7 @@ public static final String module = DataFile.class.getName(); /** List of record in the file, contains Record objects */ - protected List records = new ArrayList(); + protected List<Record> records = new ArrayList<Record>(); /** Contains the definition for the file */ protected ModelDataFile modelDataFile; @@ -98,7 +98,7 @@ return modelDataFile; } - public List getRecords() { + public List<Record> getRecords() { return records; } @@ -221,9 +221,8 @@ writeRecords(outStream, this.records); } - protected void writeRecords(OutputStream outStream, List records) throws DataFileException { - for (int r = 0; r < records.size(); r++) { - Record record = (Record) records.get(r); + protected void writeRecords(OutputStream outStream, List<Record> records) throws DataFileException { + for (Record record: records) { String line = record.writeLineString(modelDataFile); try { Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile2EntityXml.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile2EntityXml.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile2EntityXml.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/DataFile2EntityXml.java Sun Jun 29 11:47:15 2008 @@ -50,13 +50,10 @@ outFile.newLine(); outFile.write("<entity-engine-xml>"); outFile.newLine(); - List records = dataFile.getRecords(); - for(int r=0; r<records.size(); r++) { - Record record = (Record)records.get(r); + for (Record record: dataFile.getRecords()) { ModelRecord modelRecord = record.getModelRecord(); outFile.write("<" + modelRecord.name + " "); - for (int f=0;f<modelRecord.fields.size(); f++) { - ModelField modelField = (ModelField)modelRecord.fields.get(f); + for (ModelField modelField: modelRecord.fields) { if (modelField.ignored) continue; Object value = record.get(modelField.name); if (value == null) { @@ -115,13 +112,10 @@ } // ----------------------------------------- - List records = dataFile.getRecords(); - for(int r=0; r<records.size(); r++) { - Record record = (Record)records.get(r); + for (Record record: dataFile.getRecords()) { ModelRecord modelRecord = record.getModelRecord(); outFile.write("<" + modelRecord.name + " "); - for (int f=0;f<modelRecord.fields.size(); f++) { - ModelField modelField = (ModelField)modelRecord.fields.get(f); + for (ModelField modelField: modelRecord.fields) { Object value = record.get(modelField.name); if (value instanceof String) { value = ((String)value).trim(); Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFile.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFile.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFile.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFile.java Sun Jun 29 11:47:15 2008 @@ -57,11 +57,10 @@ public String description = ""; /** List of record definitions for the file */ - public List records = new ArrayList(); + public List<ModelRecord> records = new ArrayList<ModelRecord>(); public ModelRecord getModelRecord(String recordName) { - for (int i = 0; i < records.size(); i++) { - ModelRecord curRecord = (ModelRecord) records.get(i); + for (ModelRecord curRecord: records) { if (curRecord.name.equals(recordName)) { return curRecord; @@ -134,11 +133,11 @@ this.description = description; } - public List getRecords() { + public List<ModelRecord> getRecords() { return records; } - public void setRecords(List records) { + public void setRecords(List<ModelRecord> records) { this.records = records; } } Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelDataFileReader.java Sun Jun 29 11:47:15 2008 @@ -47,19 +47,19 @@ public static final String module = ModelDataFileReader.class.getName(); - public static UtilCache readers = new UtilCache("ModelDataFile", 0, 0); + public static UtilCache<URL, ModelDataFileReader> readers = new UtilCache<URL, ModelDataFileReader>("ModelDataFile", 0, 0); public URL readerURL = null; - public Map modelDataFiles = null; + public Map<String, ModelDataFile> modelDataFiles = null; public static ModelDataFileReader getModelDataFileReader(URL readerURL) { ModelDataFileReader reader = null; - reader = (ModelDataFileReader) readers.get(readerURL); + reader = readers.get(readerURL); if (reader == null) { // don't want to block here synchronized (ModelDataFileReader.class) { // must check if null again as one of the blocked threads can still enter - reader = (ModelDataFileReader) readers.get(readerURL); + reader = readers.get(readerURL); if (reader == null) { if (Debug.infoOn()) Debug.logInfo("[ModelDataFileReader.getModelDataFileReader] : creating reader.", module); reader = new ModelDataFileReader(readerURL); @@ -82,12 +82,12 @@ getModelDataFiles(); } - public Map getModelDataFiles() { + public Map<String, ModelDataFile> getModelDataFiles() { if (modelDataFiles == null) { // don't want to block here synchronized (ModelDataFileReader.class) { // must check if null again as one of the blocked threads can still enter if (modelDataFiles == null) { // now it's safe - modelDataFiles = new HashMap(); + modelDataFiles = new HashMap<String, ModelDataFile>(); UtilTimer utilTimer = new UtilTimer(); @@ -153,10 +153,10 @@ * @return An DataFile object describing the specified dataFile of the specified descriptor file. */ public ModelDataFile getModelDataFile(String dataFileName) { - Map ec = getModelDataFiles(); + Map<String, ModelDataFile> ec = getModelDataFiles(); if (ec != null) { - return (ModelDataFile) ec.get(dataFileName); + return ec.get(dataFileName); } else { return null; } @@ -165,8 +165,8 @@ /** Creates a Iterator with the dataFileName of each DataFile defined in the specified XML DataFile Descriptor file. * @return A Iterator of dataFileName Strings */ - public Iterator getDataFileNamesIterator() { - Collection collection = getDataFileNames(); + public Iterator<String> getDataFileNamesIterator() { + Collection<String> collection = getDataFileNames(); if (collection != null) { return collection.iterator(); @@ -178,8 +178,8 @@ /** Creates a Collection with the dataFileName of each DataFile defined in the specified XML DataFile Descriptor file. * @return A Collection of dataFileName Strings */ - public Collection getDataFileNames() { - Map ec = getModelDataFiles(); + public Collection<String> getDataFileNames() { + Map<String, ModelDataFile> ec = getModelDataFiles(); return ec.keySet(); } @@ -218,8 +218,7 @@ } } - for (int i = 0; i < dataFile.records.size(); i++) { - ModelRecord modelRecord = (ModelRecord) dataFile.records.get(i); + for (ModelRecord modelRecord: dataFile.records) { if (modelRecord.parentName.length() > 0) { ModelRecord parentRecord = dataFile.getModelRecord(modelRecord.parentName); @@ -250,7 +249,7 @@ tempStr = UtilXml.checkEmpty(recordElement.getAttribute("tc-isnum")); if (tempStr != null && tempStr.length() > 0) { - record.tcIsNum = Boolean.valueOf(tempStr).booleanValue(); + record.tcIsNum = Boolean.parseBoolean(tempStr); } tempStr = UtilXml.checkEmpty(recordElement.getAttribute("tc-position")); @@ -313,17 +312,17 @@ tempStr = UtilXml.checkEmpty(fieldElement.getAttribute("prim-key")); if (tempStr != null && tempStr.length() > 0) { - field.isPk = Boolean.valueOf(tempStr).booleanValue(); + field.isPk = Boolean.parseBoolean(tempStr); } tempStr = UtilXml.checkEmpty(fieldElement.getAttribute("ignored")); if (tempStr != null && tempStr.length() > 0) { - field.ignored = Boolean.valueOf(tempStr).booleanValue(); + field.ignored = Boolean.parseBoolean(tempStr); } tempStr = UtilXml.checkEmpty(fieldElement.getAttribute("expression")); if (tempStr != null && tempStr.length() > 0) { - field.expression = Boolean.valueOf(tempStr).booleanValue(); + field.expression = Boolean.parseBoolean(tempStr); } return field; Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelRecord.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelRecord.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelRecord.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/ModelRecord.java Sun Jun 29 11:47:15 2008 @@ -65,14 +65,13 @@ public String limit = ""; public ModelRecord parentRecord = null; - public List childRecords = new ArrayList(); + public List<ModelRecord> childRecords = new ArrayList<ModelRecord>(); /** List of the fields that compose this record */ - public List fields = new ArrayList(); + public List<ModelField> fields = new ArrayList<ModelField>(); ModelField getModelField(String fieldName) { - for (int i = 0; i < fields.size(); i++) { - ModelField curField = (ModelField) fields.get(i); + for (ModelField curField: fields) { if (curField.name.equals(fieldName)) { return curField; @@ -105,11 +104,11 @@ this.parentName = parentName; } - public List getFields() { + public List<ModelField> getFields() { return fields; } - public void setFields(List fields) { + public void setFields(List<ModelField> fields) { this.fields = fields; } } Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java Sun Jun 29 11:47:15 2008 @@ -36,7 +36,7 @@ public class Record implements Serializable { /** Contains a map with field data by name */ - protected Map fields; + protected Map<String, Object> fields; /** Contains the name of the record definition */ protected String recordName; @@ -45,7 +45,7 @@ protected transient ModelRecord modelRecord; protected Record parentRecord = null; - protected List childRecords = new ArrayList(); + protected List<Record> childRecords = new ArrayList<Record>(); /** Creates new Record */ protected Record(ModelRecord modelRecord) { @@ -53,16 +53,16 @@ throw new IllegalArgumentException("Cannont create a Record with a null modelRecord parameter"); this.recordName = modelRecord.name; this.modelRecord = modelRecord; - this.fields = new HashMap(); + this.fields = new HashMap<String, Object>(); } /** Creates new Record from existing Map */ - protected Record(ModelRecord modelRecord, Map fields) { + protected Record(ModelRecord modelRecord, Map<String, Object> fields) { if (modelRecord == null) throw new IllegalArgumentException("Cannont create a Record with a null modelRecord parameter"); this.recordName = modelRecord.name; this.modelRecord = modelRecord; - this.fields = (fields == null ? new HashMap() : new HashMap(fields)); + this.fields = (fields == null ? new HashMap<String, Object>() : new HashMap<String, Object>(fields)); } public String getRecordName() { @@ -259,7 +259,7 @@ double divisor = Math.pow(10.0, decimalPlaces); number = number / divisor; - set(name, new Double(number)); + set(name, Double.valueOf(number)); } // standard types else if (fieldType.equals("java.lang.String") || fieldType.equals("String")) set(name, value); @@ -281,11 +281,11 @@ else if (fieldType.equals("java.lang.Double") || fieldType.equals("Double")) set(name, Double.valueOf(value)); else if (fieldType.equals("LEShort")) - set(name, new Short(readLEShort(value.getBytes()))); + set(name, Short.valueOf(readLEShort(value.getBytes()))); else if (fieldType.equals("LEInteger")) - set(name, new Integer(readLEInt(value.getBytes()))); + set(name, Integer.valueOf(readLEInt(value.getBytes()))); else if (fieldType.equals("LELong")) - set(name, new Long(readLELong(value.getBytes()))); + set(name, Long.valueOf(readLELong(value.getBytes()))); else { throw new IllegalArgumentException("Field type " + fieldType + " not currently supported. Sorry."); } @@ -380,8 +380,7 @@ StringBuilder lineBuf = new StringBuilder(); - for (int f = 0; f < modelRecord.fields.size(); f++) { - ModelField modelField = (ModelField) modelRecord.fields.get(f); + for (ModelField modelField: modelRecord.fields) { String data = this.getFixedString(modelField.name); // if field is null (not set) then assume we want to pad the field @@ -444,7 +443,7 @@ return parentRecord; } - public List getChildRecords() { + public List<Record> getChildRecords() { return childRecords; } @@ -469,7 +468,7 @@ * @throws DataFileException Exception thown for various errors, generally has a nested exception * @return */ - public static Record createRecord(ModelRecord modelRecord, Map fields) throws DataFileException { + public static Record createRecord(ModelRecord modelRecord, Map<String, Object> fields) throws DataFileException { Record record = new Record(modelRecord, fields); return record; @@ -485,8 +484,7 @@ public static Record createRecord(String line, int lineNum, ModelRecord modelRecord) throws DataFileException { Record record = new Record(modelRecord); - for (int i = 0; i < modelRecord.fields.size(); i++) { - ModelField modelField = (ModelField) modelRecord.fields.get(i); + for (ModelField modelField: modelRecord.fields) { String strVal = null; @@ -528,8 +526,7 @@ else { st = new StringTokenizer(line, "" + delimiter, true); } - for (int i = 0; i < modelRecord.fields.size(); i++) { - ModelField modelField = (ModelField) modelRecord.fields.get(i); + for (ModelField modelField: modelRecord.fields) { String strVal = null; if (modelField.expression) { Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java?rev=672660&r1=672659&r2=672660&view=diff ============================================================================== --- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java (original) +++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/RecordIterator.java Sun Jun 29 11:47:15 2008 @@ -163,7 +163,7 @@ // if this record has children, put it on the parentStack and get/check the children now if (this.curRecord.getModelRecord().childRecords.size() > 0) { - Stack parentStack = new Stack(); + Stack<Record> parentStack = new Stack<Record>(); parentStack.push(curRecord); while (this.nextRecord != null && this.nextRecord.getModelRecord().parentRecord != null) { @@ -171,7 +171,7 @@ Record parentRecord = null; while (parentStack.size() > 0) { - parentRecord = (Record) parentStack.peek(); + parentRecord = parentStack.peek(); if (parentRecord.recordName.equals(this.nextRecord.getModelRecord().parentName)) { break; } else { @@ -226,8 +226,7 @@ // if (Debug.infoOn()) Debug.logInfo("[DataFile.findModelForLine] line: " + line, module); ModelRecord modelRecord = null; - for (int i = 0; i < modelDataFile.records.size(); i++) { - ModelRecord curModelRecord = (ModelRecord) modelDataFile.records.get(i); + for (ModelRecord curModelRecord: modelDataFile.records) { if (curModelRecord.tcPosition < 0) { modelRecord = curModelRecord; |
Free forum by Nabble | Edit this page |