3535/**
3636 * A list of VM instructions, with a program counter.
3737 */
38- public class VMProgram extends InteractiveComputerPart
39- implements ProgramEventListener {
38+ class VMProgram extends InteractiveComputerPart implements ProgramEventListener {
4039
4140 // pseudo address for returning to built-in functions
42- public static final short BUILTIN_FUNCTION_ADDRESS = -1 ;
41+ static final short BUILTIN_FUNCTION_ADDRESS = -1 ;
4342
4443 // Possible values for the current status - has the user allowed
4544 // access to built-in vm functions?
@@ -86,12 +85,12 @@ public class VMProgram extends InteractiveComputerPart
8685 /**
8786 * Constructs a new empty program with the given GUI.
8887 */
89- public VMProgram (VMProgramGUI gui ) {
88+ VMProgram (VMProgramGUI gui ) {
9089 super (gui != null );
9190 this .gui = gui ;
92- listeners = new Vector <ProgramEventListener >();
93- staticRange = new Hashtable <String , Object >();
94- functions = new Hashtable <String , Short >();
91+ listeners = new Vector <>();
92+ staticRange = new Hashtable <>();
93+ functions = new Hashtable <>();
9594
9695 if (hasGUI ) {
9796 assert gui != null ;
@@ -132,7 +131,7 @@ public void loadProgram(String fileName) throws ProgramException {
132131 staticRange .clear ();
133132 functions .clear ();
134133 builtInAccessStatus = BUILTIN_ACCESS_UNDECIDED ;
135- Hashtable <String , Short > symbols = new Hashtable <String , Short >();
134+ Hashtable <String , Short > symbols = new Hashtable <>();
136135 nextPC = 0 ;
137136 for (File f : files ) {
138137 String name = f .getName ();
@@ -534,7 +533,7 @@ private String unCommentLine(String line) {
534533 * form of a 2-elements array {startAddress, endAddress}.
535534 * If unknown class name, returns null.
536535 */
537- public int [] getStaticRange (String className ) {
536+ int [] getStaticRange (String className ) {
538537 return (int [])staticRange .get (className );
539538 }
540539
@@ -545,7 +544,7 @@ public int getSize() {
545544 return instructionsLength ;
546545 }
547546
548- public short getAddress (String functionName ) throws ProgramException {
547+ short getAddress (String functionName ) throws ProgramException {
549548 Short address = functions .get (functionName );
550549 if (address != null ) {
551550 return address ;
@@ -580,28 +579,28 @@ public short getAddress(String functionName) throws ProgramException {
580579 /**
581580 * Returns the next program counter.
582581 */
583- public short getPC () {
582+ short getPC () {
584583 return nextPC ;
585584 }
586585
587586 /**
588587 * Returns the current value of the program counter.
589588 */
590- public short getCurrentPC () {
589+ short getCurrentPC () {
591590 return currentPC ;
592591 }
593592
594593 /**
595594 * Returns the previous value of the program counter.
596595 */
597- public short getPreviousPC () {
596+ short getPreviousPC () {
598597 return prevPC ;
599598 }
600599
601600 /**
602601 * Sets the program counter with the given address.
603602 */
604- public void setPC (short address ) {
603+ void setPC (short address ) {
605604 prevPC = currentPC ;
606605 currentPC = nextPC ;
607606 nextPC = address ;
@@ -618,7 +617,7 @@ public void setPC(short address) {
618617 * stop an infinite loop in a built-in jack class.
619618 * A message containing information may be provided (can be null).
620619 */
621- public void setPCToInfiniteLoopForBuiltIns (String message ) {
620+ void setPCToInfiniteLoopForBuiltIns (String message ) {
622621 if (hasGUI ) {
623622 gui .notify (message );
624623 }
@@ -629,7 +628,7 @@ public void setPCToInfiniteLoopForBuiltIns(String message) {
629628 * Returns the next VMEmulatorInstruction and increments the PC by one.
630629 * The PC will be incremented by more if the next instruction is a label.
631630 */
632- public VMEmulatorInstruction getNextInstruction () {
631+ VMEmulatorInstruction getNextInstruction () {
633632 VMEmulatorInstruction result = null ;
634633
635634 if (nextPC < instructionsLength ) {
@@ -645,7 +644,7 @@ public VMEmulatorInstruction getNextInstruction() {
645644 return result ;
646645 }
647646
648- public short getNextInstructionAddress (short pc ) {
647+ short getNextInstructionAddress (short pc ) {
649648 do {
650649 pc ++;
651650 } while (pc < instructionsLength && instructions [pc ].getOpCode () == HVMInstructionSet .LABEL_CODE );
@@ -655,7 +654,7 @@ public short getNextInstructionAddress(short pc) {
655654 /**
656655 * Restarts the program from the beginning.
657656 */
658- public void restartProgram () {
657+ void restartProgram () {
659658 currentPC = -999 ;
660659 prevPC = -999 ;
661660 nextPC = startAddress ;
@@ -713,16 +712,16 @@ private void setGUIPC() {
713712 gui .setCurrentInstruction (nextPC );
714713 }
715714
716- public VMEmulatorInstruction getInstructionAt (short pc ) {
715+ VMEmulatorInstruction getInstructionAt (short pc ) {
717716 return pc >= 0 && pc < instructions .length ? instructions [pc ] : null ;
718717 }
719718
720719 // The task that loads a new program into the emulator
721- class LoadProgramTask implements Runnable {
720+ private class LoadProgramTask implements Runnable {
722721
723722 private String fileName ;
724723
725- public LoadProgramTask (String fileName ) {
724+ LoadProgramTask (String fileName ) {
726725 this .fileName = fileName ;
727726 }
728727
@@ -746,7 +745,7 @@ public void refreshGUI() {
746745 /**
747746 * Registers the given ProgramEventListener as a listener to this GUI.
748747 */
749- public void addProgramListener (ProgramEventListener listener ) {
748+ void addProgramListener (ProgramEventListener listener ) {
750749 listeners .add (listener );
751750 }
752751
@@ -755,7 +754,7 @@ public void addProgramListener(ProgramEventListener listener) {
755754 * a ProgramEvent (with the new event type and program's file name) and sending it using the
756755 * programChanged function to all the listeners.
757756 */
758- protected void notifyProgramListeners (byte eventType , String programFileName ) {
757+ private void notifyProgramListeners (byte eventType , String programFileName ) {
759758 ProgramEvent event = new ProgramEvent (this , eventType , programFileName );
760759
761760 for (ProgramEventListener listener : listeners )
0 commit comments