import java.util.*;

public class Command
{
    public static final String MASK = "mask";
    public static final String MEM = "mem";
    public static final String OPEN_BRACE = "[";
    public static final String CLOSE_BRACE = "]";
    public static final String EQUALS = "=";

    public static final char FLOATING_BIT = 'X';

    public static final int INTEGER_SIZE = 36;

    public Command (String mask, Vector<String> cmds, boolean debug)
    {
        _mask = mask;
        _commands = cmds;
        _debug = debug;
    }

    public void execute (Memory mem)
    {
        String theMask = _mask.substring(_mask.indexOf(EQUALS) +1).trim();

        if (_debug)
            System.out.println("Bitmask is: "+theMask);

        for (int i = 0; i < _commands.size(); i++)
        {
            int startIndex = _commands.elementAt(i).indexOf(OPEN_BRACE);
            int endIndex = _commands.elementAt(i).indexOf(CLOSE_BRACE);
            String addrStr = _commands.elementAt(i).substring(startIndex +1, endIndex);
            Long addr = Long.parseLong(addrStr);

            if (_debug)
                System.out.println("Memory address: "+addr);

            startIndex = _commands.elementAt(i).indexOf(EQUALS);

            String valueStr = _commands.elementAt(i).substring(startIndex +1).trim();
            Long value = Long.parseLong(valueStr);

            if (_debug)
                System.out.println("Value: "+value);
        }
    }

    @Override
    public String toString ()
    {
        String str = _mask;

        for (int i = 0; i < _commands.size(); i++)
        {
            str += "\n" + _commands.elementAt(i);
        }

        return str;
    }

    private String applyMask (String address, String theMask)
    {

    }

    // 000000000000000000000000000000X1001X

    private Vector<String> generateAllAddresses (String address, byte[] theMask, int index)
    {
        Vector<String> addresses = new Vector<String>();
        int nextFloatingBit = -1;

        for (int i = 0; (i < theMask.length) && (nextFloatingBit != index); i++)
        {
        }

        return addresses;
	}

    private String generateAddress (String address, byte[] theMask, int index)
    {
        return null;
    }

    private String _mask;
    private Vector<String> _commands;
    private boolean _debug;
}
@@ -320,16 +320,105 @@
 T = 'X';
+%0A    public static final char ONE_BIT = '1';%0A    public static final char ZERO_BIT = '0';
 %0A%0A    pu
@@ -1781,64 +1781,1579 @@
 ate 
-String applyMask (String address, String theMask)%0A    %7B%0A
+byte%5B%5D applyMask (String address, String theMask)%0A    %7B%0A        byte%5B%5D addrAsChar = convertToBinary(Long.parseLong(address));%0A%0A        for (int i = 0; theMask.length(); i++)%0A        %7B%0A            switch (theMask.charAt(i))%0A            %7B%0A                case ONE_BIT:%0A                case FLOATING_BIT:%0A                %7B%0A                    /*%0A                     * If the bitmask bit is 1, the corresponding memory address bit is overwritten with 1.%0A                     * If the bitmask bit is X, the corresponding memory address bit is floating.%0A                     */%0A%0A                     addrAsChar%5Bi%5D = theMask.charAt(i);%0A                %7D%0A                break;%0A                case ZERO_BIT:%0A                default:%0A                %7B%0A                    // If the bitmask bit is 0, the corresponding memory address bit is unchanged.%0A                %7D%0A                break;%0A            %7D%0A        %7D%0A%0A        return addrAsChar;%0A    %7D%0A%0A    private char%5B%5D convertToBinary (long value)%0A    %7B%0A        char%5B%5D tempBinary = Long.toBinaryString(value).toCharArray();%0A        char%5B%5D binary;%0A%0A        if (tempBinary.length %3C INTEGER_SIZE)%0A        %7B%0A            binary = new char%5BINTEGER_SIZE%5D;%0A%0A            for (int i = 0; i %3C (INTEGER_SIZE - tempBinary.length); i++)%0A            %7B%0A                binary%5Bi%5D = '0';%0A            %7D%0A%0A            for (int j = 0; j %3C tempBinary.length; j++)%0A            %7B%0A                binary%5B(INTEGER_SIZE - tempBinary.length) +j%5D = tempBinary%5Bj%5D;%0A            %7D%0A        %7D%0A        else%0A            binary = tempBinary;%0A%0A        return binary;
 %0A   

Update Command.java