1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #9665

    +70

    1. 1
    FORMAT.format(Calendar.getInstance().getTime())

    Ну в календаре-то явно точнее время.

    roman-kashitsyn, 13 Марта 2012

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

    +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
    public boolean getSuccessSubmitted() {
        for (ReportDto report : getReports()) {
           if (!(report.getOrder().getReceiptDate() != null && report.getReportReceived())) {
               return false;
           }
        }
        return !(getReports().isEmpty());
    }
    
    public boolean getUnSuccessSubmitted(){
        for (ReportDto report : getReports()) {
            if (!(report.getOrder().getOrderDate() != null && !(report.getReportReceived()))) {
                return false;
            }
        }
        return !(getReports().isEmpty());
    }

    для классического трио нехватает лишь getFailSubmitted()

    roman-kashitsyn, 11 Марта 2012

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

    +70

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static void getUsers(User[] users)
    {
    		boolean b,bb;
    		for(int x=0;x<users.length;x++)
    			{
    				b=users[x].getNick().equals("------");
    				bb=users[x].getPassword().equals("------");
    				if (b==false && bb==false) {System.out.println("ник : "+users[x].getNick()+", пароль: "+users[x].getPassword()+", id: "+users[x].id+", " +"репутация: "+users[x].reputation);}
    				else {System.out.println("          НЕТ ДАННЫХ.        ");}
    			}
    }

    http://programmersforum.ru/showthread.php?t=185055

    Как по мне так забавно

    denis90, 24 Января 2012

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

    +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
    public class Brakets {
    	public static void main(String args[]) {
    		String sample;
    		if (args.length > 0 && args[0] != "")
    			sample = args[0];
    		else
    			sample = "asdf(sd{sd}sdfgs[sdfg{}]_)){}sdfg[sdfg{sdfg}]";
    		// init handler and add patterns
    		BracketHandler b = new BracketHandler();
    		b.add("[", "]");
    		b.add("{", "}");
    		b.add("[", "]");
    		b.add("(", ")");
    
    		// init input stack
    		CommonStack<BracketTemplate> result = new CommonStack<BracketTemplate>();
    
    		for (int i = 0; i < sample.length(); i++) {
    			// Assert that pattern is one characted length
    			String subString = sample.substring(i, i + 1);
    			BracketTemplate tmp = b.getTemplate(subString);
    			if (tmp != null) {
    				if (tmp.isStartPattern(subString)) {
    					result.push(tmp);
    				} else {
    					BracketTemplate t = result.pop();
    					if (t == null || !t.isEndPAttern(subString)) {
    						System.out.print("Check failed");
    						return;
    					}
    				}
    
    			}
    		}
    		System.out.print("Check passed");
    	}
    }

    Ещё одна реализация Brackets, теперь и на Java (от автора предыдущего класса стека)

    varg242, 21 Января 2012

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

    +70

    1. 1
    2. 2
    3. 3
    4. 4
    @Override protected void finalize()
    {
        Runtime.addShutdownHook();
    }

    Здесь без комментариев...

    dwinner, 09 Ноября 2011

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

    +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
    for (AllResponseCache actionResponse : allResponses) {
                    if (null != actionResponse.getResponseStatus() && actionResponse.getResponseStatus().length() > 0) {
                        for (ResponseSubjectCache subj : actionResponse.getSubjects()) {
                            // find needed element
                            if (subj.getClaims() != null) {
                                for (ClaimCache claimCache : subj.getClaims()) {
                                    Seller seller = getSellerByPersonMatched(pool, claimCache);
                                    if (seller != null) {
                                        if (mapToSyncronize.get(seller) == null) {
                                            mapToSyncronize.put((SellerrEntity) seller, new LinkedList<ReportResponseCache>());
                                        }
                                        mapToSyncronize.get(seller).add(actionResponse);
                                    }
                                }
                            }
                        }
                    }
                }

    Индусы и "for-if"-ы.

    Я уж думал будет хронология как в России с "президентами" - "лысый, волосатый, лысый, волосатый" и так далее.
    А тут "for, if, for, if" но в конце всё-таки 2 иф-а!

    Dimedrol, 25 Октября 2011

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

    +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
    //обработка поведения кнопки копировать
          if(tni.isTreeStruct()) {
             copyDocuments.setEnabled(false);
          }
          else {
             copyDocuments.setEnabled(true);
             if(jTree.getSelectionCount() > 1) {
                copyDocuments.setEnabled(false);
             }
             else {
                copyDocuments.setEnabled(true);
             }
          }
          //-----------------------------------------------------------
    
          //обработка поведения кнопки копировать c файлами
          if(tni.isTreeStruct()) {
             copyDocsWithFile.setEnabled(false);
          }
          else {
             copyDocsWithFile.setEnabled(true);
             if(jTree.getSelectionCount() > 1) {
                copyDocsWithFile.setEnabled(false);
             }
             else {
                copyDocsWithFile.setEnabled(true);
             }
          }
          //-----------------------------------------------------------

    Это - "Гребаный копипаст"

    maxt, 01 Июля 2011

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

    +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
    import java.util.Random;
    public class A {
    	public static void main(String args[]) {
    		int minimalSuccessTime = Integer.MAX_VALUE;
    		int maximalSuccessTime = Integer.MIN_VALUE;
    		for(int i = 0; i < 10000; i++) {
    			Random rnd = new Random();
    			boolean state = rnd.nextBoolean();
    			final byte prisonersCount = 100;
    			boolean prisoners[] = new boolean[prisonersCount];
    			byte prisonersCounted = 1;
    			int daysPassed = 0;
    			while(true) {
    				daysPassed++;
    				int tmp = rnd.nextInt(prisonersCount);
    				if(tmp == 0) {
    					if(state) {
    						state = false;
    						prisonersCounted++;
    						if(prisonersCounted == prisonersCount) {
    							break;
    						}
    					}
    				} else {
    					if(!state && !prisoners[tmp]) {
    						state = true;
    						prisoners[tmp] = true;
    					}
    				}
    			}
    			if(daysPassed < minimalSuccessTime) {
    				minimalSuccessTime = daysPassed;
    			}
    			if(daysPassed > maximalSuccessTime) {
    				maximalSuccessTime = daysPassed;
    			}
    		}
    		System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
    		System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
    	}
    }

    One hundred prisoners have been newly ushered into prison. The warden tells
    them that starting tomorrow, each of them will be placed in an isolated cell,
    unable to communicate amongst each other. Each day, the warden will choose
    one of the prisoners uniformly at random with replacement, and place him in
    a central interrogation room containing only a light bulb with a toggle switch.
    The prisoner will be able to observe the current state of the light bulb. If he
    wishes, he can toggle the light bulb. He also has the option of announcing that
    he believes all prisoners have visited the interrogation room at some point in
    time. If this announcement is true, then all prisoners are set free, but if it is
    false, all prisoners are executed.
    The warden leaves, and the prisoners huddle together to discuss their fate.
    Can they agree on a protocol that will guarantee their freedom?

    guest2011, 14 Июня 2011

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

    +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
    public static void m()
        {
            cO = cO + "3659";
            RecordStore recordstore;
            if((recordstore = RecordStore.openRecordStore("saves", true)) != null)
            {
                if(recordstore.getNumRecords() == 20)
                    recordstore.closeRecordStore();
                for(; recordstore.getNumRecords() < 20; recordstore.addRecord(null, 0, 0));
                byte abyte0[] = recordstore.getRecord(6);
                recordstore.setRecord(20, abyte0, 0, abyte0 == null ? 0 : abyte0.length);
                recordstore.closeRecordStore();
            }
            return;
            JVM INSTR dup ;
            Exception exception;
            exception;
            printStackTrace();
            cQ.concat("fuck ur hax, nigers :) muahaha :D");
            cQ + "x";
            return;
        }

    Не поверите, но это было найдено в недрах java игрушки :)

    Govnocoder#0xFF, 07 Апреля 2011

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

    +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
    public class HttpServer {
    
        public static void main(String[] args) throws Throwable {
            ServerSocket ss = new ServerSocket(8080);
            while (true) {
                Socket s = ss.accept();
                System.err.println("Client accepted");
                new Thread(new SocketProcessor(s)).start();
            }
        }
    
        private static class SocketProcessor implements Runnable {
    
            private Socket s;
            private InputStream is;
            private OutputStream os;
    
            private SocketProcessor(Socket s) throws Throwable {
                this.s = s;
                this.is = s.getInputStream();
                this.os = s.getOutputStream();
            }
    
            public void run() {
                try {
                    readInputHeaders();
                    writeResponse("<html><body><h1>Hello from Habrahabr</h1></body></html>");
                } catch (Throwable t) {
                    /*do nothing*/
                } finally {
                    try {
                        s.close();
                    } catch (Throwable t) {
                        /*do nothing*/
                    }
                }
                System.err.println("Client processing finished");
            }
    
            private void writeResponse(String s) throws Throwable {
                String response = "HTTP/1.1 200 OK\r\n" +
                        "Server: YarServer/2009-09-09\r\n" +
                        "Content-Type: text/html\r\n" +
                        "Content-Length: " + s.length() + "\r\n" +
                        "Connection: close\r\n\r\n";
                String result = response + s;
                os.write(result.getBytes());
                os.flush();
            }
    
            private void readInputHeaders() throws Throwable {
                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                while(true) {
                    String s = br.readLine();
                    if(s == null || s.trim().length() == 0) {
                        break;
                    }
                }
            }
        }
    }

    Это весь код вебсервера.
    К слову сказать, это от сюда:
    http://habrahabr.ru/blogs/java/69136/

    Говногость, 17 Декабря 2010

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