Ejemplo n.º 1
0
  public static void main(String args[]) {
    int port;
    String host;

    if (args.length == 1) {
      try {
        port = Integer.parseInt(args[0]);

        doEcho(port);

      } catch (IOException io_ex) {
        io_ex.printStackTrace();
        System.exit(1);

      } catch (NumberFormatException num_ex) {
        num_ex.printStackTrace();
        System.exit(1);
      }
    } else if (args.length == 2) {
      try {
        host = args[0];
        port = Integer.parseInt(args[1]);

        UDPEcho ut = new UDPEcho(host, port);
        Thread thread = new Thread(ut);
        thread.start();

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s;
        System.out.print("Enter datagram:");
        s = in.readLine();
        while (s != null) {
          ut.send(s);
          try {
            Thread.currentThread().sleep(100);
          } catch (InterruptedException i_ex) {
          }
          System.out.print("Enter datagram:");
          s = in.readLine();
        }
        System.exit(1);

      } catch (IOException io_ex) {
        io_ex.printStackTrace();
        System.exit(1);
      } catch (NumberFormatException num_ex) {
        num_ex.printStackTrace();
        System.exit(1);
      }

    } else {
      usage();
    }
  }
Ejemplo n.º 2
0
  private void save_buttonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_save_buttonActionPerformed
    for (int i = 0; i < rubric_table.getColumnCount(); i++) {
      try {
        GradeAccess.enterGrade(
            studentID,
            courseID,
            actName,
            rubric_table.getModel().getValueAt(i, 0).toString(),
            Float.parseFloat(rubric_table.getModel().getValueAt(i, 1).toString()));
      } catch (NumberFormatException e) {
        e.printStackTrace();
      } catch (SQLException e) {
        GradeAccess.updateGrade(
            studentID,
            courseID,
            actName,
            rubric_table.getModel().getValueAt(i, 0).toString(),
            Float.parseFloat(rubric_table.getModel().getValueAt(i, 1).toString()));
      }
    }

    try {
      PrintWriter out = new PrintWriter(paths[0] + "/" + studentID + "/" + actName + ".py");
      out.write(submission_text_area.getText());
      out.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
    setOkToNav();
    JOptionPane.showMessageDialog(this, "Grade and comments saved.");
  } // GEN-LAST:event_save_buttonActionPerformed
Ejemplo n.º 3
0
  /**
   * read the transition matrix from the file
   *
   * @param fp
   * @return
   */
  public static Map<Integer, Set<Integer>> readTransitionMatrix(String fp) {
    Map<Integer, Set<Integer>> res = new HashMap<Integer, Set<Integer>>();

    if (fp == null || fp.length() == 0) return res;

    try {
      BufferedReader reader =
          new BufferedReader(new InputStreamReader(new FileInputStream(new File(fp))));

      String line = null;
      while ((line = reader.readLine()) != null) {
        String[] fields = line.split(" ");
        int from = Integer.parseInt(fields[0]);
        int to = Integer.parseInt(fields[1]);

        if (res.containsKey(from)) {
          res.get(from).add(to);
        } else {
          Set<Integer> cset = new HashSet<Integer>();
          cset.add(to);

          res.put(from, cset);
        }
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return Collections.unmodifiableMap(res);
  }
Ejemplo n.º 4
0
  public static DataSet createFromFile(
      String filePath, int inputsCount, int outputsCount, String delimiter) {
    FileReader fileReader = null;

    try {
      DataSet trainingSet = new DataSet(inputsCount, outputsCount);
      fileReader = new FileReader(new File(filePath));
      BufferedReader reader = new BufferedReader(fileReader);

      String line = "";

      while ((line = reader.readLine()) != null) {
        double[] inputs = new double[inputsCount];
        double[] outputs = new double[outputsCount];
        String[] values = line.split(delimiter);

        if (values[0].equals("")) {
          continue; // skip if line was empty
        }
        for (int i = 0; i < inputsCount; i++) {
          inputs[i] = Double.parseDouble(values[i]);
        }

        for (int i = 0; i < outputsCount; i++) {
          outputs[i] = Double.parseDouble(values[inputsCount + i]);
        }

        if (outputsCount > 0) {
          trainingSet.addRow(new DataSetRow(inputs, outputs));
        } else {
          trainingSet.addRow(new DataSetRow(inputs));
        }
      }

      return trainingSet;

    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException ex1) {
        }
      }
      ex.printStackTrace();
    } catch (NumberFormatException ex) {
      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException ex1) {
        }
      }
      ex.printStackTrace();
      throw ex;
    }

    return null;
  }
Ejemplo n.º 5
0
 public static boolean isNumber(String n) {
   try {
     double d = Double.valueOf(n).doubleValue();
     return true;
   } catch (NumberFormatException e) {
     e.printStackTrace();
     return false;
   }
 }
Ejemplo n.º 6
0
 /**
  * Return a integer parsed from the value associated with the given key, or "def" in key wasn't
  * found.
  */
 public static int parseProperty(Properties preferences, String key, int def) {
   String val = preferences.getProperty(key);
   if (val == null) return def;
   try {
     return Integer.parseInt(val);
   } catch (NumberFormatException nfe) {
     nfe.printStackTrace();
     return def;
   }
 }
Ejemplo n.º 7
0
 /** @return the pot */
 public static int getPort() {
   int port = 0;
   try {
     port = Integer.parseInt(pot.getText());
   } catch (NumberFormatException f) {
     f.printStackTrace();
     new WhatIDo("Entrer un port valide", f.toString());
   }
   return port;
 }
Ejemplo n.º 8
0
    public void actionPerformed(ActionEvent e) {
      JTextField fieldEdited = (JTextField) e.getSource();
      try {
        systemOrder = Integer.parseInt(fieldEdited.getText());
      } catch (NumberFormatException nfex) {
        System.out.println("Number format exception in getting system order");
        nfex.printStackTrace();
      }

      String updatedStatusText = prepareStatusText();
      statusAreaTop.setText(updatedStatusText);
    }
Ejemplo n.º 9
0
 public List<Object> readExcel(Workbook wb, Class clz, int readLine, int tailLine) {
   Sheet sheet = wb.getSheetAt(0); // 取第一张表
   List<Object> objs = null;
   try {
     Row row = sheet.getRow(readLine); // 开始行,主题栏
     objs = new ArrayList<Object>();
     Map<Integer, String> maps = getHeaderMap(row, clz); // 设定对应的字段顺序与方法名
     if (maps == null || maps.size() <= 0)
       throw new RuntimeException("要读取的Excel的格式不正确,检查是否设定了合适的行"); // 与order顺序不符
     for (int i = readLine + 1; i <= sheet.getLastRowNum() - tailLine; i++) { // 取数据
       row = sheet.getRow(i);
       Object obj = clz.newInstance(); //   调用无参结构
       for (Cell c : row) {
         int ci = c.getColumnIndex();
         String mn = maps.get(ci).substring(3); // 消除get
         mn = mn.substring(0, 1).toLowerCase() + mn.substring(1);
         Map<String, Object> params = new HashMap<String, Object>();
         if (!"enterDate".equals(mn)) c.setCellType(Cell.CELL_TYPE_STRING); // 设置单元格格式
         else c.setCellType(Cell.CELL_TYPE_NUMERIC);
         if (this.getCellValue(c).trim().equals("是")) {
           BeanUtils.copyProperty(obj, mn, 1);
         } else if (this.getCellValue(c).trim().equals("否")) {
           BeanUtils.copyProperty(obj, mn, 0);
         } else BeanUtils.copyProperty(obj, mn, this.getCellValue(c));
       }
       objs.add(obj);
     }
   } catch (InstantiationException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (InvocationTargetException e) {
     e.printStackTrace();
     logger.error(e);
   } catch (NumberFormatException e) {
     e.printStackTrace();
     logger.error(e);
   }
   return objs;
 }
Ejemplo n.º 10
0
 /**
  * @return a double parsed from the value associated with the given key in the given Properties.
  *     returns "def" in key wasn't found, or if a parsing error occured. If "value" contains a "%"
  *     sign, we use a <code>NumberFormat.getPercentInstance</code> to convert it to a double.
  */
 public static double parseProperty(Properties preferences, String key, double def) {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   String val = preferences.getProperty(key);
   if (val == null) return def;
   if (val.indexOf("%") == -1) { // not in percent format !
     try {
       return Double.parseDouble(val);
     } catch (NumberFormatException nfe) {
       nfe.printStackTrace();
       return def;
     }
   }
   // else it's a percent format -> parse it
   try {
     Number n = formatPercent.parse(val);
     return n.doubleValue();
   } catch (ParseException ex) {
     ex.printStackTrace();
     return def;
   }
 }
 private void inputIPAddr() {
   try {
     String ipSample = getIPAndroid();
     String hostStr =
         Messages.showInputDialog(
             "What is your host?",
             "Input your host address",
             Messages.getQuestionIcon(),
             ipSample + ":" + port,
             null);
     if (hostStr == null) {
       hostStr = ipSample + ":1234";
     }
     int index = hostStr.indexOf(":");
     serverName = hostStr.substring(0, index);
     port = Integer.parseInt(hostStr.substring(index + 1));
   } catch (NumberFormatException e) {
     e.printStackTrace();
     serverName = "localhost";
     port = 1234;
   }
 }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    javax.servlet.jsp.PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;

    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html;charset=ISO-8859-1");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n\n");
      out.write("\n\n");

      PollerConfiguration pollconfig = getPollerConfiguration();
      org.opennms.netmgt.config.poller.Package pkg = null;

      int pkgIdx = -1;

      String pkgIdxStr = (String) request.getParameter("pkgidx");
      if (pkgIdxStr != null && pkgIdxStr.trim().length() > 0) {
        try {
          pkgIdx = Integer.parseInt(pkgIdxStr);
          if (pkgIdx >= 0) {
            if (pollconfig != null) {
              pkg = pollconfig.getPackage(pkgIdx);
            }
          }
        } catch (NumberFormatException ne) {
          ne.printStackTrace();
        }
      }

      if (pkg == null) {
        if ((org.opennms.netmgt.config.poller.Package) request.getSession().getAttribute("pkg")
            != null) {
          pkg = (org.opennms.netmgt.config.poller.Package) request.getSession().getAttribute("pkg");
        }
      }

      if (pkgIdx == -1) {
        pkgIdxStr = (String) request.getSession().getAttribute("pkgidx");
        if (pkgIdxStr != null && pkgIdxStr.trim().length() > 0) {
          try {
            pkgIdx = Integer.parseInt(pkgIdxStr);
          } catch (NumberFormatException ne) {
            ne.printStackTrace();
          }
        }
      }

      request.getSession().setAttribute("pkg", pkg);
      request.getSession().setAttribute("pkgidx", String.valueOf(pkgIdx));

      String title = " Poller Package Downtime Model";
      if (pkg != null) {
        title = " Poller Package - Downtime Model for: " + pkg.getName();
      }

      out.write("\n\n");
      out.write("<html>\n");
      out.write("<head>\n  ");
      out.write("<title>");
      out.print(title);
      out.write("</title>\n  ");
      out.write(
          "<link rel=\"stylesheet\" type=\"text/css\" href=\"/wt-portal/css/default.css\" />\n  ");
      out.write("<script type=\"text/javascript\" src=\"/wt-portal/javascript/WTtools.js\">");
      out.write("</script>\n\n");
      out.write(
          "<script language=javascript>\nfunction confirmDelete(msg)\n{\n\tvar agree=confirm(msg);\n\tif (agree)\n\t\treturn true;\n\telse\n\t\treturn false;\n}\n\nfunction addDowntime()\n{\n    var msg = \"\";\n    var error = false;\n    var begin = 0;\n    var end = 0;\n    var interval = 0;\n\n    dtbeginday = parseInt(document.downtime.dtbeginday.value) * 24 * 60 * 60 * 1000;\n    dtbeginhour = parseInt(document.downtime.dtbeginhour.value) * 60 * 60 * 1000;\n    dtbeginminute = parseInt(document.downtime.dtbeginminute.value) * 60 * 1000;\n    dtbeginsecond = parseInt(document.downtime.dtbeginsecond.value) * 1000;\n    dtbeginmillisecond = parseInt(document.downtime.dtbeginmillisecond.value);\n\n    dtendday = parseInt(document.downtime.dtendday.value) * 24 * 60 * 60 * 1000;\n    dtendhour = parseInt(document.downtime.dtendhour.value) * 60 * 60 * 1000;\n    dtendminute = parseInt(document.downtime.dtendminute.value) * 60 * 1000;\n    dtendsecond = parseInt(document.downtime.dtendsecond.value) * 1000;\n    dtendmillisecond = parseInt(document.downtime.dtendmillisecond.value);\n");
      out.write(
          "\n    dtintervalday = parseInt(document.downtime.dtintervalday.value) * 24 * 60 * 60 * 1000;\n    dtintervalhour = parseInt(document.downtime.dtintervalhour.value) * 60 * 60 * 1000;\n    dtintervalminute = parseInt(document.downtime.dtintervalminute.value) * 60 * 1000;\n    dtintervalsecond = parseInt(document.downtime.dtintervalsecond.value) * 1000;\n    dtintervalmillisecond = parseInt(document.downtime.dtintervalmillisecond.value);\n\n    document.downtime.dtbegin.value = dtbeginday + dtbeginhour + dtbeginminute + dtbeginsecond + dtbeginmillisecond;\n    document.downtime.dtend.value = dtendday + dtendhour + dtendminute + dtendsecond + dtendmillisecond;\n    document.downtime.dtinterval.value = dtintervalday + dtintervalhour + dtintervalminute + dtintervalsecond + dtintervalmillisecond;\n\n\tvar beginVal = trim(document.downtime.dtbegin.value);\n\tvar endVal = trim(document.downtime.dtend.value);\n\tvar intervalVal = trim(document.downtime.dtinterval.value);\n\n    if (beginVal == \"\") {\n        error = true;\n        msg += \"Must enter a numeric time value for \\\"begin\\\".\\n\";\n");
      out.write(
          "    }\n    if (endVal == \"\") {\n        error = true;\n        msg += \"\\nMust enter a numeric time value for \\\"end\\\".\\n\";\n    }\n    if (intervalVal  == \"\") {\n        error = true;\n        msg += \"\\nMust enter a numeric time value for \\\"interval\\\".\\n\";\n    }\n    if (isNaN(beginVal)) {\n        error = true;\n        msg += \"\\nMust enter a numeric time value for \\\"begin\\\".\\n\";\n    }\n    if (isNaN(endVal)) {\n        error = true;\n        msg += \"\\nMust enter a numeric time value for \\\"end\\\".\\n\";\n    }\n    if (isNaN(intervalVal)) {\n        error = true;\n        msg += \"\\nMust enter a numeric time value for \\\"interval\\\".\\n\";\n    }\n\n    if (!error) {\n        begin = parseInt(beginVal);\n        end = parseInt(endVal);\n        interval = parseInt(intervalVal);\n    \n        if (!(end > 0)) {\n            error = true;\n            msg = \"The end time must be greater than zero.\\n\";\n        }\n        if (!(interval > 0)) {\n            error = true;\n            msg += \"\\nThe 'interval' value must be greater than zero.\\n\";\n        }\n");
      out.write(
          "        if (!((end - begin) > 0)) {\n            error = true;\n            msg += \"\\nThe 'end' time must be greater than the 'begin'.\\n\";\n        }\n        if (!(interval ");
      out.write(
          "<= (end - begin))) {\n            error = true;\n            msg += \"\\nThe 'interval' time must be less than the difference of the 'begin' and the 'end'.\\n\";\n        }\n    }\n\n    if (error) {\n        alert (msg);\n        return;\n    }\n    else\n    {\n        document.downtime.target = \"pollerDetailFrame\";\n    \tdocument.downtime.action.value = 'adddt';\n    \tdocument.downtime.submit();\n    }\n}\n\nfunction removeDowntime(dtidx)\n{\n    if (confirmDelete('Are you sure you want to delete this downtime model?')) {\n        document.downtime.target = \"pollerDetailFrame\";\n        document.downtime.action.value = 'removedt';\n        document.downtime.dtidx.value = dtidx;\n    \tdocument.downtime.submit();\n    }\n}\n\nfunction updateDowntime()\n{\n    document.downtime.target = \"_parent\";\n    document.downtime.action.value = 'updatedt';\n\tdocument.downtime.submit();\n}\n\nfunction restoreDefaultDowntime()\n{\n    if (confirmDelete('Are you sure you want to restore the default downtime model? All your changes will be lost.')) {\n        document.downtime.target = \"pollerDetailFrame\";\n");
      out.write(
          "        document.downtime.action.value = 'restoredt';\n    \tdocument.downtime.submit();\n    }\n}\n");
      out.write("</script>\n");
      out.write("</head>\n");
      out.write("<body>\n\n\t");
      String breadcrumb1 = "<a href='admin/index.jsp'></a>";
      out.write("\n\t");
      String breadcrumb2 = "Poller Packages";
      out.write("\n\t");
      JspRuntimeLibrary.include(
          request,
          response,
          "/includes/header.jsp"
              + "?"
              + "title="
              + java.net.URLEncoder.encode("" + title)
              + "&"
              + "location="
              + "admin"
              + "&"
              + "help="
              + "monitoringadmin%2Fpolling%2FWTHelp_PollerPackageDowntimeModel.html"
              + "&"
              + "noPopOut="
              + "true"
              + "&"
              + "breadcrumb="
              + java.net.URLEncoder.encode("" + breadcrumb1)
              + "&"
              + "breadcrumb="
              + java.net.URLEncoder.encode("" + breadcrumb2),
          out,
          false);
      out.write("\n");
      out.write("<!-- BEGIN FRAMING TABLE:open tags, keep at 100%-->\n");
      out.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\t");
      out.write("<tr>\n\t\t");
      out.write("<td width=\"10\">");
      out.write(
          "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"1\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">");
      out.write("</td>\n\t\t");
      out.write("<td>\n");
      out.write("<!-- END FRAMING TABLE:open tags, keep at 100%-->\n\t");
      out.write("<form action=\"");
      out.print(WTTools.getMonServletURL(request));
      out.write("WTPollerPackages\" method=\"post\" name=\"downtime\" target=\"_parent\">\n\t  ");
      out.write("<input type=\"hidden\" name=\"action\" value=\"\">\n\t  ");
      out.write("<input type=\"hidden\" name=\"pkgidx\" value=\"\">\n\t  ");
      out.write("<input type=\"hidden\" name=\"dtidx\" value=\"\">\n\t  ");
      out.write("<input type=\"hidden\" name=\"dtbegin\" value=\"\">\n\t  ");
      out.write("<input type=\"hidden\" name=\"dtend\" value=\"\">\n\t  ");
      out.write("<input type=\"hidden\" name=\"dtinterval\" value=\"\">\n\n");
      out.write("<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n     ");
      out.write("<tr>\n        ");
      out.write("<td colspan=\"4\">");
      out.write("<b>Downtime Model:");
      out.write("</b>");
      out.write("<a class=\"tt\" href=\"javascript: towerTip(");
      out.print(WTTips.TIP_POLLER_MON_SERVICE);
      out.write(");\" title=\"Telemetry Tip\">");
      out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">");
      out.write("</a>");
      out.write("</td>\n    ");
      out.write("</tr>\n     ");
      out.write("<tr class=\"tableHeader\">\n        ");
      out.write("<td class=\"tableHeader\" width=\"25%\">Begin Time");
      out.write("<a class=\"tt\" href=\"javascript: towerTip(");
      out.print(WTTips.TIP_POLLER_DT_BEGIN);
      out.write(");\" title=\"Telemetry Tip\">");
      out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">");
      out.write("</a>");
      out.write("</td>\n        ");
      out.write("<td class=\"tableHeader\" width=\"25%\">End Time");
      out.write("<a class=\"tt\" href=\"javascript: towerTip(");
      out.print(WTTips.TIP_POLLER_DT_END);
      out.write(");\" title=\"Telemetry Tip\">");
      out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">");
      out.write("</a>");
      out.write("</td>\n        ");
      out.write("<td class=\"tableHeader\" width=\"25%\">Polling Interval");
      out.write("<a class=\"tt\" href=\"javascript: towerTip(");
      out.print(WTTips.TIP_POLLER_DT_INTERVAL);
      out.write(");\" title=\"Telemetry Tip\">");
      out.write("<img src=\"/wt-portal/images/icons/tower_tips.gif\" border=\"0\">");
      out.write("</a>");
      out.write("</td>\n        ");
      out.write("<td class=\"tableHeader\" width=\"25%\">Action");
      out.write("</td>\n    ");
      out.write("</tr>\n        ");

      long daymilli = 24 * 60 * 60 * 1000; // 86400000
      long hourmlli = 60 * 60 * 1000; // 3600000;
      long minutemilli = 60 * 1000; // 60000;
      long secondmilli = 1000;

      String pattern2digit = "00";
      DecimalFormat df2digit = new DecimalFormat(pattern2digit);

      String pattern3digit = "000";
      DecimalFormat df3digit = new DecimalFormat(pattern3digit);

      long begin = 0;
      long end = 0;
      long interval = 0;
      String delete = null;
      long addbegin = 0;
      if (pkg != null) {
        Downtime[] ds = pkg.getDowntime();
        if (ds != null) {
          for (int i = 0; i < ds.length; i++) {
            Downtime d = ds[i];

            begin = d.getBegin();
            end = d.getEnd();
            interval = d.getInterval();
            delete = d.getDelete();

            long dtbegin = begin;
            long dtend = end;
            long dtinterval = interval;
            addbegin = begin;

            long dtbeginday = 0;
            long dtbeginhour = 0;
            long dtbeginminute = 0;
            long dtbeginsecond = 0;
            long dtbeginmillisecond = 0;

            long dtendday = 0;
            long dtendhour = 0;
            long dtendminute = 0;
            long dtendsecond = 0;
            long dtendmillisecond = 0;

            long dtintervalday = 0;
            long dtintervalhour = 0;
            long dtintervalminute = 0;
            long dtintervalsecond = 0;
            long dtintervalmillisecond = 0;

            if (dtbegin > 0) {
              dtbeginday = dtbegin / daymilli;
              dtbegin -= (dtbeginday * daymilli);
            }
            if (dtbegin > 0) {
              dtbeginhour = dtbegin / hourmlli;
              dtbegin -= (dtbeginhour * hourmlli);
            }
            if (dtbegin > 0) {
              dtbeginminute = dtbegin / minutemilli;
              dtbegin -= (dtbeginminute * minutemilli);
            }
            if (dtbegin > 0) {
              dtbeginsecond = dtbegin / secondmilli;
              dtbegin -= (dtbeginsecond * secondmilli);
            }
            if (dtbegin > 0) {
              dtbeginmillisecond = dtbegin;
            }

            if (dtend > 0) {
              dtendday = dtend / daymilli;
              dtend -= (dtendday * daymilli);
            }
            if (dtend > 0) {
              dtendhour = dtend / hourmlli;
              dtend -= (dtendhour * hourmlli);
            }
            if (dtend > 0) {
              dtendminute = dtend / minutemilli;
              dtend -= (dtendminute * minutemilli);
            }
            if (dtend > 0) {
              dtendsecond = dtend / secondmilli;
              dtend -= (dtendsecond * secondmilli);
            }
            if (dtend > 0) {
              dtendmillisecond = dtend;
            }

            if (dtinterval > 0) {
              dtintervalday = dtinterval / daymilli;
              dtinterval -= (dtintervalday * daymilli);
            }
            if (dtinterval > 0) {
              dtintervalhour = dtinterval / hourmlli;
              dtinterval -= (dtintervalhour * hourmlli);
            }
            if (dtinterval > 0) {
              dtintervalminute = dtinterval / minutemilli;
              dtinterval -= (dtintervalminute * minutemilli);
            }
            if (dtinterval > 0) {
              dtintervalsecond = dtinterval / secondmilli;
              dtinterval -= (dtintervalsecond * secondmilli);
            }
            if (dtinterval > 0) {
              dtintervalmillisecond = dtinterval;
            }

            out.write("\n                    ");
            out.write("<!--\n            \t\t");
            out.write("<TR>\n                \t\t");
            out.write("<TD align=\"center\">\n                \t\t");
            out.write("<INPUT name=\"dtbegin_");
            out.print(String.valueOf(i));
            out.write("\" type=\"text\" value=\"");
            out.print(begin);
            out.write("\" disabled>\n                \t\t");
            out.write("</TD>\n                \t\t");
            out.write("<TD align=\"center\">");
            out.write("<INPUT name=\"dtend_");
            out.print(String.valueOf(i));
            out.write("\" type=\"text\" value=\"");
            out.print(end);
            out.write("\" disabled>");
            out.write("</TD>\n                \t\t");
            out.write("<TD align=\"center\">");
            out.write("<INPUT name=\"dtinterval_");
            out.print(String.valueOf(i));
            out.write("\" type=\"text\" value=\"");
            out.print(interval);
            out.write("\" disabled>");
            out.write("</TD>\n                \t\t");
            out.write("<TD align=\"center\">");
            out.write("<INPUT name=\"dtdel_");
            out.print(String.valueOf(i));
            out.write("\" type=\"checkbox\" value=\"true\" ");
            if (delete != null && delete.equals("true")) {
              out.write("checked");
            }
            out.write(" disabled>");
            out.write("</TD>\n                \t\t");
            out.write("<TD align=\"center\">\n                            ");
            if ((i + 2) == ds.length) {
              out.write("\n                                ");
              out.write("<a HREF=\"javascript:removeDowntime('");
              out.print(i);
              out.write("')\" title=\"Remove Downtime Model\">Remove");
              out.write("</a>\n                            ");
            } else {
              out.write("\n                               &nbsp;\n                            ");
            }
            out.write("\n                        ");
            out.write("</TD>\n            \t\t");
            out.write("</TR>\n            \t\t-->\n\n                \t\t");
            if (i < (ds.length - 1)) {
              out.write("\n                           ");
              out.write("<tr class=\"");
              out.print(((i % 2) == 0) ? "tableRowLIght" : "tableRowDark");
              out.write("\">\n                \t\t");
              out.write("<td class=\"tableText\">\n                    \t\t");
              out.print(dtbeginday);
              out.write(" days ");
              out.print(df2digit.format(dtbeginhour));
              out.write(":");
              out.print(df2digit.format(dtbeginminute));
              out.write(":");
              out.print(df2digit.format(dtbeginsecond));
              out.write(":");
              out.print(df3digit.format(dtbeginmillisecond));
              out.write("\n                        ");
              out.write("</td>\n                \t\t");
              out.write("<td class=\"tableText\">\n                   \t\t    ");
              out.print(dtendday);
              out.write(" days ");
              out.print(df2digit.format(dtendhour));
              out.write(":");
              out.print(df2digit.format(dtendminute));
              out.write(":");
              out.print(df2digit.format(dtendsecond));
              out.write(":");
              out.print(df3digit.format(dtendmillisecond));
              out.write("\n                        ");
              out.write("</td>\n                \t\t");
              out.write("<td class=\"tableText\">\n                    \t\t");
              out.print(dtintervalday);
              out.write(" days ");
              out.print(df2digit.format(dtintervalhour));
              out.write(":");
              out.print(df2digit.format(dtintervalminute));
              out.write(":");
              out.print(df2digit.format(dtintervalsecond));
              out.write(":");
              out.print(df3digit.format(dtintervalmillisecond));
              out.write("\n                        ");
              out.write("</td>\n                        ");
              out.write("<td class=\"tableText\">\n                                 ");
              if (i == (ds.length - 2)) {
                out.write("\n                                     ");
                out.write("<a href=\"javascript:removeDowntime('");
                out.print(i);
                out.write("')\" title=\"Remove Downtime Model\">Remove");
                out.write("</a>");
                out.write("</td>\n                                 ");
              }
              out.write("\n                        ");
              out.write("</td>\n                \t\t");
            } else {
              out.write("\n\t\t\t\t\t\t");
              out.write("<tr>");
              out.write("<td colspan=\"3\">&nbsp;");
              out.write("</td>");
              out.write("</tr>\n                           ");
              out.write("<tr class=\"tableHeader\">\n                \t\t");
              out.write("<td class=\"tableHeader\" colspan=\"3\">\n                            ");
              if ((delete == null || !delete.equals("true")) && end == 0 && interval > 0) {
                out.write("\n                    \t\tAfter\n                    \t\t");
                out.write("<b>\n                \t\t    ");
                if (dtbeginday > 0) {
                  out.print(dtbeginday);
                  out.write(" days");
                }
                out.write("\n                \t\t    ");
                if (dtbeginhour > 0) {
                  out.print(dtbeginhour);
                  out.write(" hr");
                }
                out.write("\n                \t\t    ");
                if (dtbeginminute > 0) {
                  out.print(dtbeginminute);
                  out.write(" min");
                }
                out.write("\n                \t\t    ");
                if (dtbeginsecond > 0) {
                  out.print(dtbeginsecond);
                  out.write(" sec");
                }
                out.write("\n                \t\t    ");
                if (dtbeginmillisecond > 0) {
                  out.print(dtbeginmillisecond);
                  out.write(" ms");
                }
                out.write("\n                    \t\t");
                out.write(
                    "</b>\n                    \t\tthe system will continue to poll downed nodes at a\n                    \t\t");
                out.write("<b>\n                \t\t    ");
                if (dtintervalday > 0) {
                  out.print(dtintervalday);
                  out.write(" day");
                }
                out.write("\n                \t\t    ");
                if (dtintervalhour > 0) {
                  out.print(dtintervalhour);
                  out.write(" hr");
                }
                out.write("\n                \t\t    ");
                if (dtintervalminute > 0) {
                  out.print(dtintervalminute);
                  out.write(" min");
                }
                out.write("\n                \t\t    ");
                if (dtintervalsecond > 0) {
                  out.print(dtintervalsecond);
                  out.write(" sec");
                }
                out.write("\n                \t\t    ");
                if (dtintervalmillisecond > 0) {
                  out.print(dtintervalmillisecond);
                  out.write(" ms");
                }
                out.write("\n                            ");
                out.write(
                    "</b>\n                            interval.\n                            ");
              }
              out.write("\n                        ");
              out.write("</td>\n                                   ");
              if (i == (ds.length - 2)) {
                out.write("\n                                   ");
              } else {
                out.write("\n                                      ");
                out.write("<td class=\"tableHeader\">&nbsp;");
                out.write("</td>\n                                   ");
              }
              out.write("\n                \t\t");
            }
            out.write("\n            \t\t");
            out.write("</tr>\n            \t\t");
          }
        }
      }

      out.write("\n        ");
      out.write("<!--\n    \t");
      out.write("<TR>\n        \t");
      out.write("<TD align=\"center\">");
      out.write("<INPUT name=\"dtbegin\" type=\"text\" value=\"");
      out.print(begin);
      out.write("\" readonly>");
      out.write("</TD>\n        \t");
      out.write("<TD align=\"center\">");
      out.write("<INPUT name=\"dtend\" type=\"text\" value=\"\">");
      out.write("</TD>\n        \t");
      out.write("<TD align=\"center\">");
      out.write("<INPUT name=\"dtinterval\" type=\"text\" value=\"\">");
      out.write("</TD>\n        \t");
      out.write("<TD align=\"center\">");
      out.write("<INPUT name=\"dtdel\" type=\"checkbox\" value=\"true\" disabled>");
      out.write("</TD>\n        \t");
      out.write("<TD align=\"center\">");
      out.write("<a HREF=\"javascript:addDowntime()\" title=\"Add Downtime Model\">Add Downtime");
      out.write("</a>");
      out.write("</TD>\n    \t");
      out.write("</TR>\n    \t-->\n    \t");

      long dtbeginday = 0;
      long dtbeginhour = 0;
      long dtbeginminute = 0;
      long dtbeginsecond = 0;
      long dtbeginmillisecond = 0;

      long dtendday = 0;
      long dtendhour = 0;
      long dtendminute = 0;
      long dtendsecond = 0;
      long dtendmillisecond = 0;

      long dtintervalday = 0;
      long dtintervalhour = 0;
      long dtintervalminute = 0;
      long dtintervalsecond = 0;
      long dtintervalmillisecond = 0;

      if (addbegin > 0) {
        dtbeginday = addbegin / daymilli;
        addbegin = addbegin - (dtbeginday * daymilli);
      }
      if (addbegin > 0) {
        dtbeginhour = addbegin / hourmlli;
        addbegin = addbegin - (dtbeginhour * hourmlli);
      }
      if (addbegin > 0) {
        dtbeginminute = addbegin / minutemilli;
        addbegin = addbegin - (dtbeginminute * minutemilli);
      }
      if (addbegin > 0) {
        dtbeginsecond = addbegin / secondmilli;
        addbegin = addbegin - (dtbeginsecond * secondmilli);
      }
      if (addbegin > 0) {
        dtbeginmillisecond = addbegin;
      }

      out.write("\n    \t");
      out.write("<tr class=\"tableRowLight\">\n        \t");
      out.write("<td>\n        \t  ");
      out.write("<input type=\"hidden\" name=\"dtbeginday\" value=\"");
      out.print(dtbeginday);
      out.write("\">\n        \t  ");
      out.write("<input type=\"hidden\" name=\"dtbeginhour\" value=\"");
      out.print(dtbeginhour);
      out.write("\">\n        \t  ");
      out.write("<input type=\"hidden\" name=\"dtbeginminute\" value=\"");
      out.print(dtbeginminute);
      out.write("\">\n        \t  ");
      out.write("<input type=\"hidden\" name=\"dtbeginsecond\" value=\"");
      out.print(dtbeginsecond);
      out.write("\">\n        \t  ");
      out.write("<input type=\"hidden\" name=\"dtbeginmillisecond\" value=\"");
      out.print(dtbeginmillisecond);
      out.write("\">\n        \t    ");
      out.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Days: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.print(dtbeginday);
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Hours: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.print(dtbeginhour);
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Minutes: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.print(dtbeginminute);
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Seconds: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.print(dtbeginsecond);
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Milliseconds: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.print(dtbeginmillisecond);
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t    ");
      out.write("</table>\n        \t");
      out.write("</td>\n        \t");
      out.write("<td>\n        \t    ");
      out.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Days: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtendday\">\n\t\t        ");
      for (int i = 0; i <= 365; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtendday == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Hours: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtendhour\">\n\t\t        ");
      for (int i = 0; i < 24; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtendhour == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Minutes: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtendminute\">\n\t\t        ");
      for (int i = 0; i < 60; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtendminute == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Seconds: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtendsecond\">\n\t\t        ");
      for (int i = 0; i < 60; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtendsecond == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Milliseconds: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtendmillisecond\">\n\t\t        ");
      for (int i = 0; i < 1000; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtendmillisecond == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t    ");
      out.write("</table>\n\n         \t");
      out.write("</td>\n        \t");
      out.write("<td>\n        \t    ");
      out.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Days: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtintervalday\">\n\t\t        ");
      for (int i = 0; i <= 365; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtintervalday == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Hours: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtintervalhour\">\n\t\t        ");
      for (int i = 0; i < 24; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtintervalhour == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Minutes: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtintervalminute\">\n\t\t        ");
      for (int i = 0; i < 60; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtintervalminute == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Seconds: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtintervalsecond\">\n\t\t        ");
      for (int i = 0; i < 60; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtintervalsecond == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t        ");
      out.write("<tr class=\"tableRowLight\">\n        \t            ");
      out.write("<td nowrap>Milliseconds: ");
      out.write("</td>\n        \t            ");
      out.write("<td nowrap>");
      out.write("<select name=\"dtintervalmillisecond\">\n\t\t        ");
      for (int i = 0; i < 1000; i++) {
        out.write("\n\t\t            ");
        out.write("<option value=");
        out.print(i);
        out.write(" ");
        if (dtintervalmillisecond == i) {
          out.write("selected");
        }
        out.write(">");
        out.print(df3digit.format(i));
        out.write("\n                ");
      }
      out.write("\n\t\t      ");
      out.write("</select>");
      out.write("</td>\n        \t        ");
      out.write("</tr>\n        \t    ");
      out.write("</table>\n        \t");
      out.write("</td>\n         \t");
      out.write("<!--\n        \t");
      out.write("<TD align=\"center\">\n        \t");
      out.write("<INPUT name=\"dtdel\" type=\"checkbox\" value=\"true\" disabled>\n        \t");
      out.write("</TD>\n        \t-->\n        \t");
      out.write("<td align=\"center\" nowrap>");
      out.write("<a href=\"javascript:addDowntime()\" title=\"Add Downtime Model\">Add Downtime");
      out.write("</a>");
      out.write("</td>\n    ");
      out.write("</tr>\n    ");
      out.write("<tr class=\"tableRowLight\">\n        ");
      out.write("<td class=\"tableText\" colspan=\"4\">");
      out.write(
          "<img src=\"/wt-portal/images/spacers/spacer.gif\" height=\"4\" width=\"10\" border=\"0\" alt=\"WebTelemetry\">");
      out.write("</td>\n    ");
      out.write("</tr>\n     ");
      out.write("<tr>\n        ");
      out.write("<td colspan=\"4\">");
      out.write("<br />\n        ");
      out.write("<a href=\"javascript:restoreDefaultDowntime()\">");
      out.write(
          "<img src=\"/wt-portal/images/buttons/btn_restore_defaults.gif\" border=\"0\" alt=\"Restore Defaults\">");
      out.write("</a>\n        \n        ");
      out.write("<!--");
      out.write(
          "<input type=\"submit\" name=\"button\" onclick=\"return restoreDefaultDowntime()\" value=\"Restore Defaults\" title=\"Restore Downtime Model Defaults\">-->");
      out.write("<br />\n        ");
      out.write("</td>\n    ");
      out.write("</tr>\n");
      out.write("</table>\n");
      out.write("</form>\n");
      out.write("<!-- BEGIN FRAMING TABLE:close tags-->\n\t\t");
      out.write("</td>\n\t");
      out.write("</tr>\n");
      out.write("</table>\n");
      out.write("<!-- END FRAMING TABLE:close tags-->\n");
      out.write("<p>\n");
      JspRuntimeLibrary.include(
          request, response, "/includes/footer.jsp" + "?" + "location=" + "admin", out, false);
      out.write("\n\n  ");
      out.write("</body>\n");
      out.write("</html>\n");
    } catch (Throwable t) {
      out = _jspx_out;
      if (out != null && out.getBufferSize() != 0) out.clearBuffer();
      if (pageContext != null) pageContext.handlePageException(t);
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
    }
  }
 /**
  * Reads a given line and decides what to do with it depending on the contents of the line Calls
  * find, add, or sell depending on what the line says
  *
  * @param line - a single command
  */
 public void parse(String line) {
   // Splits the input by commas into an array for easier parsing
   String[] delimited = line.split(",");
   AudioFormat audioFormat = null;
   try {
     if (delimited[0].equals(MusicStoreInventory.ADD)) { // ADD command
       // Creates a new CD, Vinyl, or Cassette depending on the input
       if (delimited[4].equals("CD")) {
         audioFormat = new CD(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("VINYL")) {
         audioFormat =
             new Vinyl(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("CASSETTE")) {
         audioFormat =
             new Cassette(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else {
         // If it's not any of the three types, throws an exception
         throw new IllegalArgumentException("Invalid input: not a valid record type (ADD).");
       }
       // Adds the item to the inventory
       this.addItem(
           audioFormat,
           this.convertStringToInt(delimited[5]),
           this.convertStringToDouble(delimited[6]));
     } else if (delimited[0].equals(MusicStoreInventory.SELL)) { // SELL command
       // Creates a new CD, Vinyl, or Cassette depending on the input
       if (delimited[4].equals("CD")) {
         audioFormat = new CD(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("VINYL")) {
         audioFormat =
             new Vinyl(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else if (delimited[4].equals("CASSETTE")) {
         audioFormat =
             new Cassette(delimited[1], delimited[2], this.convertStringToInt(delimited[3]));
       } else {
         // If it's not any of the three types, throws an exception
         throw new IllegalArgumentException("Invalid input: not a valid record type (SELL)");
       }
       // Sells the item
       this.sellItem(audioFormat, this.convertStringToInt(delimited[5]));
     } else if (delimited[0].equals(MusicStoreInventory.FIND)) { // FIND command
       // There should only be 2 parameters for a FIND command
       if (delimited.length != 2) {
         throw new IllegalArgumentException("Invalid input: wrong number of commands (FIND).");
       }
       this.findItemsByArtist(delimited[1]);
     } else {
       // The only thing that can remain is the initial input of data, which has exactly 6 commands
       if (delimited.length != 6) {
         throw new IllegalArgumentException("Invalid input: wrong number of commands.");
       }
       // Creates a new CD, Vinyl, or Cassette depending on the input
       if (delimited[3].equals("CD")) {
         audioFormat = new CD(delimited[0], delimited[1], this.convertStringToInt(delimited[2]));
       } else if (delimited[3].equals("VINYL")) {
         audioFormat =
             new Vinyl(delimited[0], delimited[1], this.convertStringToInt(delimited[2]));
       } else if (delimited[3].equals("CASSETTE")) {
         audioFormat =
             new Cassette(delimited[0], delimited[1], this.convertStringToInt(delimited[2]));
       } else {
         // If it's not any of the three types, throws an exception
         throw new IllegalArgumentException("Invalid input: not a valid record type (ADD)");
       }
       // Adds the item to the inventory
       this.addItem(
           audioFormat,
           this.convertStringToInt(delimited[4]),
           this.convertStringToDouble(delimited[5]));
     }
   } catch (NumberFormatException e) {
     System.out.println("Invalid input: price or year is not valid.");
     e.printStackTrace();
   } catch (IllegalArgumentException | NullPointerException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 14
0
  /**
   * Read command line input and load config file, set config value to the instance of DotsConfig.
   */
  public static void loadConfig(String[] args) {
    int i;
    String configFileName = "./config.ini";
    String tmpString;
    String value;
    File configFile = null;
    StringTokenizer stk = null;
    Properties props = new Properties();
    String propString;

    /* Read command line input */
    for (i = 0; i < args.length; ) {
      String option = args[i++];

      if (option.equals("-config")) {
        configFileName = args[i++];
      } else if (option.equals("-case")) {
        TESTCASENAME = args[i++];
      } else if (option.equals("-?") || option.equals("-help")) {
        System.out.println("Usage:Dots [-option]");
        System.out.println("\t\t-config				Config file name");
        System.out.println("\t\t-case				Test case name");
        System.out.println("\t\t-help				Print this message");
        System.exit(0);
      } else {
        System.out.println("Expected Option Is Not Found!");
        System.out.println("Usage:	Dots -config [config file] -case [case name]");
        System.exit(0);
      }
    }

    TESTCASENAME = TESTCASENAME.toUpperCase();

    /* Check test case name */
    if (TESTCASENAME.equals("")) {
      System.out.println("Testcase Name Must Be Specified!");
      System.out.println("Usage:	Dots -config [config file] -case [case name]");
      System.exit(0);
    }
    if (!(TESTCASENAME.equals("BTCJ1")
        || TESTCASENAME.equals("BTCJ2")
        || TESTCASENAME.equals("BTCJ3")
        || TESTCASENAME.equals("BTCJ4")
        || TESTCASENAME.equals("BTCJ5")
        || TESTCASENAME.equals("BTCJ6")
        || TESTCASENAME.equals("BTCJ7")
        || TESTCASENAME.equals("BTCJ8")
        || TESTCASENAME.equals("ATCJ1")
        || TESTCASENAME.equals("ATCJ2"))) {
      System.out.println("Testcase Name Is Not Correct!");
      System.exit(0);
    }

    /* Load config file and set DotsConfig value */
    try {
      props.load(new FileInputStream(configFileName));

      if ((propString = props.getProperty("DURATION")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option DURATION Is Not Found!");
          System.exit(1);
        }
        stk = new StringTokenizer(propString, ":");
        if (stk.countTokens() > 1) {
          value = stk.nextToken().trim();
          tmpString = stk.nextToken().trim();
          DotsConfig.DURATION = Integer.parseInt(value) * 60 + Integer.parseInt(tmpString);
        } else DotsConfig.DURATION = Integer.parseInt(propString.trim()) * 60;
        if (DotsConfig.DURATION <= 1) {
          System.out.println("DURATION value is too small(<=1)!");
          System.exit(1);
        }
      } else {
        System.out.println("Expected Config File Option DURATION Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("CONCURRENT_CONNECTIONS")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option CONCURRENT_CONNECTIONS Is Not Found!");
          System.exit(1);
        }
        DotsConfig.CONNECTIONS = Integer.parseInt(propString.trim());
        if (DotsConfig.CONNECTIONS < 1) {
          System.out.println("CONCURRENT_CONNECTIONS value is too small(<1)!");
          System.exit(1);
        }
      } else {
        System.out.println("Expected Config File Option CONCURRENT_CONNECTIONS Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("CPU_TARGET")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option CPU_TARGET Is Not Found!");
          System.exit(1);
        }
        DotsConfig.CPU_TARGET = Integer.parseInt(propString.trim());
        if (DotsConfig.CPU_TARGET <= 10) {
          System.out.println("CPU_TARGET value is too small(<10)!");
          System.exit(1);
        }
        if (DotsConfig.CPU_TARGET > 100) {
          System.out.println("CPU_TARGET value is too large(>100)!");
          System.exit(1);
        }
      } else {
        System.out.println("Expected Config File Option CPU_TARGET Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("LOG_DIR")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option LOG_DIR Is Not Found!");
          System.exit(1);
        }
        DotsConfig.LOG_DIR = propString.trim();
      } else {
        System.out.println("Expected Config File Option LOG_DIR Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("AUTO_MODE")) != null) {
        if (propString.trim().equalsIgnoreCase("yes")) DotsConfig.AUTO_MODE = true;
        else if (propString.trim().equalsIgnoreCase("no")) DotsConfig.AUTO_MODE = false;
        else {
          System.out.println("AUTO_MODE format is not correct!");
          System.exit(1);
        }
      } else {
        System.out.println("Expected Config File Option AUTO_MODE Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("SUMMARY_INTERVAL")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option SUMMARY_INTERVAL Is Not Found!");
          System.exit(1);
        }
        DotsConfig.SUMMARY_INTERVAL = Integer.parseInt(propString.trim());
        if (DotsConfig.SUMMARY_INTERVAL < 1) {
          System.out.println("SUMMARY_INTERVAL value is too small(<1)!");
          System.exit(1);
        }
      } else {
        System.out.println("Expected Config File Option SUMMARY_INTERVAL Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("UserID")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option UserID Is Not Found!");
          System.exit(1);
        }
        DotsConfig.DB_UID = propString.trim();
      } else {
        System.out.println("Expected Config File Option UserID Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("Password")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option Password Is Not Found!");
          System.exit(1);
        }
        DotsConfig.DB_PASSWD = propString.trim();
      } else {
        System.out.println("Expected Config File Option Password Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("DriverClass")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option DriverClass Is Not Found!");
          System.exit(1);
        }
        DotsConfig.DRIVER_CLASS_NAME = propString.trim();
      } else {
        System.out.println("Expected Config File Option DriverClass Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("URL")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option URL Is Not Found!");
          System.exit(1);
        }
        DotsConfig.URL = propString.trim();
      } else {
        System.out.println("Expected Config File Option URL Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("SERVER_IP")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option SERVER_IP Is Not Found!");
          System.exit(1);
        }
        DotsConfig.SERVER_IP = propString.trim();
      } else {
        System.out.println("Expected Config File Option SERVER_IP Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("SERVER_PORT")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option SERVER_PORT Is Not Found!");
          System.exit(1);
        }
        DotsConfig.PERF_SVR_PORT = propString.trim();
      } else {
        System.out.println("Expected Config File Option SERVER_PORT Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("MAX_ROWS")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Expected Config File Option MAX_ROWS Is Not Found!");
          System.exit(1);
        }
        DotsConfig.MAX_ROWS = Integer.parseInt(propString.trim());
        if (DotsConfig.MAX_ROWS <= 1) {
          System.out.println("MAX_ROWS value is too small(<=1)!");
          System.exit(1);
        }
      } else {
        System.out.println("Expected Config File Option MAX_ROWS Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("MAX_LOGFILESIZE")) != null) {
        if (propString.trim().length() <= 0) {
          System.out.println("Excepted Config File Option MAX_LOGFILESIZE Is Not Found!");
          System.exit(1);
        }
        DotsConfig.MAX_LOGFILESIZE = Integer.parseInt(propString.trim());
        if (DotsConfig.MAX_LOGFILESIZE <= 102400) {
          System.out.println("MAX_LOGFILESIZE value is too small(<=100K)");
          System.exit(1);
        }
        if (DotsConfig.MAX_LOGFILESIZE > 1073741824) { // 1G
          System.out.println("MAX_LOGFILESIZE value is too large(>1G)");
          System.exit(1);
        }
      } else {
        System.out.println("Excepted Config File Option MAX_LOGFILESIZE Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("CREATIONINTERVAL")) != null) {
        DotsConfig.INTERVAL = Integer.parseInt(propString.trim());
        if (DotsConfig.INTERVAL > 5) {
          System.out.println("CREATIONINTERVAL value is too large(>5min)");
          System.exit(1);
        }
        if (DotsConfig.INTERVAL < 1) {
          System.out.println("CREATIONPINTERVAL value is too small(<1min");
          System.exit(1);
        }
      } else {
        System.out.println("Excepted Config File Option CREATIONINTERVAL Is Not Found!");
        System.exit(1);
      }

      if ((propString = props.getProperty("RUN_AUTO")) != null) {
        if (propString.trim().equalsIgnoreCase("yes")) DotsConfig.RUN_AUTO = true;
        else if (propString.trim().equalsIgnoreCase("no")) DotsConfig.RUN_AUTO = false;
        else {
          System.out.println("RUN_AUTO format is not correct!");
          System.exit(1);
        }
      } else {
        DotsConfig.RUN_AUTO = false;
      }

      DotsConfig.THRDGRP = new ThreadGroup("DBAccess");
      DotsConfig.CPU_USAGE = 0;
      DotsConfig.QUERYCOUNT = 0;
      DotsConfig.INSERTCOUNT = 0;
      DotsConfig.DELETECOUNT = 0;
      DotsConfig.UPDATECOUNT = 0;
      DotsConfig.FAILEDCOUNT = 0;
    } catch (NumberFormatException e) {
      System.out.println("Config File Number Format Error!");
      e.printStackTrace();
      System.exit(1);
    } catch (IOException e) {
      System.out.println("Read Config File Error!");
      e.printStackTrace();
      System.exit(1);
    }
  }
Ejemplo n.º 15
0
  // This method gets called from a method in the Hand object (startStreet())
  // In that method, each player is looped through to act();
  public synchronized int act(
      int minimumBet, int pot, HeadsUpHand hand, HeadsUpPokerGame game, int streetIn) {

    boolean isCorrect = false;
    String action;
    int betSize = minimumBet;
    if (!this.folded && !this.isAllIn) {
      while (!isCorrect) {
        // Output board
        hand.printBoard(game, streetIn, game.handNumber, this);
        // Output hand and player stats
        addMessage(this.toString(game));
        addMessage("Bet/Check/Call/Fold");
        send();
        clearMessages();
        action = receive();
        // Checks what action user inputs
        if (action.equalsIgnoreCase("Bet")) {
          while (true) {
            // Output board
            hand.printBoard(game, streetIn, game.handNumber, this);
            // Output hand and player stats
            addMessage(this.toString(game));
            try {
              addMessage("Size");
              send();
              clearMessages();
              // Requires exception?
              try {
                betSize = Integer.parseInt(receive());
              } catch (NumberFormatException e) {
                e.printStackTrace();
              }

              // For headsup this is fine since there isn't a scenario where your betsize is
              // larger than how much the other player has and also less that what you have
              if (betSize > game.players.get(otherPlayerID).getMoney()) {
                // Only allow player to bet how much other play has
                betSize = game.players.get(otherPlayerID).getMoney();
                // Any additional bet is total (don't have to remember previous bet)
                this.spendMoney(betSize - streetMoney);
                hand.addToPot(betSize - streetMoney);
                // Total streetmoney becomes betsize
                streetMoney = betSize;
                isCorrect = true;
                game.players.get(otherPlayerID).addMessage(name + " puts you all in");
                // Increase all in counter so that
                // when other player calls further actions are skipped
                hand.increaseAllInCounter();
              } else if (money <= betSize) {
                // If betsize is greater than money, player is all in
                betSize = money;
                this.spendMoney(betSize);
                hand.addToPot(betSize);
                streetMoney = betSize;
                isAllIn = true;
                hand.increaseAllInCounter();
                isCorrect = true;
                if (streetIn != 12) {
                  game.players.get(otherPlayerID).addMessage(name + " is all in");
                }
              } else if (betSize < 2 * minimumBet || betSize == 0) {
                addMessage("Illegal bet size");
                // Reset betsize to what was previously bet (miniumum bet)
                betSize = minimumBet;
              } else {
                // Any additional bet is total (don't have to remember previous bet)
                this.spendMoney(betSize - streetMoney);
                hand.addToPot(betSize - streetMoney);
                // Total streetmoney becomes betsize
                streetMoney = betSize;
                isCorrect = true;
                game.players.get(otherPlayerID).addMessage(name + " bet " + betSize);
              }
              break;
            } catch (InputMismatchException e) {
              addMessage("Not a number");
              in.next();
              continue;
            }
          }
        }
        // we need a way for BB to check b/c minbet is still > 0 for him
        else if (action.equalsIgnoreCase("Check")) {
          if (minimumBet - streetMoney > 0) {
            addMessage("You cannot check when the pot is raised");
          } else {
            isCorrect = true;
            betSize = 0;
            game.players.get(otherPlayerID).addMessage(name + " checked");
          }
        } else if (action.equalsIgnoreCase("Call")) {
          if (minimumBet == 0 || minimumBet - streetMoney == 0) {
            addMessage("You cannot call when there is no bet");
          } else if (money <= minimumBet) {
            betSize = money;
            this.spendMoney(betSize);
            hand.addToPot(betSize);
            isAllIn = true;
            // If you call all in then hand must end
            // Add 1 to AllInCounter in order to skip further actions == players.size() in Hand
            // class
            // Betting all in is different since other player still has to act
            hand.increaseAllInCounter();
            isCorrect = true;
            if (streetIn != 12) {
              game.players.get(otherPlayerID).addMessage(name + " is all in");
            }
          } else {
            this.spendMoney(minimumBet - streetMoney);
            hand.addToPot(minimumBet - streetMoney);
            isCorrect = true;
            betSize = minimumBet;
            game.players.get(otherPlayerID).addMessage(name + " called " + betSize);
          }
        } else if (action.equalsIgnoreCase("Fold")) {
          this.fold();
          isCorrect = true;
          betSize = 0;
        } else {
          addMessage("Incorrect action, please try again");
        }
      }
    } else {
      betSize = 0;
    }
    return betSize;
  }