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

    +69

    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
    package mypackage;
    import java.io.*;
    
    public class RimToArab {
    		public static void main(String [] args){
    			System.out.println("Enter the Roman numeral:");
    			String Rim = "";
    			char[] Rch = {'I','V','X','L','C','D','M'};
    			int[] Acf = {1,5,10,50,100,500,1000};
    			
    			
    			int i,j=0,rez=0;						
    			try {
    				BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
    				Rim = d.readLine();  
    			} catch  (IOException e) {
    				System.out.println("Input error!");
    			} 				
    			for (int c = Rim.length()-1; c>=0; --c ){				
    					for(i=6;i>=0; --i){
    						if (Rch[i]==Rim.charAt(c)){
    							if (j>Acf[i]){
    								rez=rez-Acf[i];
    							} else {
    								rez=rez+Acf[i];
    							}					
    							j=Acf[i];
    						}											
    					}							
    									
    			}				
    			if (rez!=0){
    				System.out.println(rez);
    			}	else {
    				System.out.println("Wrong format of input!");
    			}
    		}
    }

    говнокод наоборот римские в арабские

    Norick, 21 Марта 2015

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

    +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
    package mypackage;
    import java.io.*;
    
    public class ArabToRim{
    
        public static void main(String arg[]){
            String RimSym[] ={"I", "V", "X", "L","C","D","M"} ;
    		
    		
    		String Arab = "";
            System.out.println("Input simbol");
            try {
    			BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
    			Arab = d.readLine();  
            } catch  (IOException e) {
                System.out.println("Input ERROR");
            } 
    		Arab = new StringBuilder(Arab).reverse().toString();
    		String Rim = "";
    		String rez = "";
    		int n = 0;
    		int c = 0;
    		int i = 0;
    		
    		for(int k=Arab.length();k>0; --k){
    			int s = Character.getNumericValue(Arab.charAt(c));
    			rez = "";
    		
    			if (s<=3) {
    				for (i=s; i>0; --i){
    					rez=rez + RimSym[n];
    				}
    			}
    			if (s==4) {
    				rez=rez + RimSym[n]+RimSym[n+1];			
    			}
    			if (s==5) {
    				rez=rez + RimSym[n+1];
    			}
    			if (s>=6) {
    				if (s<9){
    					rez=rez + RimSym[n+1];
    					for (i=s-5; i>0; --i){
    						rez=rez + RimSym[n];
    					}
    				}
    			}
    			if (s==9) {
    				rez=rez + RimSym[n]+ RimSym[n+2];
    			}	
    			++c;
    			n = n+2;
    			Rim=rez+Rim;
    			
    			
    		}
    		System.out.println(Rim);		
        }
    }

    Говнокод арабские в римские

    Norick, 20 Марта 2015

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

    +79

    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
    builder.append(" SELECT ");
            for(int i=7;i>0;i--){            	
            	int month = cal.get(Calendar.MONTH) + 1;
                    int year = cal.get(Calendar.YEAR);
            	cal.add(Calendar.MONTH, -1);
            	builder.append(" IFNULL(SUM(IF((MONTH(FEED.feed_date)= "+ month +" && YEAR(FEED.feed_date)="+year+"),"+measurementByColumn+",0)),0) AS M"+i+ " , ");
            }
    builder.append(" IFNULL(MAX(IF((YEAR(FEED.feed_date)="+currentyear+" and FEED.feed_date=FEEDYEARDATA.curYearMaxFeedDate),"+measurementByColumn+",null)),0) AS CUR_YEAR_DATA, ");
    builder.append(" IFNULL(MAX(IF((YEAR(FEED.feed_date)="+lastyear+" and FEED.feed_date=FEEDYEARDATA.lastYearMaxFeedDate ),"+measurementByColumn+",null)),0) AS LAST_YEAR_DATA , ");
    builder.append(" FEED.pa_code,FEED.sub_pa_code ");
    builder.append(" FROM lm_dealer_info_data_feed FEED ");
    builder.append(" inner join ( SELECT pa_code,sub_pa_code, ");
    builder.append(" MAX(IF(YEAR(feed_date)="+currentyear+",feed_date,NULL)) as curYearMaxFeedDate, ");
    builder.append(" MAX(IF(YEAR(feed_date)="+lastyear+",feed_date,NULL)) as lastYearMaxFeedDate " );
    builder.append(" FROM lm_dealer_info_data_feed  " );
    builder.append(" GROUP BY pa_code,sub_pa_code  ) as FEEDYEARDATA " );
    builder.append(" ON FEED.pa_code =FEEDYEARDATA.pa_code and FEED.sub_pa_code = FEEDYEARDATA.sub_pa_code " );
    builder.append(" GROUP BY FEED.pa_code,FEED.sub_pa_code ");
    return builder.toString();

    Формируем чоткий запрос :)

    vetal, 18 Марта 2015

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public void setSkyboxName(String skyboxName) {
        if (skyboxName != null && skyboxName.length() > 2) {
          this.setSkybox(new SkyBox(skyboxName));
        } else {
          this.setSkybox(null);
        }
      }

    если имя неба длинна > 2 значит создать новое небо,
    а иначе неба не будет вообще

    dmli, 18 Марта 2015

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

    +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
    for (int i = 0; i < blockNodeSize; i++) {
        String blockTitle = subBlock.getElementsByClass("b-results__drugs-title").get(i).text();
        String blockData = String.valueOf(subBlock.getElementsByTag("dd").get(i))
                //.replace("\n", "")
                .replace("<dd>", "")
                .replace("</dd>", "")
                .replace("<p><i>", "")
                .replace("</i></p>", ":")
                .replace("<p>", "")
                .replace("</p>", "")
                .replace("</i>", "")
                .replace("<br>", "")
                .replace("</br>", "\n");

    extruder, 13 Марта 2015

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

    +80

    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
    public Object convert(Object entity) {
            
            Object result = null;
            
            //TUser to UserDTO
            if(entity.getClass().isInstance(TUser.class)) {
                result = new UserDTO();
                ((UserDTO)result).setId(((TUser)entity).getId());
                ((UserDTO)result).setLogin(((TUser)entity).getLogin());
                ((UserDTO)result).setPassword(((TUser)entity).getPassword());
            } 
            
            //TState to StateDTO
            if(entity.getClass().isInstance(TState.class)) {
                result = new StateDTO();
                ((StateDTO)result).setId(((TState)entity).getId());
                ((StateDTO)result).setAlias(((TState)entity).getAlias());
                ((StateDTO)result).setCaption(((TState)entity).getCaption());
            } 
            
            //TSale to SaleDTO
            if(entity.getClass().isInstance(TSale.class)) {
                result = new SaleDTO();
                ((SaleDTO)result).setId(((TSale)entity).getId());
                ((SaleDTO)result).setBuyerInfo(((TSale)entity).getBuyerInfo());
                ((SaleDTO)result).setCreateDate(((TSale)entity).getCreateDate());
                ((SaleDTO)result).setNumber(((TSale)entity).getNumber());
                TState state = ((TSale)entity).getStateId();
                ((SaleDTO)result).setState((StateDTO)convert(state));
                TGoods goods = ((TSale)entity).getGoodsId();
                ((SaleDTO)result).setGoods((GoodsDTO)convert(goods));
            } 
            
            //TImage to ImageDTO
            if(entity.getClass().isInstance(TImage.class)) {
                result = new ImageDTO();
                ((ImageDTO)result).setId(((TImage)entity).getId());
                ((ImageDTO)result).setPath(((TImage)entity).getPath());
                TGoods goods = ((TImage)entity).getGoodsId();
                ((ImageDTO)result).setGoods((GoodsDTO)convert(goods));
            } 
            
            //TGoods to GoodsDTO
            if(entity.getClass().isInstance(TGoods.class)) {
                result = new GoodsDTO();
                ((GoodsDTO)result).setId(((TGoods)entity).getId());
                ((GoodsDTO)result).setName(((TGoods)entity).getName());
                ((GoodsDTO)result).setPrice(((TGoods)entity).getPrice());
                ((GoodsDTO)result).setDescription(((TGoods)entity).getDescription());
                TCategory category = ((TGoods)entity).getCategoryId();
                ((GoodsDTO)result).setCategory((CategoryDTO)convert(category));
            } 
            
            //TCategory to CategoryDTO
            if(entity.getClass().isInstance(TCategory.class)) {
                result = new CategoryDTO();
                ((CategoryDTO)result).setId(((TCategory)entity).getId());
                ((CategoryDTO)result).setDescription(((TCategory)entity).getDescription());
                ((CategoryDTO)result).setName(((TCategory)entity).getName());
            } 
            return result;
        }

    Выдавил из себя преобразование из Entity в DTO

    carapuz, 08 Марта 2015

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

    +79

    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
    private short findHeaderLength() {
        return (short)(
            1+
            3+
            4+
            2+
            2+
            2+
            1+
            1+
            4+
            4+
            4+
            1+
            1+
            2+
            (32*fieldArray.length)+
            1
        );
    }

    DBFHeader

    bormand, 06 Марта 2015

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

    +85

    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
    public final class Equality {
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eq(@Nullable O o, @Nullable O a) {
            return Objects.equals(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a) {
            return eq(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b) {
            return eq(o, a) || eq(o, b);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c) {
            return eqAny(o, a, b) || eq(o, c);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d) {
            return eqAny(o, a, b, c) || eq(o, d);
        }
    
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @param e an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d, @Nullable O e) {
            return eqAny(o, a, b, c, d) || eq(o, e);
        }
        
        /**
         * @param o an object
         * @param a an array of objects to be compared
         * @return true if any the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, O... a) {
            for(O e: a)
                if(eq(o, e))
                    return true;
            return false;
        }
    }

    Мой любимый класс.
    Когда на душе становится тяжело, я всегда открываю этот класс, и признаки депрессии улетучиваются.
    И да, комментарии врут, и да, там еще столько же методов eqAll(...)

    stasmarkin, 05 Марта 2015

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

    +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
    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
    private void spreadBullets() {
            bulletItemsWip.clear();
            for (AbstractInventoryItem item : inventoryItemsSortedByValue) {
                if (item instanceof RangeBulletItem) {
                    bulletItemsWip.add((RangeBulletItem) item);
                }
            }
    
            rangeUnitsQueueWip.clear();
            for (Unit unit : areaObject.getUnits()) {
                if (unit.getSpecialization().equals(Unit.UnitSpecialization.RANGE)) {
                    rangeUnitsQueueWip.add(unit);
                }
            }
    
            while (rangeUnitsQueueWip.size > 0 && bulletItemsWip.size > 0) {
                Iterator<Unit> unitsIterator = rangeUnitsQueueWip.iterator();
                while (unitsIterator.hasNext()) {
                    // find suitable bullets or remove unit from queue
                    Unit rangeUnit = unitsIterator.next();
    
                    RangeBulletItem foundBulletItemInInventoryForUnit = searchBulletFor(rangeUnit);
                    if (foundBulletItemInInventoryForUnit == null) {
                        // remove unit from bullets queue
                        unitsIterator.remove();
                    } else {
                        //  bullet was found
                        RangeBulletItem unitBulletsItem = rangeUnit.getEquipment().getRangeBulletsItem();
                        if (unitBulletsItem == null) {
                            unitBulletsItem = foundBulletItemInInventoryForUnit.split(1);
                            rangeUnit.getEquipment().setRangeBulletsItem(unitBulletsItem);
                        } else {
                            if (unitBulletsItem.getClass().equals(foundBulletItemInInventoryForUnit.getClass())){
                                if (!unitBulletsItem.isFull()) {
                                    foundBulletItemInInventoryForUnit.moveQuantity(1, unitBulletsItem);
                                } 
                            } else {
                                rangeUnit.getEquipment().dropRangeBullets();
                                unitBulletsItem = foundBulletItemInInventoryForUnit.split(1);
                                rangeUnit.getEquipment().setRangeBulletsItem(unitBulletsItem);
                            }
                        }
    
                        if (foundBulletItemInInventoryForUnit.isEmpty()) {
                            // remove item from inventory
                            bulletItemsWip.removeValue(foundBulletItemInInventoryForUnit, true);
                            remove(foundBulletItemInInventoryForUnit);
                        }
    
                        if (unitBulletsItem.isFull()) {
                            // remove unit from bullets queue
                            unitsIterator.remove();
                        }
    
                        if (bulletItemsWip.size == 0) {
                            // stop spreading
                            break;
                        }
                    }
                }
            }
    
            // sync quantities to inventory
            for (AbstractInventoryItem item : bulletItemsWip) {
                getItem(item.getClass()).setQuantity(item.getQuantity());
            }
        }

    Раздать пули отряду...

    dmli, 01 Марта 2015

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

    +81

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class GetDataFromMySQL extends AsyncTask<String, String, String> {
    
     protected String doInBackground(String[] params) {
    
         runOnUiThread(new Runnable() {
            public void run() {
            ...
            ... 
          //абсолютно вся логика здесь.
            }

    Мастер многопоточного ПОГРОМмирования под Ондроид...

    argamidon, 01 Марта 2015

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