Javaコードに問題があります。何らかの理由で、リストに追加しようとしている属性は機能していますが、リスト内のオブジェクトを保持または表示するだけです。属性が消去されているのか、それとも何なのかわかりませんが、本当に迷惑です。
public static Program parseProgram(File fileName)
throws FileNotFoundException {
Scanner in1 = new Scanner(fileName);
Program program = new Program();
Short value = 0;
Short address = 0;
boolean indirect = false;
String[] temp = null;
while (in1.hasNextLine()) {
String line = in1.nextLine();
temp = line.split("\\s+");
Scanner in2 = new Scanner(temp[0]);
if (in2.hasNextInt(16)) {
int temp1 = Integer.parseInt(temp[0]);
Short temp2 = (short) temp1;
int temped = Integer.parseInt(temp[1]);
Short temp3 = (short) temped;
DataLine data = new DataLine(temp2, temp3);
try {
program.addDataLine(data);
} catch (DataAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String s = "*";
String ss = new String();
Instruction instruction = Instruction.getByName(temp[0]);
if (instruction.requiresArgument()) {
int temped = Integer.parseInt(temp[1], 16);
Short arg = (short) temped;
if (temp.length > 1) {
if (temp[1].endsWith("*")) {
indirect = true;
ss = temp[1].substring(0, temp[1].indexOf("*"));
arg = (short) Integer.parseInt(ss);
CodeLine code = new CodeLine(instruction, arg,
indirect);
try {
program.addCodeLine(code);
} catch (CodeAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (line.contains(s)) {
indirect = true;
String sg = temp[1].substring(0,
temp[1].indexOf("*"));
String st = temp[1]
.substring(temp[1].indexOf("*") + 1);
ss = sg + st;
arg = (short) Integer.parseInt(ss);
CodeLine code = new CodeLine(instruction, arg);
try {
program.addCodeLine(code);
} catch (CodeAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
System.out.println("error");
}
}
else {
CodeLine code = new CodeLine(instruction);
try {
program.addCodeLine(code);
} catch (CodeAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
return program;
}
} }
public class Program は Serializable を実装します{
private List<CodeLine> codeSegment = new ArrayList<CodeLine>();
private List<DataLine> dataSegment = new ArrayList<DataLine>();
/**
* Add a line of code to this program.
*
* @param line must not be null.
* @throws CodeAccessException if line is null
*/
public void addCodeLine(CodeLine line) throws CodeAccessException{
if(line == null)
throw new CodeAccessException("Cannot add null code lines to a program.");
codeSegment.add(line);
}
/**
* Add a data instructionn to this program. A data instruction is
* a address - value pair.
*
* @param line must not be null.
* @throws DataAccessException if line is null
*/
public void addDataLine(DataLine line) throws DataAccessException{
if(line == null)
throw new DataAccessException("Cannot add null data lines to a program.");
dataSegment.add(line);
}