Generics, enhanced-for, Number.valueOf.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@672660 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -44,7 +44,7 @@ public class DataFile {
|
||||
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 @@ public class DataFile {
|
||||
return modelDataFile;
|
||||
}
|
||||
|
||||
public List getRecords() {
|
||||
public List<Record> getRecords() {
|
||||
return records;
|
||||
}
|
||||
|
||||
@@ -221,9 +221,8 @@ public class DataFile {
|
||||
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 {
|
||||
|
||||
@@ -50,13 +50,10 @@ public class DataFile2EntityXml {
|
||||
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 @@ public class DataFile2EntityXml {
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
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();
|
||||
|
||||
@@ -57,11 +57,10 @@ public class ModelDataFile {
|
||||
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 @@ public class ModelDataFile {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,19 +47,19 @@ public class ModelDataFileReader {
|
||||
|
||||
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 @@ public class ModelDataFileReader {
|
||||
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 @@ public class ModelDataFileReader {
|
||||
* @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 @@ public class ModelDataFileReader {
|
||||
/** 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 @@ public class ModelDataFileReader {
|
||||
/** 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 @@ public class ModelDataFileReader {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class ModelDataFileReader {
|
||||
|
||||
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 @@ public class ModelDataFileReader {
|
||||
|
||||
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;
|
||||
|
||||
@@ -65,14 +65,13 @@ public class ModelRecord {
|
||||
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 @@ public class ModelRecord {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import java.util.NoSuchElementException;
|
||||
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 @@ public class Record implements Serializable {
|
||||
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 @@ public class Record implements Serializable {
|
||||
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 @@ public class Record implements Serializable {
|
||||
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 @@ public class Record implements Serializable {
|
||||
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 @@ public class Record implements Serializable {
|
||||
|
||||
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 @@ public class Record implements Serializable {
|
||||
return parentRecord;
|
||||
}
|
||||
|
||||
public List getChildRecords() {
|
||||
public List<Record> getChildRecords() {
|
||||
return childRecords;
|
||||
}
|
||||
|
||||
@@ -469,7 +468,7 @@ public class Record implements Serializable {
|
||||
* @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 class Record implements Serializable {
|
||||
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 @@ public class Record implements Serializable {
|
||||
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) {
|
||||
|
||||
@@ -163,7 +163,7 @@ public class RecordIterator {
|
||||
|
||||
// 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 @@ public class RecordIterator {
|
||||
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 @@ public class RecordIterator {
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user