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

    −55.8

    1. 1
    2. 2
    3. 3
    4. 4
    public static int daysBetween(Date startDate, Date endDate)
    {
         int difInDays = (int) ((endDate.getTime() - startDate.getTime())/(1000*60*60*24));
    }

    Потрясающая воображение функция, которая считает разницу в днях между датами. Различие с правильным результатом в +\- 1 день получается в 30% случаев...

    guest, 11 Декабря 2008

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

    +18.5

    1. 1
    2. 2
    3. 3
    if (true) {
      // Something
    }

    Уже два года, как девушка закончила универ...

    guest, 10 Декабря 2008

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

    +27

    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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    private int checkTerm(PatternTerm term, int arr[],
          int symbNum, boolean isEditing) {
        if (term.count != INFINITY) {
          int endIdx = Math.min(symbNum + term.count, arr.length);
            int count = 0;
            switch(term.termType) {
              case DIGIT: {
                for(int i = symbNum; i < endIdx; i++) {
                  if (!Character.isDigit((char)arr[i]))
                    return -1;
                  count++;
                }
                break;
              }
              case LETTER: {
                for(int i = symbNum; i < endIdx; i++) {
                  if (!Character.isLetter((char)arr[i]))
                    return -1;
                  count++;
                }
                break;
              }
              case LETTERORDIGIT: {
                for(int i = symbNum; i < endIdx; i++) {
                  if (!Character.isLetterOrDigit((char)arr[i]))
                    return -1;
                  count++;
                }
                break;
              }
              case CHARACTER: {
                for(int i = symbNum; i < endIdx; i++) {
                  if (arr[i] != term.value)
                    return -1;
                  count++;
                }
                break;
              }
          }
          if (!isEditing && count != term.count)
            return -1;
          
          symbNum+=term.count;
        } else {
          int i = 0;
          switch(term.termType) {
            case DIGIT: {
              while (((symbNum + i) < arr.length) &&
                  Character.isDigit((char)arr[symbNum + i])) i++;
              break;
            }
            case LETTER: {
              while (((symbNum + i) < arr.length) &&
                  Character.isLetter((char)arr[symbNum + i])) i++;
              break;
            }
            case LETTERORDIGIT: {
              while (((symbNum + i) < arr.length) &&
                  Character.isLetterOrDigit((char)arr[symbNum + i])) i++;
              break;
            }
            case CHARACTER: {
              while (((symbNum + i) < arr.length) &&
                  (arr[symbNum + i] == term.value)) i++;
              break;
            }
          }
          symbNum+=i;
        }
        return symbNum;
      }

    Паша любит такие конструкции, которые хрен разобрать

    guest, 10 Декабря 2008

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

    −50

    1. 1
    2. 2
    3. 3
    4. 4
    contents = contents.replaceAll("\\&lt;(\\w+)\\&gt;", "<CT_$1>\n");
    				contents = contents.replaceAll("\\&lt;(\\w+)(\\s\\w+)=\\&quot;(\\w+)\\&quot;\\&gt;", "<CT_$1$2=\"$3\">\n");
    				contents = contents.replaceAll("\\&lt;(\\w+)(\\s\\w+)=\\&apos;(\\w+)\\&apos;\\&gt;", "<CT_$1$2='$3'>\n");
    				contents = contents.replaceAll("\\&lt;/(\\w+)\\&gt;", "\n</CT_$1>\n");

    преобразуем эскейпнутые тэги в обычные

    guest, 09 Декабря 2008

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

    −32.7

    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
    public void updateAmountValues(List<TransactionResultItem> transactionResultItems) {
            for (TransactionResultItem transaction : transactionResultItems) {
                Account account = getAccountById(transaction.getAccountId());
                if ((transaction.getMainTransaction()
                        && ! transaction.getTransactionTypeId().equals(4)
                        && ! transaction.getTransactionTypeId().equals(5)
                        && ! transaction.getTransactionTypeId().equals(6))
                        ||
                        (! transaction.getMainTransaction() &&
                                (transaction.getTransactionTypeId().equals(5) &&
                                        ((account.getAccountTypeId().equals(AccountType.INCOME_TYPE_ID) ||
                                                account.getAccountTypeId().equals(AccountType.OTHER_INCOME_TYPE_ID)) &&
                                                transaction.getAmount() > 0)
                                        || (transaction.getAccountId().equals(getSalesTaxPayableAccountId()) && transaction.getAmount() > 0)
                                        || ((account.getAccountTypeId().equals(AccountType.EXPENSE_TYPE_ID) ||
                                        account.getAccountTypeId().equals(AccountType.OTHER_EXPENSE_TYPE_ID)) && transaction.getAmount() < 0))
                                || (transaction.getTransactionTypeId().equals(1) &&
                                (account.getAccountTypeId().equals(AccountType.INCOME_TYPE_ID) ||
                                        account.getAccountTypeId().equals(AccountType.OTHER_INCOME_TYPE_ID)) &&
                                transaction.getAmount() < 0)
                                || (transaction.getTransactionTypeId().equals(2) &&
                                (account.getAccountTypeId().equals(AccountType.INCOME_TYPE_ID) ||
                                        account.getAccountTypeId().equals(AccountType.OTHER_INCOME_TYPE_ID)) &&
                                transaction.getAmount() > 0)
                        )) {
                    Double amount = transaction.getAmount();
                    transaction.setAmount(-amount);
                }
            }
        }

    Потрясающий по понятности код. Вызывался несколько раз в одном и том же методе.

    guest, 08 Декабря 2008

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

    −53.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    /**
     * Reply string array after tokenize the url address
     *
     * @param String url
     * @return String[]
     */
    protected String[] processURL(String url) {
    
        StringBuffer s = new StringBuffer(url);
        StringBuffer AfterRemoval = s.delete(0, 27);
    ...

    ...в тот день магическим числом для паренька из Индии было число 27... похоже он и сам не понимал почему.. возможно это как то было связано с именем хоста...

    guest, 08 Декабря 2008

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

    −43.8

    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
    private Map<Class<?>, Map<String, String[]>> compressDependencies(
          Map<Class<?>, Map<String, List<String>>> dependencies) {
        final Map<Class<?>, Map<String, String[]>> result =
            new FastMap<Class<?>, Map<String, String[]>>(dependencies.size());
        final Set<Entry<Class<?>, Map<String, List<String>>>> entrySet = dependencies.entrySet();
        for (Entry<Class<?>, Map<String, List<String>>> entry : entrySet) {
          final Map<String, List<String>> value = entry.getValue();
          final Map<String, String[]> desc = new FastMap<String, String[]>(value.size());
          final Set<Entry<String, List<String>>> subEntries = value.entrySet();
          for (Entry<String, List<String>> valueEntry : subEntries) {
            final List<String> list = valueEntry.getValue();
            if (list != null && !list.isEmpty()) {
              desc.put(valueEntry.getKey(), list.toArray(new String[list.size()]));
            }
          }
          result.put(entry.getKey(), desc);
        }
        return result;
      }

    Код от "мега разработчика", архитектора очень большого проекта.

    PS Будьте осторожны в использовании java generics :)

    guest, 08 Декабря 2008

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

    +24

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
      * Getter for billbackAdjustmentType 
      *
      * @return the billbackAdjustmentType instance
      */
    public BillbackAdjustmentType getBillbackAdjustmentType() {
        return billbackAdjustmentType != null ? billbackAdjustmentType : BillbackAdjustmentType.PlusBillbackAdjustment;
    }

    ...и попробуй такое найди под дебагом :)

    guest, 04 Декабря 2008

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

    −11.2

    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
    public static Date createDate(Integer iYear, Integer iMonth, Integer iDay) throws Exception
        {
            if ((!(iYear instanceof Integer))
                    || (!(iMonth instanceof Integer))
                    || (!(iDay instanceof Integer))
                    )
            {
                throw new Exception();
            }
    
            Date date = null;
            String year, month, day;
    
            year = iYear.toString();
            month = iMonth.toString();
            day = iDay.toString();
            try
            {
                date = new SimpleDateFormat("yyyy/MM/dd").parse(year + "/" + month + "/" + day);
    
            } catch (ParseException e)
            {
                log.warn("Date transformation failed for year, month, day:  " + iYear + ", " + iMonth + ", " + iDay);
            }
            return date;
        }

    Индусы Рулят!!!

    guest, 02 Декабря 2008

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

    −34.2

    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
    public boolean foo(...){
      ...
      try{
      ...
      }
      finally{
        if(expr_1){
          return false;
        }
        if(expr_2){
          return false;
        }
        ...
        if(expr_n){
          return false;
        }
      }
      ...
      return true;
    }

    поймал на сопровождении, долго курил (метод на 3 экранах)

    guest, 28 Ноября 2008

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