1. Java / Говнокод #16812

    +73

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    for (int i = 1; i <= 3; i++) {
                if (i <= arr.length) {
                    xmlDocumentNode.setNodeValue("P_15_" + i, arr[i - 1].getNAME());
                    xmlDocumentNode.setNodeValue("P_16_" + i, arr[i - 1].getSERIAL());
                    xmlDocumentNode.setNodeValue("P_17_1_" + i, arr[i - 1].getPLANTMANUF());
                    xmlDocumentNode.setNodeValue("P_17_2_" + i, arr[i - 1].getPLANTMANUFNAME());
                    xmlDocumentNode.setNodeValue("P_18_" + i, arr[i - 1].getDATEMANUF());
                    xmlDocumentNode.setNodeValue("P_19_1_" + i, arr[i - 1].getPLANTREP());
                    xmlDocumentNode.setNodeValue("P_19_2_" + i, arr[i - 1].getPLANTREPNAME());
                    xmlDocumentNode.setNodeValue("P_20_" + i, arr[i - 1].getDATEREP());
                    xmlDocumentNode.setNodeValue("P_21_1_" + i, arr[i - 1].getDEFECT());
                    xmlDocumentNode.setNodeValue("P_21_2_" + i, arr[i - 1].getDEFECTNAME());
                } else {
                    xmlDocumentNode.setNodeValue("P_15_" + i, "");
                    xmlDocumentNode.setNodeValue("P_16_" + i, "");
                    xmlDocumentNode.setNodeValue("P_17_1_" + i, "");
                    xmlDocumentNode.setNodeValue("P_17_2_" + i, "");
                    xmlDocumentNode.setNodeValue("P_18_" + i, "");
                    xmlDocumentNode.setNodeValue("P_19_1_" + i, "");
                    xmlDocumentNode.setNodeValue("P_19_2_" + i, "");
                    xmlDocumentNode.setNodeValue("P_20_" + i, "");
                    xmlDocumentNode.setNodeValue("P_21_1_" + i, "");
                    xmlDocumentNode.setNodeValue("P_21_2_" + i, "");
                }
            }

    Обработка XML-таблиц. fillTable? не, не слышал

    Koshak90, 07 Октября 2014

    Комментарии (0)
  2. Java / Говнокод #16810

    +120

    1. 1
    stopPos.updateStopPositionPortPositionWithoutRedrawingOfIt();

    someone, 07 Октября 2014

    Комментарии (9)
  3. Java / Говнокод #16798

    +74

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    // TODO: This is not the smartest way to implement the config
    public int getFileFragmentationLevel() {
      return config.getFileFragmentationLevel();
    }
    
    public void setFileFragmentationLevel(int fileFragmentationLevel) {
      config.setFileFragmentationLevel(fileFragmentationLevel);
    }
    
    public int getStackTraceOutputMethod() {
      return config.getStackTraceOutputMethod();
    }
    
    public void setStackTraceOutputMethod(int stackTraceOutputMethod) {
      config.setStackTraceOutputMethod(stackTraceOutputMethod);
    }
    
    public String getOutputDirectory() {
      return config.getOutputDirectory();
    }
    
    public void setOutputDirectory(String outputDirectory) {
      config.setOutputDirectory(outputDirectory);
    }
    
    // и так для всех филдов (геттеров/сеттеров) объекта config

    https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/reporters/XMLReporter.java
    Ну хоть признаёт.

    Actine, 05 Октября 2014

    Комментарии (1)
  4. Java / Говнокод #16791

    +89

    1. 1
    2. 2
    3. 3
    String os = System.getProperty("os.name");
    if (os.startsWith("Windows 9") || os.equals("Windows Me")) {
    throw new RuntimeException(

    https://searchcode.com/?q=if%28version%2Cstartswith%28%22window s+9%22%29
    Очевидно Windows 10 спасёт ситуацию.

    Говногость, 03 Октября 2014

    Комментарии (54)
  5. Java / Говнокод #16781

    +78

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    protected String getFeedText() {
      StringBuffer answer = new StringBuffer();
      if (getFeedName() != null) {
       answer.append("Feed Named: " + getFeedName() + " - ");
    
      }
      return answer.toString();
     }

    1. Похоже на праведное намерение использовать StringBuilder :)
    2. Положение звезд и фаза луны помешали воспользоваться хотя бы StringBuffer, вычисление все равно сделано на простых String

    tort, 01 Октября 2014

    Комментарии (6)
  6. Java / Говнокод #16768

    +80

    1. 1
    2. 2
    3. 3
    if (!driver.findElement(By.id(DD_LAUNCH_ID)).equals(null)) {
        pause(1000);
    }

    Тогда уж почему не null.equals(...)?

    Actine, 25 Сентября 2014

    Комментарии (14)
  7. Java / Говнокод #16764

    +118

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    import static com.google.gwt.query.client.GQuery.*;
    import com.google.gwt.query.client.Function;
    
    public void onModuleLoad() {
      //Hide the text and set the width and append an h1 element
      $("#text").hide()
        .css("width", "400px")
        .prepend("<h1>GwtQuery Rocks !</h1>");
        
        //add a click handler on the button
        $("button").click(new Function(){
          public void f() {
            //display the text with effects and animate its background color
            $("#text").as(Effects)
              .clipDown()
              .animate("backgroundColor: 'yellow'", 500)
              .delay(1000)
              .animate("backgroundColor: '#fff'", 1500);
          }
        });
    }

    Не ГК, но мне показалось забавно.

    https://code.google.com/p/gwtquery/

    someone, 25 Сентября 2014

    Комментарии (12)
  8. Java / Говнокод #16759

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    static final String MIN_INTEGER = String.valueOf(Integer.MIN_VALUE);
      static final String MAX_INTEGER = String.valueOf(Integer.MAX_VALUE);
      static final String MIN_LONG = String.valueOf(Long.MIN_VALUE);
      static final String MAX_LONG = String.valueOf(Long.MAX_VALUE);
    
      static final int NS_INTEGER = 1;
      static final int NS_LONG = 2;
    
      /**
       * Проверяет, является ли передаваемая строка строковым представлением числа типа int (long)
       * @param s строка для проверки
       * @return <code>true</code>, если строка может быть распарсена как int (ling).
       * @see Integer#parseInt
       * @see Long#parseLong
       */
      private static boolean isNumber(String s, int NUMBER_SIZE) {
        String MIN_NUMBER = "", MAX_NUMBER = "";
        switch (NUMBER_SIZE) {
          case (NS_INTEGER):
            MIN_NUMBER = MIN_INTEGER;
            MAX_NUMBER = MAX_INTEGER;
          break;
          case (NS_LONG):
            MIN_NUMBER = MIN_LONG;
            MAX_NUMBER = MAX_LONG;
          break;
        }
        if (s == null) return false;
        final int len = s.length();
        boolean negative = false;
        int pos = len > 0 && (negative = s.charAt(0) == '-') ? 1 : 0;
        if (pos == len) return false;
        while (pos < len && s.charAt(pos) == '0') pos++; //пропустим 0
        if (pos == len) return true; // там 0
        // если длина заведомо больше, то и значение по-любому выходит за пределы
        if (negative && len - pos > MIN_NUMBER.length() - 1 || len - pos > MAX_NUMBER.length()) return false;
        // нужно проверять предельные значения
        boolean needCheckRange = negative && len - pos == MIN_NUMBER.length() - 1 || len - pos == MAX_NUMBER.length();
        if (needCheckRange) {
          final String rangeString = negative ? MIN_NUMBER : MAX_NUMBER;
          for (int i = negative? 1:0; pos<len; pos++,i++) {
            final char c = s.charAt(pos);
            char r = 0;
            if (c < '0' || c > '9' ||
                (needCheckRange && c > (r = rangeString.charAt(i))) ||
                ((needCheckRange &= c == r) && false))
              return false;
          }
        } else {
          for (;pos<len;pos++) {
            final char c = s.charAt(pos);
            if (c < '0' || c > '9')
              return false;
          }
        }
        return true;
      }

    glprizes, 24 Сентября 2014

    Комментарии (1)
  9. Java / Говнокод #16736

    +73

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    String getFindList(StringBuffer sb, String[] src) {
    // int tid = Helper.parseType(src[2]);
    // if(tid < 1 || tid > 99) return "Error parse good type";
    int stk = Helper.parseType(src[3]);
    if(stk < 412 || stk > 416)	return "Error parse stock code";
    // --------------------------------------------------------
    IntHashtable work = new IntHashtable();
    double[] vals = null;
    Entry ent = null;
    Enumeration e=cache.getEntryElements();
    while(e.hasMoreElements()) {
    ent = (Entry)e.nextElement();
    if(ent.Credit != stk)	continue;
    if(ent.Status == 0)	continue;
    vals = (double[])work.get(ent.SubCred);
    if(vals == null) {
    vals = new double[2];
    vals[0] = ent.Value;
    work.put(ent.SubCred, vals);
    } else
    vals[0]+=ent.Value;
    }
    // ---------------------------------------------------------
    String s="SELECT  ... ";
    int id;
    String cod, gnm, uni;
    double amt,val,pack,vlr;
    double[] prcs = new double[4];
    Connection con = cache.getConnection();
    if(con == null)	return "No free conection";
    try {
    Statement stmt = con.createStatement();
    ResultSet rset = stmt.executeQuery(s);
    while(rset.next()) {
    id = rset.getInt("id");
    cod = rset.getString("code");
    gnm = rset.getString("name");
    uni = rset.getString("unit");
    pack = rset.getDouble("pack");
    amt = rset.getDouble("amount");
    val = rset.getDouble("value");
    prcs[0] = rset.getDouble("price");
    prcs[1] = rset.getDouble("price1");
    prcs[1]=(prcs[1] < 0.01) ? prcs[0] : prcs[1];
    prcs[2] = rset.getDouble("price2");
    prcs[2]=(prcs[2] < 0.01) ? prcs[1] : prcs[2];
    prcs[3] = rset.getDouble("sprice");
    prcs[3]=(prcs[3] < 0.01) ? prcs[2] : prcs[3];
    vals = (double[])work.get(id);
    vlr =(vals == null) ? 0 : vals[0];
    sb.append(id+",'"+gnm+"','"+cod+"','"+uni+"',"+pack+","+val+","+vlr+",");
    for(int i=0; i<prcs.length; i++)	sb.append(prcs[i]+",");
    sb.append((amt/val)+",\n");
    }
    rset.close();
    stmt.close();
    s = null;
    } catch (SQLException ex) {
    s=ex.getMessage();
    }
    cache.freeConnection(con);
    return s;
    }

    qw0, 21 Сентября 2014

    Комментарии (0)
  10. Java / Говнокод #16724

    +74

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    url = new URL("http://[FF01:0:0:0:0:0:0:0101]");
    String originalHostName = url.getHost();
    System.out.println(originalHostName);
    if (originalHostName.startsWith("[") && originalHostName.endsWith("]")) {
     i1 = originalHostName.indexOf("[");
     originalHostName = originalHostName.substring(i1 + 1);
     i2 = originalHostName.lastIndexOf("]");
     originalHostName = originalHostName.substring(0, i2);
     if (IPV6REGEX.matcher(originalHostName).matches()) {
      System.out.println(url + " is a ipv6 address");
      String hostName = InetAddress.getByName(originalHostName).getHostAddress().toLowerCase();
      if (hostName.contains(":")) {
       hostName = "[" + hostName + "]";
      }
     }
    }

    Взято отсюда: http://www.pretechsol.com/2013/05/ipv6-java-regular-expression-example.html#.VBtooLn69B0

    0rt, 19 Сентября 2014

    Комментарии (2)