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

    +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
    long[] times = new long[9];
    times[0] = System.currentTimeMillis();
    initPsrList();
    times[1] = System.currentTimeMillis();
    initPsrHierarchy();
    times[2] = System.currentTimeMillis();
    initPsrCheckList()
    times[3] = System.currentTimeMillis();
    initTranslationTables();
    times[4] = System.currentTimeMillis();
    initTranslationInfo()
    times[5] = System.currentTimeMillis();
    initVoltage();
    times[6] = System.currentTimeMillis();        
    initElectroMetterPrecision();
    times[7] = System.currentTimeMillis();        
    initMeasTransformers();
    times[8] = System.currentTimeMillis();
    
    long diff;
    System.out.println("\n\n\n\n******************************************************************");
    diff = times[1] - times[0];
    System.out.println("-- initPsrList() = " + diff + "ms");
    diff = times[2] - times[1];
    System.out.println("-- initPsrHierarchy() = " + diff + "ms");
    diff = times[3] - times[2];
    System.out.println("-- initPsrCheckList() = " + diff + "ms");
    diff = times[4] - times[3];
    System.out.println("-- initTranslationTables() = " + diff + "ms");
    diff = times[5] - times[4];
    System.out.println("-- initTranslationInfo() = " + diff + "ms");
    diff = times[6] - times[5];
    System.out.println("-- initVoltage() = " + diff + "ms");
    diff = times[7] - times[6];
    System.out.println("-- initElectroMettersPrecision() = " + diff + "ms");
    diff = times[8] - times[7];
    System.out.println("-- initMeasTransformers() = " + diff + "ms");
    diff = times[8] - times[0];
    System.out.println("total = " + diff + "ms");
    System.out.println("\n******************************************************************\n\n\n\n ");

    Код подготовки отображаемой страницы на сервере.

    Eyeless, 12 Мая 2010

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

    +75

    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
    private void changeName() throws Exception {
        File inFile = new File(torrentFilePath);
        File outFile = new File(torrentFilePath + Hashes.getRandom(6));
        BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(inFile));
        BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(outFile));
    
        int bytesRead;
        int totalBytesRead = 0;
        byte[] bytes = new byte[1024];
        String inString = "";
    
        while((bytesRead = inStream.read(bytes)) > 0) {
            inString += new String(bytes, 0, bytesRead);
            totalBytesRead += bytesRead;
        }
        inStream.close();
        int len = inString.length();
        int idx = inString.indexOf(NAME_TAG);
        int lastidx = inString.indexOf(objectName) + objectName.length();
    
        outStream.write(bytes, 0, idx + NAME_TAG.length());
        outStream.write(new String(objectKey.length() + ":" + objectKey).getBytes());
        outStream.write(bytes, lastidx, totalBytesRead - lastidx);
    
        outStream.close();
        outFile.renameTo(inFile);
    }

    Горячий привет из солнечной Калифорнии. Таким образом студенты из Университета Санта-Барбары меняют имя файла в торренте.

    raorn, 11 Мая 2010

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static String cutN(String s,int n) { 
            char [] chars = s.toCharArray(); 
            String result = ""; 
            if (chars.length<n) throw new RuntimeException(); 
            for (int l=0; l<n;l++) { 
                result += chars[l]; 
            } 
            return result; 
        }

    http://www.linux.org.ru/forum/development/4858351

    qnikst учит новичка говнокодить.

    bbk123, 08 Мая 2010

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

    +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
    public enum MONTHS {
    		January(31), February(28), March(31), April(30), May(31), June(30), July(31), August(31), September(30), October(31), November(30), December(31);
    		
    		private int days;
    		
    		private MONTHS(int days){
    			this.days = days;
    		}
    
    		public int getDays() {
    			return days;
    		}
    
    		public void setDays(int days) {
    			this.days = days;
    		}
    		
    		public static int getIndex(MONTHS month){
    			int i = 0;
    			for (MONTHS m : MONTHS.values()) {
    				if(m.equals(month)){
    					return i;
    				}
    				i++;
    			}
    			return 0;
    		}
    	}

    Хоть код и GWT (нету j.u.Calendar), но все равно феерично, я считаю.

    OlegYch, 07 Мая 2010

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

    +77

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (InputField.class.isInstance(comp))
            {
                InputField f = (InputField)comp;
                DataDate dd=f.getDate();
                val = readDate(dd);
            }
            else
            {
                throw new ClassCastException();
            }

    Комментарии излишни

    pirj, 07 Мая 2010

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

    +75

    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
    private String getIdString() {
            String answer = Integer.toHexString(id.intValue());
            switch (answer.length()) {
            case 0:
                answer = "00000000";
                break;
            case 1:
                answer = "0000000" + answer;
                break;
            case 2:
                answer = "000000" + answer;
                break;
            case 3:
                answer = "00000" + answer;
                break;
            case 4:
                answer = "0000" + answer;
                break;
            case 5:
                answer = "000" + answer;
                break;
            case 6:
                answer = "00" + answer;
                break;
            case 7:
                answer = "0" + answer;
                break;
            }
            return answer;
        }

    JBoss Netty org.jboss.netty.channel.AbstractChannel

    yvu, 30 Апреля 2010

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

    +67

    1. 1
    2. 2
    3. 3
    public boolean isActive() {
            return !isKilling() && !isKilled() && !isKillPending();
        }

    Made in Estonia (part 2)

    bot225, 28 Апреля 2010

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

    +77

    1. 1
    private final List<ItemInfo> _items = Collections.synchronizedList(new Vector<ItemInfo>());

    Пример убер-синхронизации (чтоб наверняка).
    Используется и по сей день.

    Кусок из крупного эмулятора сервера L2 (Потомок сборки L2Rebellion).

    VirtualVoid, 28 Апреля 2010

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

    +84

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public void setPhones(List<PhoneNumber> phones) throws Exception {
        this.phones = phones;
        this.phones.clear();
        this.phones.addAll(phones);
    }

    Вот такой метод нашёл сегодня в коде.

    asolntsev, 21 Апреля 2010

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

    +71

    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 XXX implements YYY
    {
        public static final String UTILITYBATCHES = "utilityBatches";
        public static final String UTILITYCALCULATIONS = "utilityCalculations";
        public static final String WARDREGISTRATION = "wardRegistration";
        public static final String WARDINSPECTIONS = "wardInspections";
        public static final String WARDPRIMARYREGISTRATION = "wardPrimaryRegistration";
        public static final String SOCIALEVENTS2DOCUMENTS = "socialEvents2documents";
        public static final String SOCIALEVENTS = "socialEvents";
        public static final String SOCIALPACKAGES = "socialPackages";
        public static final String SOCIALAIDS = "socialAids";
        public static final String PRIVCATEGORIES = "privCategories";
        public static final String PAYMENTS = "payments";
        public static final String PAYMENTDETAILS = "paymentDetails";
        public static final String PAYMENTBATCHES = "paymentBatches";
        public static final String FAMILYRELATIONS = "familyRelations";
        public static final String FOSTERFAMILIES = "fosterFamilies";
        public static final String FAMILYMEMBERS = "familyMembers";
        public static final String INVALIDNESS = "invalidness";
        public static final String HEALTHINSPECTIONS = "healthInspections";
        public static final String EMPLOYMENTS = "employments";
        public static final String EDUCATION = "education";
        public static final String DOCUMENTS = "documents";
        public static final String FAMILIES = "families";
        public static final String DECORATIONS = "decorations";
        public static final String CALCULATIONS = "calculations";
        public static final String ATTRIBUTEVALUEHISTORY = "attributeValueHistory";
        public static final String ATTRIBUTEVALUES = "attributeValues";
        public static final String ASSIGNMENTS = "assignments";
        public static final String ADDRESSES = "addresses";
        public static final String ATTACHMENTS = "attachments";
        public static final String PERSONS = "persons";
        public static final String OCCUPANCIES = "occupancies";
        public static final String PROPERTIES = "properties";
        public static final String BUILDINGS = "buildings";
        public static final String WELFAREDELIVERY = "welfareDelivery";
    }

    clipper, 20 Апреля 2010

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