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

    +83.5

    1. 1
    2. 2
    3. 3
    for (Person p : c) {
                return p;
            }

    yvu, 28 Сентября 2009

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

    −49.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
     * Pause length in milliseconds.
     */
     private static final int _100000 = 100000;
     /**
     * Summary pause length in milliseconds.
     */
     private static final int _500000 = _100000 * 5;

    Автор творения сказал, что так удобнее читать код:)

    intr13, 28 Сентября 2009

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

    +65

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (s.length() < 2)
                return false;
    if (s.charAt(1) == ':') {
                return true;
    }
    return false;

    lian, 23 Сентября 2009

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

    +73.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
    public Object save(Object entity) {
            final EntityManager em = getEntityManager();
            try {
                final EntityTransaction et = em.getTransaction();
                try {
                    et.begin();
                    em.persist(entity);
                    et.commit();
                } finally {
                    if (et != null && et.isActive()) {
                        entity = null;
                        et.rollback();
                    }
                }
            } finally {
                if (em != null && em.isOpen()) {
                    em.close();
                }
            }
            return entity;
        }

    Простое и понятное управление транзакциями придумали трусы!
    А rollback в секции finally, и вложенные try-catch секции -- вообще модная сейчас фишка.

    rh.mbox, 23 Сентября 2009

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

    +71.9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (!selectAndAdd(select, administrators,
                                        userUid)) //shouldn't be so but...
                                {
                                    throw new IllegalStateException(
                                            "World is full of mystical things. That is one of them");
                                }

    Мир полон таинственных вещей! :-)

    sweetshadow, 17 Сентября 2009

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

    +70.5

    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
    private JTextField m_tfSeries = new JTextField(9){
            protected void processFocusEvent(FocusEvent e) {
                if( m_tfSeries == null 
                                || m_tfSeries == null 
                                || !m_tfSeries.isEnabled() 
                                || !m_tfSeries.isEditable())
                    return;
                super.processFocusEvent(e);
                if(e.getID() == FocusEvent.FOCUS_LOST) {
                    onRangeBeginFocusLost();
                }
                
                if(e.getID() == FocusEvent.FOCUS_GAINED) {
                    reactToChanges();
                    m_showWarning(WARNING_INVALID_SERIES_ID);
                }
            }
        };

    Самый оригинальный FocusListener из тех, что я видел =)

    mrscalder, 14 Сентября 2009

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

    +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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    ..........
    
    if (year.equals(beginYear)) {
        //таск полностью попадает в месяц
        if ((beginMonth == month) && (endMonth == month)) {
         for (int i = 1; i < beginDate; i++) {
          row.add(3);
         }
         for (int i = beginDate; i < realizationDate; i++) {
             row.add(-1);
         }
         row.add(1);
         for (int i = realizationDate + 1; i <= endDate; i++) {
             row.add(2);
         }
         for (int i = endDate; i < columnCount; i++) {
          row.add(3);
         }
        }
        
        //таск полностью не попадает в месяц или полностью занимает месяц
        if ((beginMonth < month) && (endMonth > month)) {
         for (int i = 1; i < columnCount; i++) {
          row.add(-1);
         }
        } else if ((beginMonth < month) && (endMonth < month)) {
         for (int i = 1; i < columnCount; i++) {
          row.add(3);
         }
        } else if ((beginMonth > month) && (endMonth > month)) {
         for (int i = 1; i < columnCount; i++) {
          row.add(3);
         }
        }
        
        //таск попадает в месяц частично
        if ((beginMonth == month) && (beginMonth < endMonth)) {
         if (beginMonth == realizationMonth) {
          for (int i = 1; i < beginDate; i++) {
           row.add(3);
          }
          for (int i = beginDate; i < realizationDate; i++) {
              row.add(-1);
          }
          row.add(1);
          for (int i = realizationDate + 1; i < columnCount; i++) {
              row.add(2);
          }
         } else {
          for (int i = 1; i < beginDate; i++) {
           row.add(3);
          }
          for (int i = beginDate; i < columnCount; i++) {
              row.add(-1);
          }
         }
        } else if ((endMonth == month) && (beginMonth < endMonth)){
         if (endMonth == realizationMonth) {
          for (int i = 1; i < realizationDate; i++) {
           row.add(-1);
          }
          row.add(1);
        
          for (int i = realizationDate + 1; i <= endDate; i++) {
              row.add(2);
          }
          for (int i = (endDate + 1); i < columnCount; i++) {
           row.add(3);
          }
         } else {
          for (int i = 1; i <= endDate; i++) {
           row.add(2);
          }
          for (int i = (endDate + 1); i < columnCount; i++) {
           row.add(3);
          }
         } 
        }
       } else {
        for (int i = 1; i < columnCount; i++) {
         row.add(3);
        }
       }
    ...........

    Вот так корень кладёт данные в таблицу по определённой дате

    paranoid, 11 Сентября 2009

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

    +75.3

    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
    public static ru.project.subpackage.PersonDTO convertOshPersonDtoToPersonDto(OshPersonDTO person){
            ru.project.subpackage.PersonDTO dto = new ru.project.subpackage.PersonDTO();
            dto.setPersonid(person.getPersonid().longValue());
            dto.setNamelast(person.getNamelast());
            dto.setNamefirst            (person.getNamefirst            ());
            dto.setNamesec              (person.getNamesec              ());
            dto.setInitials             (person.getInitials             ());
            dto.setSex                  (convertSkVocValue(person.getSex()));
            dto.setReason               (person.getReason               ());
            dto.setWorkphone            (person.getWorkphone            ());
            dto.setWorkphonedigit       (person.getWorkphonedigit       ());
            dto.setLocalphone           (person.getLocalphone           ());
            dto.setLocalphonedigit      (person.getLocalphonedigit      ());
            dto.setHomephone            (person.getHomephone            ());
            dto.setHomephonedigit       (person.getHomephonedigit       ());
            dto.setMobilephone          (person.getMobilephone          ());
            dto.setMobilephonedigit     (person.getMobilephonedigit     ());
            dto.setFax                  (person.getFax                  ());
            dto.setFaxdigit             (person.getFaxdigit             ());
            dto.setPager                (person.getPager                ());
            dto.setEmail                (person.getEmail                ());
            dto.setWeb                  (person.getWeb                  ());
            dto.setNamelastdative       (person.getNamelastdative       ());
            dto.setNamefirstdative      (person.getNamefirstdative      ());
            dto.setNamesecdative        (person.getNamesecdative        ());
            dto.setNamelastaccusative   (person.getNamelastaccusative   ());
            dto.setNamefirstaccusative  (person.getNamefirstaccusative  ());
            dto.setNamesecaccusative    (person.getNamesecaccusative    ());
            dto.setNamelastgenitive     (person.getNamelastgenitive     ());
            dto.setNamefirstgenitive    (person.getNamefirstgenitive    ());
            dto.setNamesecgenitive      (person.getNamesecgenitive      ());
            dto.setNamelastinstrumental (person.getNamelastinstrumental ());
            dto.setNamefirstinstrumental(person.getNamefirstinstrumental());
            dto.setNamesecinstrumental  (person.getNamesecinstrumental  ());
            dto.setNamelastprepositional(person.getNamelastprepositional());
            dto.setNamefirstprepositional(person.getNamefirstprepositional());
            dto.setNamesecprepositional (person.getNamesecprepositional ());
            return dto;
        }

    И так далее еще несколько сотен строк. А главное переупаковка из одних объектов в другие и обратно бессмысленна, т.к. можно использовать исходные (они доступны в приложении)

    johnsoft, 07 Сентября 2009

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

    +82.7

    1. 1
    2. 2
    3. 3
    4. 4
    public static boolean isUnix()
        {
            return System.getProperty("file.separator").equals("/");
        }

    johnsoft, 07 Сентября 2009

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

    +71.3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    /**
         * Возбуждает IllegalArgumentException если аргумент null.
         * Формирует сообщение об ошибке с именем условия.
         *
         * @param argument     проверяемый аргумент
         * @param argumentName имя аргумента
         */
        public static void ensureNotNull(Object argument, String argumentName) {
            if (argument == null) {
                throw new IllegalArgumentException("Null '" + argumentName + "' not allowed.");
            }
        }

    johnsoft, 07 Сентября 2009

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