Esempio n. 1
0
 public static void main(String[] args) {
   int n = 0;
   int m = 0;
   while (true) {
     try {
       BufferedReader sisse = new BufferedReader(new InputStreamReader(System.in));
       System.out.println("V2ljumiseks vajutage ctrl-C");
       System.out.print("Laste arv: ");
       String s = sisse.readLine();
       n = Integer.parseInt(s);
       if (n < 0) throw new IllegalArgumentException(String.valueOf(n));
       System.out.print("6unte arv: ");
       s = sisse.readLine();
       m = Integer.parseInt(s);
       if (m < 0) throw new IllegalArgumentException(String.valueOf(m));
       System.out.println(
           "Igale lapsele "
               + String.valueOf(m / n)
               + " 6una ja "
               + String.valueOf(m % n)
               + " j22b yle");
     } catch (NumberFormatException e) {
       System.out.println("Ei ole arv: " + e.toString());
     } catch (ArithmeticException e) {
       System.out.println("Aritmeetikakatkestus: " + e.toString());
     } catch (Exception muu) {
       System.out.println("Probleem: " + muu.toString());
     } finally {
       System.out.println("n = " + n + "  m = " + m);
     }
   }
 } // main
  /**
   * 数据解包,解包顺序参见<A href ={@docRoot}/dataStructure/tb.html#PrpLECRecommendation>历史记账凭证主表信息</A>表字段
   *
   * @param: strMessage String 包含一条纪录数据的字符串
   * @return: boolean
   */
  public boolean decode(String strMessage) {
    try {
      recommend = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 1, SysConst.PACKAGESPILTER);
      recommended = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 2, SysConst.PACKAGESPILTER);
      sendtimes =
          new Integer(ChgData.chgNumericStr(StrTool.getStr(strMessage, 3, SysConst.PACKAGESPILTER)))
              .intValue();
      success = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 4, SysConst.PACKAGESPILTER);
      registered = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 5, SysConst.PACKAGESPILTER);
      field1 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 6, SysConst.PACKAGESPILTER);
      field2 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 7, SysConst.PACKAGESPILTER);
      field3 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 8, SysConst.PACKAGESPILTER);
      makedate = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 9, SysConst.PACKAGESPILTER);
      maketime = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 10, SysConst.PACKAGESPILTER);
      modifydate = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 11, SysConst.PACKAGESPILTER);
      modifytime = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 12, SysConst.PACKAGESPILTER);
    } catch (NumberFormatException ex) {
      // @@错误处理
      CError tError = new CError();
      tError.moduleName = "LECRecommendationSchema";
      tError.functionName = "decode";
      tError.errorMessage = ex.toString();
      this.mErrors.addOneError(tError);

      return false;
    }
    return true;
  }
Esempio n. 3
0
 /**
  * @param v
  * @exception DicomException
  */
 public void addValue(String v) throws DicomException {
   short shortValue = 0;
   try {
     shortValue = (short) Integer.parseInt(v);
   } catch (NumberFormatException e) {
     throw new DicomException(e.toString());
   }
   addValue(shortValue);
 }
Esempio n. 4
0
 /**
  * @param v
  * @exception DicomException
  */
 public void addValue(String v) throws DicomException {
   flushCachedCopies();
   double doubleValue = 0;
   try {
     doubleValue = Double.parseDouble(v);
   } catch (NumberFormatException e) {
     throw new DicomException(e.toString());
   }
   addValue(doubleValue);
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 public void message(String s) {
   if (firstLine == null) firstLine = s;
   else {
     StringTokenizer st = new StringTokenizer(s, " ");
     try {
       st.nextToken();
       st.nextToken();
       st.nextToken();
       size = (new Integer(st.nextToken().trim())).longValue();
     } catch (NoSuchElementException e) {
       exception = new RunnerException(e.toString());
     } catch (NumberFormatException e) {
       exception = new RunnerException(e.toString());
     }
   }
 }
  /**
   * 数据解包,解包顺序参见<A href ={@docRoot}/dataStructure/tb.html#PrpSearchRecord>历史记账凭证主表信息</A>表字段
   *
   * @param: strMessage String 包含一条纪录数据的字符串
   * @return: boolean
   */
  public boolean decode(String strMessage) {
    try {
      tradeNo = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 1, SysConst.PACKAGESPILTER);
      contNo = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 2, SysConst.PACKAGESPILTER);
      userCode = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 3, SysConst.PACKAGESPILTER);
      name = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 4, SysConst.PACKAGESPILTER);
      gender = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 5, SysConst.PACKAGESPILTER);
      birthday =
          fDate.getDate(
              StrTool.getStr(StrTool.GBKToUnicode(strMessage), 6, SysConst.PACKAGESPILTER));
      province = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 7, SysConst.PACKAGESPILTER);
      city = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 8, SysConst.PACKAGESPILTER);
      mobile = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 9, SysConst.PACKAGESPILTER);
      userIDType = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 10, SysConst.PACKAGESPILTER);
      userIDNo = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 11, SysConst.PACKAGESPILTER);
      riskname = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 12, SysConst.PACKAGESPILTER);
      riskcode = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 13, SysConst.PACKAGESPILTER);
      userState = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 14, SysConst.PACKAGESPILTER);
      userSource = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 15, SysConst.PACKAGESPILTER);
      field1 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 16, SysConst.PACKAGESPILTER);
      field2 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 17, SysConst.PACKAGESPILTER);
      field3 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 18, SysConst.PACKAGESPILTER);
      field4 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 19, SysConst.PACKAGESPILTER);
      field5 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 20, SysConst.PACKAGESPILTER);
      field6 = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 21, SysConst.PACKAGESPILTER);
      searchDate =
          fDate.getDate(
              StrTool.getStr(StrTool.GBKToUnicode(strMessage), 22, SysConst.PACKAGESPILTER));
      searchTime = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 23, SysConst.PACKAGESPILTER);
      makedate =
          fDate.getDate(
              StrTool.getStr(StrTool.GBKToUnicode(strMessage), 24, SysConst.PACKAGESPILTER));
      maketime = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 25, SysConst.PACKAGESPILTER);
    } catch (NumberFormatException ex) {
      // @@错误处理
      CError tError = new CError();
      tError.moduleName = "SearchRecordSchema";
      tError.functionName = "decode";
      tError.errorMessage = ex.toString();
      this.mErrors.addOneError(tError);

      return false;
    }
    return true;
  }
  /**
   * 数据解包,解包顺序参见<A href ={@docRoot}/dataStructure/tb.html#PrpLEPRiskDuty>历史记账凭证主表信息</A>表字段
   *
   * @param: strMessage String 包含一条纪录数据的字符串
   * @return: boolean
   */
  public boolean decode(String strMessage) {
    try {
      riskCode = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 1, SysConst.PACKAGESPILTER);
      riskVer = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 2, SysConst.PACKAGESPILTER);
      dutyCode = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 3, SysConst.PACKAGESPILTER);
      choFlag = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 4, SysConst.PACKAGESPILTER);
      specFlag = StrTool.getStr(StrTool.GBKToUnicode(strMessage), 5, SysConst.PACKAGESPILTER);
    } catch (NumberFormatException ex) {
      // @@错误处理
      CError tError = new CError();
      tError.moduleName = "LEPRiskDutySchema";
      tError.functionName = "decode";
      tError.errorMessage = ex.toString();
      this.mErrors.addOneError(tError);

      return false;
    }
    return true;
  }
Esempio n. 9
0
  /**
   * If we know in advance that the table is numeric, can optimize a lot... For example, on 9803 x
   * 294 table, TableFileLoader.readNumeric takes 6s compared to 12s for WekaMine readFromTable.
   */
  public static Instances readNumeric(String fileName, String relationName, String delimiter)
      throws Exception {

    int numAttributes = FileUtils.fastCountLines(fileName) - 1; // -1 exclude heading.
    String[] attrNames = new String[numAttributes];

    // Read the col headings and figure out the number of columns in the table..
    BufferedReader reader = new BufferedReader(new FileReader(fileName), 4194304);
    String line = reader.readLine();
    String[] instanceNames = parseColNames(line, delimiter);
    int numInstances = instanceNames.length;

    System.err.print("reading " + numAttributes + " x " + numInstances + " table..");

    // Create an array to hold the data as we read it in...
    double dataArray[][] = new double[numAttributes][numInstances];

    // Populate the matrix with values...
    String valToken = "";
    try {
      int rowIdx = 0;
      while ((line = reader.readLine()) != null) {

        String[] tokens = line.split(delimiter, -1);
        attrNames[rowIdx] = tokens[0].trim();
        for (int colIdx = 0; colIdx < (tokens.length - 1); colIdx++) {
          valToken = tokens[colIdx + 1];
          double value;

          if (valToken.equals("null")) {
            value = Instance.missingValue();
          } else if (valToken.equals("?")) {
            value = Instance.missingValue();
          } else if (valToken.equals("NA")) {
            value = Instance.missingValue();
          } else if (valToken.equals("")) {
            value = Instance.missingValue();
            // }else value = DoubleParser.lightningParse(valToken); // faster double parser with
            // MANY assumptions
          } else value = Double.parseDouble(valToken);
          dataArray[rowIdx][colIdx] = value;
        }
        rowIdx++;
      }
    } catch (NumberFormatException e) {
      System.err.println(e.toString());
      System.err.println("Parsing line: " + line);
      System.err.println("Parsing token: " + valToken);
    }

    // Set up attributes, which for colInstances will be the rowNames...
    FastVector atts = new FastVector();
    for (int a = 0; a < numAttributes; a++) {
      atts.addElement(new Attribute(attrNames[a]));
    }

    // Create Instances object..
    Instances data = new Instances(relationName, atts, 0);
    data.setRelationName(relationName);

    System.err.print("creating instances..");

    // System.err.println("DEBUG: numAttributes "+numAttributes);

    /** ***** CREATE INSTANCES ************* */
    // Fill the instances with data...
    // For each instance...
    for (int c = 0; c < numInstances; c++) {
      double[] vals =
          new double[data.numAttributes()]; // Even nominal values are stored as double pointers.

      for (int r = 0; r < numAttributes; r++) {
        double val = dataArray[r][c];
        vals[r] = val;
      }
      // Add the a newly minted instance with those attribute values...
      data.add(new Instance(1.0, vals));
    }

    // System.err.println("DEBUG: data.numInstances: "+data.numInstances());
    // System.err.println("DEBUG: data.numAttributes: "+data.numAttributes());
    // System.err.println("DEBUG: data.relationNAme"+data.relationName());
    System.err.print("add feature names..");

    /** ***** ADD FEATURE NAMES ************* */
    // takes basically zero time... all time is in previous 2 chunks.
    Instances newData = new Instances(data);
    newData.insertAttributeAt(new Attribute("ID", (FastVector) null), 0);
    int attrIdx = newData.attribute("ID").index(); // Paranoid... should be 0

    for (int c = 0; c < numInstances; c++) {
      newData.instance(c).setValue(attrIdx, instanceNames[c]);
    }
    data = newData;

    // System.err.println("DEBUG: data.numInstances: "+data.numInstances());
    // System.err.println("DEBUG: data.numAttributes: "+data.numAttributes());

    return (data);
  }