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

    +70

    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
    @OnEvent("search")
    	@ReportGritter(title = "message:error", text = "message:database_error")
    	Results search() {
    		final List<Result> results = new ArrayList<Result>();
    		int count = 0;
    		final List<?> search1 = this.bands.search(this.query);
    		final String group1 = HSSearch.GROUP_BANDS;
    		if (!search1.isEmpty()) {
    			results.addAll(this.transform(search1, group1));
    			count += search1.size();
    		}
    		final List<?> search2 = this.albums.search(this.query);
    		final String group2 = HSSearch.GROUP_ALBUMS;
    		if (!search2.isEmpty()) {
    			results.addAll(this.transform(search2, group2));
    			count += search2.size();
    		}
    		final List<?> search3 = this.tracks.search(this.query);
    		final String group3 = HSSearch.GROUP_TRACKS;
    		if (!search3.isEmpty()) {
    			results.addAll(this.transform(search3, group3));
    			count += search3.size();
    		}
    		this.results.setResults(results);
    		this.results.setCount(count);
    		return this.results;
    	}
    
    	private <E> String toTitle(final E item) {
    		if (item instanceof BandEntity) {
    			return ((BandEntity) item).getTitle();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return String.format("%s (%d)", aitem.getTitle(), Integer.valueOf(aitem.getYear()));
    		}
    		if (item instanceof TrackEntity) {
    			return ((TrackEntity) item).getTitle();
    		}
    		return item.toString();
    	}
    
    	private <E> String toUrl(final E item) {
    		if (item instanceof BandEntity) {
    			final BandEntity bitem = (BandEntity) item;
    			return this.links.createPageRenderLinkWithContext(Band.class, bitem.getLetter(), bitem.getAlias())
    					.toAbsoluteURI();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, aitem.getBand().getLetter(),
    					aitem.getBand().getAlias(), aitem.getAlias()).toAbsoluteURI();
    		}
    		if (item instanceof TrackEntity) {
    			final TrackEntity titem = (TrackEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, titem.getAlbum().getBand().getLetter(),
    					titem.getAlbum().getBand().getAlias(), titem.getAlbum().getAlias()).toAbsoluteURI();
    		}
    		return this.links.createPageRenderLinkWithContext("").toAbsoluteURI();
    	}
    
    	private <E> List<Result> transform(final List<E> search, final String groupName) {
    		final ArrayList<Result> res = new ArrayList<Result>();
    		if (!search.isEmpty()) {
    			final String group = this.messages.get(groupName);
    			res.add(new Result(group));
    			for (final E item : search) {
    				res.add(new Result(group, this.toTitle(item), this.toUrl(item)));
    			}
    		}
    		return res;
    	}

    DRY in Action.
    мое домашнее творчество.

    Lure Of Chaos, 06 Июня 2013

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    changeFace($arr) {
            switch ($arr['custtype']) {
                    case 2: $facetype = 'Ф'; break; //Физическое
                    case 1: $facetype = 'Ю'; break; //Юридическое лицо
                    default: $facetype = ' '; break;
            }
            return $facetype;
    }

    В этом смысле лицо - "person"

    DIX315, 06 Июня 2013

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    PUBLIC STATIC FUNCTION /* ЭТО Я НЕ КАПСОМ ПИШУ, ЭТО Я ШИФТ ДЕРЖУ */ selectFor_confirm($delivery_mode, PtrCustomSelector $order_sel)
        {
            /* ... */
        }

    Последствия пятничного deadline-кодинга ^_^

    AntonioK, 06 Июня 2013

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

    +152

    1. 1
    2. 2
    // maybe even strtolower($value)?
    $bool = ($value && ($value !== 'false') && ($value !== 'null'));

    А разгадка одна — безблагодатность^w кривой JSON.

    AntonioK, 06 Июня 2013

    Комментарии (0)
  5. C++ / Говнокод #13120

    +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
    void Cluster::CloseConnection()
    {
        m_Connection->close();
        if (!m_Connection->IsOK())
            throw ConnectionError(m_Connection->LastError());
    }
    
    void ClusterGroup::RemoveCluster(int iIndex)
    {
        Cluster *pSubCluster = m_SubClusters->At[i];
        pSubCluster->CloseConnection();
        delete pSubCluster;
        m_SubClusters->SetAt(i, NULL);
    }

    И потекло...

    Lavir_the_Whiolet, 06 Июня 2013

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $currurl = str_replace(" ", '', $this->helper('core/url')->getCurrentUrl());
    if (strpos($currurl, 'index.php/')) {
        $currurl = str_replace('index.php/', '', $currurl);
    } else if (strpos($currurl, '/index.php')) {
        $currurl = str_replace('index.php', '', $currurl);
    }
    $url_suffix = (substr($currurl, strlen(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB))));
    <?php if (strlen($url_suffix) <= 0) : #not homepage ?>
    ...

    Magento. Увидел в template, код одной английской компании.

    crook, 06 Июня 2013

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

    +77

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if (groundsDTO.isChildCome()) {
        ZAGSAffiliation.Grounds.CHILDCONSENT childConsest = grounds.addNewCHILDCONSENT();
        childConsest.setISCHILDCONSENT(groundsDTO.isChildAgreeWithFillation());
        if (!groundsDTO.isChildCome()) {
             tranferConfirmation(childConsest.addNewCONSENTNOTAR(),groundsDTO.getChildAgree());
        }
    }

    А вдруг ребенок все-таки не придет?

    killogramm, 06 Июня 2013

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

    +121

    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
    public int sum(final Type type, final int increment) {
    	switch(type) {
    	case REDOS: 
    		return redos += increment;
    	case ONCE: 
    		return onceRedoneOrders += increment;
    	case TWICE: 
    		return twiceRedoneOrders += increment;
    	case THRICE: 
    		return thriceRedoneOrders += increment;
    	case MORE: 
    		return moreRedoneOrders += increment;
    	default:
    		break;
    	}
    	
    	throw new RuntimeException();
    }

    Осталось в наследство. Даже не знаю, что хотел изобразить предыдущий оратор...

    someone, 06 Июня 2013

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

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $startYear = date('Y', $programs[$i][1]);
                    $startMounth = date('m', $programs[$i][1]);
                    $startDay = date('d', $programs[$i][1]);
                    $startHour = date('H', $programs[$i][1]);
                    $startMinute = date('i', $programs[$i][1]);
                    $startSecond = date('s', $programs[$i][1]);
                    $startDate = mktime($startHour + $timeoffset, $startMinute, $startSecond, $startMounth, $startDay, $startYear);

    Поправка на часовой пояс

    stsaranchin, 06 Июня 2013

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

    +135

    1. 1
    #define __click_window_chkarmor (!((inventory==plr->inventory)&&(((slot==5)&&!hasflag(consts.item_flags[plr->holdingitem->type],ITEM_FLAG_ARMOR_HEAD))||((slot==6)&&!hasflag(consts.item_flags[plr->holdingitem->type],ITEM_FLAG_ARMOR_CHEST))||((slot==7)&&!hasflag(consts.item_flags[plr->holdingitem->type],ITEM_FLAG_ARMOR_FEET))||((slot==8)&&!hasflag(consts.item_flags[plr->holdingitem->type],ITEM_FLAG_ARMOR_BOOTS)))))

    Форматирование сохранено

    kostoprav, 05 Июня 2013

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