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

    +1

    1. 1
    there are java.io.FileNotFoundException and java.nio.file.NoSuchFileException . Both are subclasses of IOException, neither of them is a subclass of the opposite.

    DypHuu_niBEHb, 20 Апреля 2021

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

    +2

    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
    package org.trishinfotech.builder;
    
    public class Car {
    
        private String chassis;
        private String body;
        private String paint;
        private String interior;
        
        public Car() {
            super();
        }
    
        public Car(String chassis, String body, String paint, String interior) {
            this();
            this.chassis = chassis;
            this.body = body;
            this.paint = paint;
            this.interior = interior;
        }
    
        public String getChassis() {
            return chassis;
        }
    
    	public void setChassis(String chassis) {
            this.chassis = chassis;
    
        }
    
        public String getBody() {
            return body;
        }
    
        public void setBody(String body) {
            this.body = body;
        }
    
        public String getPaint() {
            return paint;
        }
    
        public void setPaint(String paint) {
            this.paint = paint;
        }
    		public String getInterior() {
            return interior;
        }
    
        public void setInterior(String interior) {
            this.interior = interior;
        }
    
        public boolean doQualityCheck() {
            return (chassis != null && !chassis.trim().isEmpty()) && (body != null && !body.trim().isEmpty())
                    && (paint != null && !paint.trim().isEmpty()) && (interior != null && !interior.trim().isEmpty());
        }
    
        @Override
        public String toString() {
            // StringBuilder class also uses Builder Design Pattern with implementation of java.lang.Appendable interface
            StringBuilder builder = new StringBuilder();
            builder.append("Car [chassis=").append(chassis).append(", body=").append(body).append(", paint=").append(paint)
            return builder.toString();
        }
    
    }

    https://habr.com/ru/company/otus/blog/552412/
    Паттерн проектирования Builder (Строитель) в Java

    PolinaAksenova, 15 Апреля 2021

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

    0

    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
    public static boolean isMagicSquare(int[][] a) {
        boolean isMagic = true;
        boolean isSquare = true;
        
        //square? checking here.
        for(int i = 0; i < a.length; i++) {
                if(a.length != a[i].length) {
                        isSquare = false;
                }
        }
        
        if(isSquare) {
            int sum = 0;
            int nextSum = 0;
            
            //first row
            for(int i = 0; i < a.length; i++) {
                    sum += a[0][i]; 
            }
            
            
            //rows
            for(int i = 1; i < a.length; i++) {
                    for(int j = 0; j < a.length; j++) {
                            nextSum += a[i][j];
                    }
                
                    if(nextSum != sum) {
                            isMagic = false;
                            break;
                    } else {
                            nextSum = 0;
                    }
            }
            
            //columns
            if(isMagic) {
                    for(int i = 0; i < a.length; i++) {
                            for(int j = 0; j < a.length; j++) {
                                    nextSum += a[j][i];
                            }
                        
                            if(nextSum != sum) {
                                    isMagic = false;
                                    break;
                            } else {
                                    nextSum = 0;
                            }
                    }
                
                    //diagonals
                    if(isMagic) {
                            for(int i = 0; i < a.length; i++) {
                                    nextSum += a[i][i];
                            }
                            
                            if(nextSum != sum) {
                                    isMagic = false;
                            } else {
                                    nextSum = 0;
                            }
                        
                            if(isMagic) {
                                    int j = a.length - 1;
                                
                                    for(int i = 0; i < a.length; i++) {
                                            nextSum += a[i][j];
                                            
                                            if(j > 0) {
                                                    j--;
                                            }
                                    }
                                
                                    if(nextSum != sum) {
                                            isMagic = false;
                                    }
                            }
                    }
            }
            
        } else {
                isMagic = false;
        }
    
        return isMagic;
    }

    Write a method called isMagicSquare that accepts a two-dimensional array of integers as a parameter and returns true if it is a magic square. A square matrix is a magic square if it is square in shape (same number of rows as columns, and every row the same length), and all of its row, column, and diagonal sums are equal. For example, [[2, 7, 6], [9, 5, 1], [4, 3, 8]] is a magic square because all eight of the sums are exactly 15.

    (https://practiceit.cs.washington.edu/problem/view/bjp3/chapter7/e20%2DisMagicSquare)

    Работает, но код нечитаемый. Как сократить? Понятия не имею.

    imrnccc, 28 Марта 2021

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

    +5

    1. 1
    2. 2
    3. 3
    private static String getMargin(final int size) {
            return "                                                                                                                             ".substring(0, 6 * size);
        }

    Как создать пустую строку с заданной длиной...

    nekkiy, 24 Марта 2021

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

    +1

    1. 1
    Class HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor

    https://javadoc.io/doc/org.aspectj/aspectjweaver/1.8.10/org/aspectj/weaver/patterns/HasThisTypePatternTriedToSneakInSomeGene ricOrParameterizedTypePatternMatchingStu ffAnywhereVisitor.html

    6oHo6o, 21 Марта 2021

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

    +1

    1. 1
    .

    https://vc.ru/flood/149783-podgotovte-nomer-pablik-steytik-dzhava-tochka-pomoshchnik-oleg-zachital-sboy-vo-vremya-testa-v-koll-centre-tinkoff

    3_dar, 17 Февраля 2021

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

    0

    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
    {
        "error": false,
        "message": "Ok",
        "data": {
            "countries": [
                {
                    "country": {
                        "id": 24,
                        "iso_a2": "CA",
                        "name": "Canada",
                        "prefix": "1",
                        "vendors": [
                            1
                        ]
                    },
                    "city": {
                        "id": 3723,
                        "region_id": 8,
                        "name": "Toronto",
                        "prefix": "416",
                        "icon_url": null,
                        "setup": 0.25,
                        "monthly": 1.88
                    }
                },
                {
                    "country": {
                        "id": 51,
                        "iso_a2": "IL",
                        "name": "Israel",
                        "prefix": "972",
                        "vendors": [
                            1
                        ]
                    },
                    "city": {
                        "id": 122,
                        "region_id": null,
                        "name": "Jerusalem",
                        "prefix": "2",
                        "icon_url": null,
                        "setup": 0.25,
                        "monthly": 1.88
                    }
                },
                {
                    "country": {
                        "id": 94,
                        "iso_a2": "GB",
                        "name": "United Kingdom",
                        "prefix": "44",
                        "vendors": [
                            1
                        ]
                    },
                    "city": {
                        "id": 4701,
                        "region_id": null,
                        "name": "London",
                        "prefix": "207",
                        "icon_url": null,
                        "setup": 0.25,
                        "monthly": 1.88
                    }
                },
                {
                    "country": {
                        "id": 95,
                        "iso_a2": "US",
                        "name": "United States",
                        "prefix": "1",
                        "vendors": [
                            1,
                            2
                        ]
                    },
                    "city": {
                        "id": 6400,
                        "region_id": 44,
                        "name": "New York",
                        "prefix": "332",
                        "icon_url": null,
                        "setup": 0.25,
                        "monthly": 1.88
                    }
                }
            ]
        }
    }

    CTO написал апишечку для возврата доступных локейшнов по странам для покупки телефонных номеров

    изыск 2021 я такого и в 2000ых не встречал !!!

    alexis-ag, 01 Февраля 2021

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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    This would raise the true nightmare. A type variable is a different beast than the actual type of a concrete instance. 
    A type variable could resolve to a, e.g. ? extends Comparator<? super Number> to name one (rather simple) example. 
    Providing the necessary meta information would imply that not only object allocation becomes much more expensive, 
    every single method invocation could impose these additional cost, to an even bigger extend as we are now not only 
    talking about the combination of generic classes with actual classes, but also every possible wildcarded combination, 
    even of nested generic types.

    https://stackoverflow.com/a/38060012

    Джавист-долбоеб с пеной у рта защищает type erasure, задавая вопросы "Does it [c#] have an equivalent of Function.identity()? " в комментариях и собирая плюсы таких же поехавших.
    В качестве аргументов он предлагает:

    1) сложна
    2) хранить информацию о типах в рантайме означает что в рантайме придется хранить информацию о типах!!!
    3) [s]ма-те-ма-ти-ка[/x] реф-лек-си-я

    Причем ведь наверняка знает и про темплейты в крестах, и про то что шарп такой хуйней не страдает.

    Fike, 05 Января 2021

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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    package java.util;
    
    public final class Optional<T> {
        public<U> Optional<U> map(Function<? super T, ? extends U> mapper) {
            Objects.requireNonNull(mapper);
            if (!isPresent())
                return empty();
            else {
                return Optional.ofNullable(mapper.apply(value));
            }
        }
    }

    Они не только не знают, что else после if не нужен и лишь привносит лишний нестинг, они даже единый стиль расставления фигурных скобок выдержать не могут

    Fike, 11 Ноября 2020

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

    +2

    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
    package java.nio.file;
    
    public final class Files {
        /**
         * Convert a Closeable to a Runnable by converting checked IOException
         * to UncheckedIOException
         */
        private static Runnable asUncheckedRunnable(Closeable c) {
            return () -> {
                try {
                    c.close();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            };
        }
    }

    стандартные потрошки джавы это какая-то запредельная протомразь, нарушающая собственные законы физики и запрещающая делать это другим

    Fike, 21 Октября 2020

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