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

    +79

    1. 1
    this.query = this.query == url.getQuery( ) ? this.query : url.getQuery( );

    raorn, 11 Августа 2010

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

    +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
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    class game {
      public static void main (String args[])
          throws java.io.IOException {
     
        double x = 0.0;
        byte php = 100, mhp = 100, pd = 0, md = 0;
        char pd_ch;
        boolean b1, b2;
     
        System.out.println("Welcome to \"Kill the mob\" v0.1!");
        System.out.println();
        System.out.println("While you where wandering in deep dark tunnels, a mob appeared in your way.");
        System.out.println("It appeared to be very agressive, so a fight started.");
        System.out.println();
     
        do {
          System.out.println("Your opponent is ready to act. You need to do something. What are you going to do?");
          System.out.print("Enter \"1\" to attack, \"2\" to defend yourself and \"3\" to regenerate: ");
          pd_ch = (char) System.in.read();
          if (pd_ch == '1')
            pd = 1;
          else if (pd_ch == '2')
            pd = 2;
          else
            pd = 3;
          x = Math.random();
          if (x < 0.33333)
            md = 1;
          else if (x > 0.66666)
            md = 3;
          else
            md = 2;
          System.out.println(md);
          System.out.println(pd);
          switch(pd) {
            case 1:
              System.out.print("You chose to attack, while mob chose to ");
              switch (md) {
                case 1:
                  System.out.println("attack too!");
                  System.out.println("You both lose 20 HP.");
                  php -= 20;
                  mhp -= 20;
                  break;
                case 2:
                  System.out.println("defend.");
                  System.out.println("You did not manage to hurt him.");
                  break;
                case 3:
                  System.out.println("regenerate.");
                  System.out.println("He lost 30 HP.");
                  mhp -= 30;
                  break;
              }
              break;
            case 2:
              System.out.print("You chose to defend, while mob chose to ");
              switch (md) {
                case 1:
                  System.out.println("attack.");
                  System.out.println("You did not let him hurt you.");
                  break;
                case 2:
                  System.out.println("defend too!");
                  System.out.println("You standed like two retards.");
                  break;
                case 3:
                  System.out.println("regenerate.");
                  System.out.println("He gained 20 HP.");
                  mhp += 20;
                  break;
              }
              break;
            case 3:
              System.out.print("You chose to regenerate, while mob chose to ");
              switch (md) {
                case 1:
                  System.out.println("attack.");
                  System.out.println("You was completely protectless. you you've lost 30 HP.");
                  php -= 30;
                  break;
                case 2:
                  System.out.println("defend.");
                  System.out.println("He standed like a retard, while you gained 20 HP.");
                  php += 20;
                  break;
                case 3:
                  System.out.println("regenerate too!");
                  System.out.println("Your energies helped each other, so you both gained 30 HP.");
                  mhp += 30;
                  php += 30;
                  break;
              }
              break;
          }
          System.out.println("Your HP: " + php);

    Цикл после одного ввода делается какого-то хуя 3 раза, причем с рандомными (1, 2, 3) pd и md. ЧЯДНТ?

    jesuschrist, 10 Августа 2010

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

    +112

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    private List<String> tList = new ArrayList<String>();
                ...........
    	for (String refAttr : refAttrs) {
    		t = tag.getAttribute(refAttr);
    		if (!tList.contains(t))
    			if (isCorrect(t))
    				tList.add(t);
            }

    как-то позабыл я о Сетах

    3.14159265, 09 Августа 2010

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

    +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
    public static void setSQLSafeFormat(JFormattedTextField ftf){
        DefaultFormatter sqlSafeFormatter = new DefaultFormatter(){
            @Override
            public Object stringToValue(String string) throws ParseException {
                string = string.replaceAll("\'", "");
                return super.stringToValue(string);
            }
            @Override
            public String valueToString(Object value) throws ParseException {
                 String result = super.valueToString(value);
                 return result.replaceFirst("\'", "");
            }
        };
        sqlSafeFormatter.setOverwriteMode(false);
        ftf.setFormatterFactory(new DefaultFormatterFactory(sqlSafeFormatter));
    }
    public static void setSQLSafeFilter(JTextField txt){
        DocumentFilter dc = new DocumentFilter(){
            @Override
            public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
                if(!string.contains("'"))
                super.insertString(fb, offset, string, attr);
            }
            @Override
            public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
                if(!text.contains("'"))
                super.replace(fb, offset, length, text, attrs);
            }
        };
        AbstractDocument asb = (AbstractDocument)txt.getDocument();
        asb.setDocumentFilter(dc);
    }

    суровая борьба с sql injection

    borka, 09 Августа 2010

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

    +71

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public void changeUI() {
        // Во все контролы ниже вместо .setEnabled(true) пишем
        // .setEnabled(_true), чтобы не рассерить
        // контролы при поднятии формы на просмотр
        boolean _true = getMainBehaviour().canEditForm() != ReadOnlyState.READ_ONLY;
        ...
    }

    borka, 06 Августа 2010

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

    +71

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(time.compareTo(startCheckTime) < 0)
    	return time.compareTo(startCheckTime);
    else if(time.compareTo(endCheckTime) > 0)
        return time.compareTo(startCheckTime);
    time.compareTo(startCheckTime);
    	return 0;

    welvet, 04 Августа 2010

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

    +74

    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
    public static int count(String s) {
        int res = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == '1') res++;
        }
        return res;
    }
    
    public List<VDictLiability> get(String currency_id, String usedTrailer, Date actualDate, String contract_class_id, String product_id, String risk_object_type_id) {
        for(int i = 0;i<5;i++){
            int j = 0;
            while(j < 32) {
                if(count(Integer.toBinaryString(j)) == i) {
                    String s = Integer.toBinaryString(j);
                    while (s.length() != 5) {
                        s = "0" + s;
                    }
                    List<VDictLiability> result = get(currency_id, usedTrailer, actualDate, contract_class_id, product_id, risk_object_type_id, s);
                    if(result.size() > 0) return result;
                }
                j++;
            }
        }
        return Collections.EMPTY_LIST;
    }
    
    public List<VDictLiability> get(String currency_id, String usedTrailer, Date actualDate, String contract_class_id, String product_id, String risk_object_type_id, String mask) {
        String territoryCode = App.config.getCurrentBrunchCode().substring(1, 3);
        
    ...
        
        HashMap<Double, VDictLiability> map = new HashMap<Double, VDictLiability>();
        for (VDictLiability liabilityRow : get()) {
            if(!territoryType.equals(liabilityRow.getterritory_type_id()) && !(mask.charAt(4) == '1' && liabilityRow.getterritory_type_id() == null)){
                continue;
            }
            if(actualDate != null && !CompareUtil.isInside(liabilityRow.getstart_date(), liabilityRow.getend_date(), actualDate)){
                continue;
            }
            if(((risk_object_type_id != null && !CompareUtil.isEquals(liabilityRow.getrisk_object_type_id(), risk_object_type_id)) && !(mask.charAt(0) == '1' && liabilityRow.getrisk_object_type_id() == null))){
                continue;
            }
            if(((product_id != null && !CompareUtil.isEquals(liabilityRow.getproduct_id(), product_id)) && !(mask.charAt(1) == '1' && liabilityRow.getproduct_id() == null))){
                continue;
            }
            if(((contract_class_id != null && !CompareUtil.isEquals(liabilityRow.getcontract_class_id(), contract_class_id)) && !(mask.charAt(2) == '1' && liabilityRow.getcontract_class_id() == null))){
                continue;
            }
            if((liabilityRow.getcurrency_id() != null & !CompareUtil.isEquals(liabilityRow.getcurrency_id(), currency_id)) && !(mask.charAt(3) == '1' && liabilityRow.getcurrency_id() == null)){
                continue;
            }
            if(liabilityRow.getis_used_trailer() != SQLUtils.NULL_INTEGER_VALUE & !CompareUtil.isEquals(""+liabilityRow.getis_used_trailer(), usedTrailer)){
                continue;
            }
            map.put(liabilityRow.getvalue(), liabilityRow);
        }
        
        ArrayList<VDictLiability> result = new ArrayList<VDictLiability>();
        result.addAll(map.values());
    ...
        return result;
    }
    
    public List<VDictLiability> get(String currency_id, boolean usedTrailer, Date actualDate, String contract_class_id, String product_id, String risk_object_type_id) {
        return get(currency_id, usedTrailer?"1":"0", actualDate, contract_class_id, product_id, risk_object_type_id);
    }

    Это ад

    borka, 03 Августа 2010

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

    +80

    1. 1
    2. 2
    3. 3
    String[] months = {"january", "february" ,"march" ,"april" ,"may" ,"june" ,"july" ,"august" ,"september" ,"october" ,"november" ,"december"};
    		SimpleDateFormat sdf = new SimpleDateFormat("MM");
    		String month = months[Integer.decode(sdf.format(date.getTime())) - 1];

    Пример паттерна Детонатор: Integer.decode падает начиная с 08го месяца, ожидая 8ю систему

    welvet, 02 Августа 2010

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

    +66

    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
    1. import java.security.MessageDigest;
       2. import java.security.NoSuchAlgorithmException;
       3.  
       4. public final class MD5Util {
       5.   public static final int MASK = 0xff;
       6.   public static final int RADIX = 16;
       7.  
       8.   private MD5Util() {
       9.   }
      10.  
      11.   public static String encrypt(String str) {
      12.     try {
      13.       MessageDigest md = MessageDigest.getInstance("MD5");
      14.       md.update(str.getBytes());
      15.       return byteToHexString(md.digest());
      16.     } catch (NoSuchAlgorithmException e) {
      17.       //doing smth
      18.     }
      19.   return null;
      20.   }
      21.  
      22.   public static String encrypt(byte[] data) {
      23.     try {
      24.       MessageDigest md = MessageDigest.getInstance("MD5");
      25.       md.update(data);
      26.       return byteToHexString(md.digest());
      27.     } catch (NoSuchAlgorithmException e) {
      28.       //doing smth
      29.     }
      30.     return null;
      31.   }
      32.  
      33.   public static String byteToHexString(byte[] hash) {
      34.     StringBuffer buf = new StringBuffer(hash.length * 2);
      35.  
      36.     for (byte b : hash) {
      37.       if ((b & MASK) < RADIX) {
      38.         buf.append("0");
      39.       }
      40.  
      41.       buf.append(Long.toString(b & MASK, RADIX));
      42.     }
      43.  
      44.     return buf.toString();
      45.   }
      46. }

    hromjo, 01 Августа 2010

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

    +82

    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
    private String addZerosToColor(String color)
        {
            switch(color.length())
            {
            case 1:
                color = (new StringBuilder()).append("00000").append(color).toString();
                break;
    
            case 2:
                color = (new StringBuilder()).append("0000").append(color).toString();
                break;
    
            case 3:
                color = (new StringBuilder()).append("000").append(color).toString();
                break;
    
            case 4:
                color = (new StringBuilder()).append("00").append(color).toString();
                break;
    
            case 5:
                color = (new StringBuilder()).append("0").append(color).toString();
                break;
            }
            return color;
        }

    Понятно и весьма эстетично :D

    VirtualVoid, 01 Августа 2010

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