/**
   * The coder shall be able to decode all stock mechs.
   *
   * @throws Exception
   */
  @Test
  public void testDecodeAllStock() throws Exception {
    InputStream is = LoadoutCoderV2.class.getResourceAsStream("/resources/lsmlv2stock.txt");
    Scanner sc = new Scanner(is);

    Base64 base64 = new Base64();

    // [JENNER JR7-D(F)]=lsml://rQAD5AgQCAwOFAYQCAwIuipmzMO3aIExIyk9jt2DMA==
    while (sc.hasNextLine()) {
      String line = sc.nextLine();
      Pattern pat = Pattern.compile("\\[([^\\]]*)\\]\\s*=\\s*lsml://(\\S*).*");
      Matcher m = pat.matcher(line);
      m.matches();
      ChassisBase chassi = ChassisDB.lookup(m.group(1));
      String lsml = m.group(2);
      LoadoutStandard reference = new LoadoutStandard(chassi.getName());
      LoadoutStandard decoded = cut.decode(base64.decode(lsml.toCharArray()));

      // Name is not encoded
      OperationStack stack = new OperationStack(0);
      stack.pushAndApply(new OpRename(decoded, null, reference.getName()));

      // Verify
      assertEquals(reference, decoded);
    }

    sc.close();
  }
示例#2
0
  @Override
  public void setValue(Object arg0) {
    if (getValue().equals(arg0)) return;

    try {
      final boolean setSymmetric =
          symmetric.isSelected()
              && part.getInternalComponent().getLocation().oppositeSide() != null;
      final int armor = ((Integer) arg0).intValue();

      if (setSymmetric) {
        opStack.pushAndApply(new OpSetArmorSymmetric(xBar, loadout, part, side, armor, true));
      } else {
        opStack.pushAndApply(new OpSetArmor(xBar, loadout, part, side, armor, true));
      }
    } catch (IllegalArgumentException exception) {
      // TODO: Handle failed case better!
      Toolkit.getDefaultToolkit().beep();
    } finally {
      fireStateChanged();
    }
  }