@Test
 public void replaceAll() throws Exception {
   assertEquals(
       "my name is Bob, Bob is my name",
       StringUtil.replaceAll("my name is $name, $name is my name", "$name", "Bob"));
   assertEquals("_$namex_", StringUtil.replaceAll("_$name_", "$name", "$namex"));
 }
 /**
  * find the smells related to one file, and update file object
  *
  * @param issue
  * @param filename
  */
 public static void addSmell2File(JSONObject issue, JSONObject file, String dir) {
   String version = (String) issue.get("affect");
   if (version == null || version.equals("")) {
     return;
   }
   version = StringUtil.formatIssueVersion(version);
   String extractedName = StringUtil.dir2pkg(dir);
   for (int i = 0; i < smells.size(); i++) {
     JSONObject smell = (JSONObject) smells.get(i);
     if (version.equals(smell.get("version"))) {
       JSONArray smellsPerVersion = (JSONArray) smell.get("smells");
       for (int j = 0; j < smellsPerVersion.size(); j++) {
         JSONObject smellPerVersion = (JSONObject) smellsPerVersion.get(j);
         String classname = (String) smellPerVersion.get("classname");
         // found the smells related to particular file
         if (classname.contains(extractedName)) {
           // add the smells to this file!!
           JSONObject tmpSmell = null;
           if (file.containsKey("smells")) {
             tmpSmell = (JSONObject) file.get("smells");
             int tmpSmellNum = Integer.parseInt(smellPerVersion.get("bco").toString());
             if (tmpSmellNum != 0) {
               tmpSmell.put("Concern_Overload", tmpSmellNum);
             }
             // exclude dependency cycle for now
             // tmpSmell.put("bdc", smellPerVersion.get("bdc"));
             tmpSmellNum = Integer.parseInt(smellPerVersion.get("buo").toString());
             if (tmpSmellNum != 0) {
               tmpSmell.put("Link_Overload", tmpSmellNum);
             }
             tmpSmellNum = Integer.parseInt(smellPerVersion.get("spf").toString());
             if (tmpSmellNum != 0) {
               tmpSmell.put("Scattered_Parasitic_Functionality", tmpSmellNum);
             }
           } else {
             tmpSmell = new JSONObject();
             int tmpSmellNum = Integer.parseInt(smellPerVersion.get("bco").toString());
             if (tmpSmellNum != 0) {
               tmpSmell.put("Concern_Overload", tmpSmellNum);
             }
             // exclude dependency cycle for now
             // tmpSmell.put("bdc", smellPerVersion.get("bdc"));
             tmpSmellNum = Integer.parseInt(smellPerVersion.get("buo").toString());
             if (tmpSmellNum != 0) {
               tmpSmell.put("Link_Overload", tmpSmellNum);
             }
             tmpSmellNum = Integer.parseInt(smellPerVersion.get("spf").toString());
             if (tmpSmellNum != 0) {
               tmpSmell.put("Scattered_Parasitic_Functionality", tmpSmellNum);
             }
             file.put("smells", tmpSmell);
           }
         }
       }
       return;
     }
   }
 }
Exemple #3
0
 public void testCreate() {
   board.initialize();
   assertEquals(32, board.pieceCount());
   String blankRank = StringUtil.appendNewLine("........");
   assertEquals(
       StringUtil.appendNewLine("RNBQKBNR")
           + StringUtil.appendNewLine("PPPPPPPP")
           + blankRank
           + blankRank
           + blankRank
           + blankRank
           + StringUtil.appendNewLine("pppppppp")
           + StringUtil.appendNewLine("rnbqkbnr"),
       board.print());
 }
 public String getSmartsMatchesFilePath(
     MatchEngine matchEngine, List<ListedFragmentProperty> fragments) {
   String allSmartsStrings = "";
   for (ListedFragmentProperty fragment : fragments) allSmartsStrings += fragment.getSmarts();
   String enc = StringUtil.getMD5(matchEngine + allSmartsStrings);
   return Settings.destinationFile(dataset, enc + ".matches.csv");
 }
 @Test
 public void testCombineArraysWithOneItemInFirst() {
   String[] first = new String[] {"a"};
   String[] result = StringUtil.combineArrays(first, new String[] {});
   assertEquals(1, result.length);
   assertEquals("a", result[0]);
 }
Exemple #6
0
  public byte[] getTarget() throws URLSyntaxException {
    if (target == null) {
      getSchemeSpecificPart();
      if (schemeSpecificPart == null) {
        throw new URLSyntaxException();
      }

      int idx = schemeSpecificPart.indexOf(";");
      if (idx == -1) {
        target = StringUtil.getBytes(schemeSpecificPart, true);
      } else {
        target = StringUtil.getBytes(schemeSpecificPart.substring(0, idx), true);
      }
    }
    return target;
  }
 public String getAlignResultsPerClusterFilePath(int clusterIndex, String params) {
   return Settings.destinationFile(
       dataset,
       getEncodedSettingsIncludingFeatures(clusteringData.getDatasetClusterer())
           + "."
           + StringUtil.getMD5(clusterIndex + params)
           + ".cluster");
 }
 @Test
 public void testCombineArraysWithOneItemInEach() {
   String[] first = new String[] {"a"};
   String[] second = new String[] {"b"};
   String[] result = StringUtil.combineArrays(first, second);
   assertEquals(2, result.length);
   assertEquals("a", result[0]);
   assertEquals("b", result[1]);
 }
  /** @param args */
  public static void main(String[] args) {
    ChucDanh chucDanh = new ChucDanh("GD", "Giam Doc", 0);
    NguoiDung nguoiDung =
        new NguoiDung(
            "b1203950", "Vo Phu Quoi", "Can Tho", "*****@*****.**", "0979921380", chucDanh);

    //		new ChucDanhDAO().addChucDanh(chucDanh);
    new NguoiDungDAO().addNguoiDung(nguoiDung);
    new CTNguoiDungDAO()
        .addCTNguoiDung(new CTNguoiDung(nguoiDung.getMsnv(), StringUtil.encryptMD5("12345678"), 0));
  }
Exemple #10
0
 public ResultSet departmentList(Connection con, pageBean pageBean, departmentList department)
     throws Exception {
   StringBuffer sb = new StringBuffer("select * from table_department");
   if (department != null && StringUtil.isNotEmpty(department.getDepartmentInfo())) {
     sb.append(" and departmentInfo like '%" + department.getDepartmentInfo() + "%'");
   }
   if (pageBean != null) {
     sb.append(" limit " + pageBean.getStart() + "," + pageBean.getRows());
   }
   PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
   return pstmt.executeQuery();
 }
 /** @return */
 public String resetPassword() {
   this.volunteer = (VolunteerBean) getBusiness().getLeaf(getId()).getResponseData();
   this.listSource = (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
   if (volunteer != null) {
     SystemSettingBean systemSetting = ssb.getLeaf();
     volunteer.setPassword(StringUtil.toMD5(systemSetting.getDefaultPassword()));
     getBusiness().updateLeaf(volunteer, volunteer);
     addActionMessage("密码重置成功!");
   } else {
     addActionError("获取用户失败!重置密码失败!");
   }
   return SUCCESS;
 }
  @RequestMapping("about")
  public void About(Model model, String id) {
    List<Article> aboutList = aboutService.getAboutList();
    model.addAttribute("aboutlist", aboutList);
    if (StringUtil.isNullOrEmpty(id) && aboutList.size() > 0) {
      id = String.valueOf(aboutList.get(0).getId());
    }

    model.addAttribute("classid", id);

    List<Article> aboutOneContent = aboutService.getAboutOneContent(id);
    model.addAttribute("aboutonecontent", aboutOneContent);
  }
Exemple #13
0
 public int departmentCount(Connection con, departmentList department) throws Exception {
   StringBuffer sb = new StringBuffer("select count(*) as total from table_department");
   if (StringUtil.isNotEmpty(department.getDepartmentInfo())) {
     sb.append(" and departmentInfo like '%" + department.getDepartmentInfo() + "%'");
   }
   PreparedStatement pstmt = con.prepareStatement(sb.toString().replaceFirst("and", "where"));
   ResultSet rs = pstmt.executeQuery();
   if (rs.next()) {
     return rs.getInt("total");
   } else {
     return 0;
   }
 }
Exemple #14
0
  // 根据名字查找商品列表, 包括参数是否有库存
  public String findProductByName() {
    setMessage(null);
    setTitle("商品查找结果");
    System.out.println("mergeParamsAsURI=" + mergeParamsAsURI());

    try {
      String name = getParameter("keyword");
      String availableStr = getParameter("available");

      boolean available = false;

      try {
        available = Boolean.parseBoolean(availableStr);
      } catch (Exception ex) {

      }

      if (StringUtil.isEmpty(name)) {
        setMessage("请输入商品名字");
      } else {
        setTitle("所有名字包含" + name + "的商品列表");
        List<Product> products = productManager.findAllByNameIncludeAmount(name, available);

        int currentPage = getParameterInt("page");
        PageBean pageBean = new PageBean();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageCount(2);
        pageBean.setRecordCount(
            (int) productManager.countFindAllByNameIncludeAmount(name, available));
        pageBean.setPageUrl("product/findByName.action?" + mergeParamsAsURI());
        setAttribute("pageBean", pageBean);

        if (products == null || products.size() == 0) {
          throw new Exception();
        }

        setAttribute("products", products);
      }

    } catch (Exception e) {
      setMessage("没有符合条件的商品信息");
    }

    if ("true".equalsIgnoreCase(getParameter("ajax"))) {
      return "ajax";
    }

    return SUCCESS;
  }
 @Test
 public void testCombineArraysWithMixedNumbers() {
   String[] first = new String[] {"a", "b", "c"};
   String[] second = new String[] {"d", "e"};
   String[] third = new String[] {"f", "g", "h"};
   String[] result = StringUtil.combineArrays(first, second, third);
   assertEquals(8, result.length);
   assertEquals("a", result[0]);
   assertEquals("b", result[1]);
   assertEquals("c", result[2]);
   assertEquals("d", result[3]);
   assertEquals("e", result[4]);
   assertEquals("f", result[5]);
   assertEquals("g", result[6]);
   assertEquals("h", result[7]);
 }
 @Test
 public void shouldStripCarriageReturns() throws Exception {
   assertEquals("\n", StringUtil.stripCarriageReturns("\n"));
   assertEquals("\n", StringUtil.stripCarriageReturns("\n\r"));
   assertEquals("\n", StringUtil.stripCarriageReturns("\n\r\r\r\r\r"));
   assertEquals("\n", StringUtil.stripCarriageReturns("\r\n"));
   assertEquals("\n\n", StringUtil.stripCarriageReturns("\r\n\r\n\r\r\r"));
   assertEquals(
       "This\nis\na\nset\nof\nlines.\n",
       StringUtil.stripCarriageReturns("This\n\ris\r\na\nset\r\n\rof\nlines.\n\r"));
 }
 public static void addSmell2Issue(JSONObject issue) {
   JSONArray commits = (JSONArray) issue.get("commits");
   // iterate commits
   for (int commitIdx = 0; commitIdx < commits.size(); commitIdx++) {
     JSONObject commit = (JSONObject) commits.get(commitIdx);
     JSONArray files = (JSONArray) commit.get("files");
     // iterate files in each commit
     for (int fileIdx = 0; fileIdx < files.size(); fileIdx++) {
       JSONObject file = (JSONObject) files.get(fileIdx);
       String filename = (String) file.get("filename");
       String[] pkgPrefixs = projectConfig.getValue("PKG_PREFIX").split("#");
       if (StringUtil.isValidFilename(filename, pkgPrefixs)) {
         addSmell2File(issue, file, filename);
       }
     }
   }
 }
  @RequestMapping("joinus")
  public void JoinUs(Model model, String id) {
    List<Article> joinusList = aboutService.getJoinUsList();
    model.addAttribute("joinuslist", joinusList);

    if (StringUtil.isNullOrEmpty(id) && joinusList.size() > 0) {
      id = String.valueOf(joinusList.get(0).getId());
    }

    model.addAttribute("classid", id);

    List<Article> joinUsOneContent = aboutService.getJoinUsOneContent(id);
    model.addAttribute("joinusonecontent", joinUsOneContent);

    // 附加的文章
    List<Article> othersArticle = aboutService.getOthersArticleByType(Constants.JOIN_ARTICLE);
    model.addAttribute("othersarticle", othersArticle);
  }
 public static Set<String> getDirectoryPrefix() {
   Set<String> prefixs = new HashSet<String>();
   for (int i = 0; i < issues.size(); i++) {
     JSONObject issue = (JSONObject) issues.get(i);
     JSONArray commits = (JSONArray) issue.get("commits");
     // iterate commits
     for (int commitIdx = 0; commitIdx < commits.size(); commitIdx++) {
       JSONObject commit = (JSONObject) commits.get(commitIdx);
       JSONArray files = (JSONArray) commit.get("files");
       // iterate files in each commit
       for (int fileIdx = 0; fileIdx < files.size(); fileIdx++) {
         JSONObject file = (JSONObject) files.get(fileIdx);
         String filename = (String) file.get("filename");
         prefixs.add(StringUtil.extractPkgPrefix(filename));
       }
     }
   }
   return prefixs;
 }
Exemple #20
0
  private void parseParameters() throws URLSyntaxException {
    if (parameters == null) {
      parameters = new KeyValueMap();
      getSchemeSpecificPart();
      int idx = schemeSpecificPart.indexOf(';');
      String parameters = schemeSpecificPart.substring(idx);
      StringTokenizer tokenizer = new StringTokenizer(parameters, ";");
      while (tokenizer.hasMoreElements()) {
        String nextToken = tokenizer.nextToken();
        idx = nextToken.indexOf('=');
        if (idx == -1) {
          throw new URLSyntaxException();
        }
        String key = nextToken.substring(0, idx);

        byte[] value = StringUtil.getBytes(nextToken.substring(idx + 1), true);
        this.parameters.put(key, value);
      }
    }
  }
 @Test
 public void testTrimAllSpacesStringResultsInEmptyString() {
   assertEquals("", StringUtil.trimNonNullString("   "));
 }
 public String toString() {
   StringBuffer buf = StringUtil.constructStringBuffer("Mission: ", noOfRegistered);
   buf.append(" handlers");
   return buf.toString();
 }
 @Test
 public void testTrimNullStringReturnsNull() {
   assertEquals(null, StringUtil.trimNonNullString(null));
 }
 @Test
 public void testCombineArraysBothEmpty() {
   assertEquals(0, StringUtil.combineArrays(new String[] {}, new String[] {}).length);
 }
 @Test
 public void testTrimStringWithLeadingAndTrailingSpaces() {
   assertEquals("FitNesse", StringUtil.trimNonNullString(" FitNesse "));
 }