package Payroll_System;import BasicIO.*;
/** This class is a program to merge two binary files of Employee records.
* Employees are assumed to have unique keys.
*
* @see Employee
*
* @author Dave Hughes
*
* @version 1.0 (Jan 2010)
*
* new concepts: file merge */public class MergeEmpFile {
private static final String HIGH_KEY =
Character.toString(Character.MAX_VALUE);
private BinaryDataFile empFile1; // first employee file
private BinaryDataFile empFile2; // second employee file
private BinaryOutputFile employees; // merged employee file
/** The constructor initializes the files for the merge */
public MergeEmpFile ( ) {
empFile1 = new BinaryDataFile();
empFile2 = new BinaryDataFile();
employees = new BinaryOutputFile();
}; // constructor
/** This method merges two files of binary Employee objects into a single
* binary object file. */
private void merge ( ) {
int numRec; // number of records processed
Employee emp1; // employee record from empFile1
Employee emp2; // employee record from empFile2
ASCIIDisplayer msg; // display for messages
msg = new ASCIIDisplayer();
msg.writeString("Processing....");
numRec = 0;
emp1 = getRec(empFile1);
emp2 = getRec(empFile2);
while ( ! (emp1.getEmpNum().equals(HIGH_KEY) &&
emp2.getEmpNum().equals(HIGH_KEY)) ) {
if ( emp1.getEmpNum().compareTo(emp2.getEmpNum()) < 0 ) {
employees.writeObject(emp1);
emp1 = getRec(empFile1);
}
else {
employees.writeObject(emp2);
emp2 = getRec(empFile2);
};
numRec = numRec + 1;
};
msg.writeString("Merge complete. ");
msg.newLine();
msg.writeInt(numRec);
msg.writeString(" records processed.");
msg.newLine();
msg.close();
empFile1.close();
empFile2.close();
employees.close();
}; // merge
/** This method obtains the next record from an employee file. If EOF is
* reached, it creates a dummy Employee record with key HIGH_KEY.
*
* @param from file from which to read
*
* @return Employee the employee record read. */
private Employee getRec ( BinaryDataFile from ) {
Employee result; // employee record read
result = (Employee) from.readObject();
if ( from.isEOF() ) {
result = new Employee(HIGH_KEY,"DUMMY",0.0);
};
return result;
}; // getRec
public static void main ( String[] args ) { new MergeEmpFile().merge(); };
} // MergeEmpFile2段红色的代码到底什么意思。请给的详细一点。
还有Character.toString(Character.MAX_VALUE)的Character到底怎么用
/** This class is a program to merge two binary files of Employee records.
* Employees are assumed to have unique keys.
*
* @see Employee
*
* @author Dave Hughes
*
* @version 1.0 (Jan 2010)
*
* new concepts: file merge */public class MergeEmpFile {
private static final String HIGH_KEY =
Character.toString(Character.MAX_VALUE);
private BinaryDataFile empFile1; // first employee file
private BinaryDataFile empFile2; // second employee file
private BinaryOutputFile employees; // merged employee file
/** The constructor initializes the files for the merge */
public MergeEmpFile ( ) {
empFile1 = new BinaryDataFile();
empFile2 = new BinaryDataFile();
employees = new BinaryOutputFile();
}; // constructor
/** This method merges two files of binary Employee objects into a single
* binary object file. */
private void merge ( ) {
int numRec; // number of records processed
Employee emp1; // employee record from empFile1
Employee emp2; // employee record from empFile2
ASCIIDisplayer msg; // display for messages
msg = new ASCIIDisplayer();
msg.writeString("Processing....");
numRec = 0;
emp1 = getRec(empFile1);
emp2 = getRec(empFile2);
while ( ! (emp1.getEmpNum().equals(HIGH_KEY) &&
emp2.getEmpNum().equals(HIGH_KEY)) ) {
if ( emp1.getEmpNum().compareTo(emp2.getEmpNum()) < 0 ) {
employees.writeObject(emp1);
emp1 = getRec(empFile1);
}
else {
employees.writeObject(emp2);
emp2 = getRec(empFile2);
};
numRec = numRec + 1;
};
msg.writeString("Merge complete. ");
msg.newLine();
msg.writeInt(numRec);
msg.writeString(" records processed.");
msg.newLine();
msg.close();
empFile1.close();
empFile2.close();
employees.close();
}; // merge
/** This method obtains the next record from an employee file. If EOF is
* reached, it creates a dummy Employee record with key HIGH_KEY.
*
* @param from file from which to read
*
* @return Employee the employee record read. */
private Employee getRec ( BinaryDataFile from ) {
Employee result; // employee record read
result = (Employee) from.readObject();
if ( from.isEOF() ) {
result = new Employee(HIGH_KEY,"DUMMY",0.0);
};
return result;
}; // getRec
public static void main ( String[] args ) { new MergeEmpFile().merge(); };
} // MergeEmpFile2段红色的代码到底什么意思。请给的详细一点。
还有Character.toString(Character.MAX_VALUE)的Character到底怎么用
此字段的常量值是 char 类型的最大值,即 '\uFFFF'。public static String toString(char c)
返回一个表示指定 char 值的 String 对象。结果是长度为 1 的字符串,仅由指定的 char 组成。