Jawa / Говнокод #667 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
public class ImageRotator {

    public static BufferedImage rotate(BufferedImage originalImage, int angle) {
        BufferedImage image = null;
        switch (angle) {
            case 90:
            case -270:
                image = ImageRotator.rotate90Right(originalImage);
                break;
            case 270:
            case -90:
                image = ImageRotator.rotate90Left(originalImage);
                break;
            case 180:
            case -180:
                image = ImageRotator.rotate180(originalImage);
                break;
            default:
                image = originalImage;
                break;
        }
        return image;
    }

    private static BufferedImage rotate90Left(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                biFlip.setRGB(height - 1 - j, width - 1 - i, bi.getRGB(i, j));
            }
        }
        return biFlip;
    }

    private static BufferedImage rotate90Right(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage biFlip = new BufferedImage(height, width, bi.getType());
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                biFlip.setRGB(j, i, bi.getRGB(i, j));
            }
        }
        return biFlip;
    }

    private static BufferedImage rotate180(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                biFlip.setRGB(i, j, bi.getRGB(width - 1 - i, height - 1 - j));
            }
        }
        return biFlip;
    }
}

Есть в Java для работы с изображениями такой класс как AphineTransform, но в после 3 часов активного взаимодействия с ним добился только того что изображение после болшого кол-ва поворотов привращалось в точку. Поэтому из себя была выдавлена эта заглушка...

guest guest, (Updated )

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

Jawa / Говнокод #657 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
  97. 97
package com.photoholding.processimage.eugene;

import java.awt.Point;
import java.awt.Rectangle;

import magick.ImageInfo;
import magick.MagickException;
import magick.MagickImage;

public class ProcessA {
	private MagickImage img;
	private String text;
	private String imageOrigin;
	private String fout;
	private String fmount;
	private final String tmpImg = "tmpIM.jpg";
	private final String tmpMnt = "tmpMounted.jpg";
    private final int width = 1607;
    private final int height = 1205;
	
	public ProcessA( String txt, String fin, String fout, String fmount ){
		if( txt.length() > 52 ){
			System.out.println( "error: text string more than 52" );
			System.exit(0);
		}			
		this.text = txt;
		this.img = getImage( fin );
		this.imageOrigin = fin;
		this.fmount = fmount;
		this.fout = fout;
	}

	private MagickImage getImage( String fin2 ) {
		MagickImage im = null;
		try {	
		     im = new MagickImage( new ImageInfo( fin2 ) );
		} catch ( MagickException  e ) {
			e.printStackTrace();
			return null;
		}
		return im;
	}
	
	public boolean doProcess(){
		try {
			scaleGenerally();
			annotateMounted();
			montage();
		} catch ( Exception e ) {
			e.printStackTrace();
			return false;
		}		
		return true;
	}
	
    private void montage() throws Exception {
    	MagickProcessing mp = new MagickProcessing();
    	mp.montage( tmpMnt, tmpImg, fout );		
	}

	private void annotateMounted() throws Exception {
    	MagickProcessing mp = new MagickProcessing();
    	mp.annotateImage(  text, new Point( 115, 1195 - ( 598 - ( ( text.length() /  2 ) * 23  ) ) ), fmount, tmpMnt );	
	}

	protected boolean scaleGenerally() throws Exception {

    	int h = img.getDimension().height;
		int w = img.getDimension().width;
		MagickProcessing mp = new MagickProcessing();
		if( h > w ){
			if ( !mp.rotateANDscale( "1607x", imageOrigin, tmpImg )) return false;
			img = getImage( tmpImg );
			h = img.getDimension().height;
			w = img.getDimension().width;
			if( h < height ){
				if( !mp.rotateANDscale( "x1205", imageOrigin, tmpImg )) return false;
				img = getImage( tmpImg );
				h = img.getDimension().height;
				w = img.getDimension().width;
			}
			if( !mp.crop( new Rectangle( ( w - width ) / 2, 0, 1607, 1205 ), tmpImg, tmpImg )) return false;
		} else {
			if( !mp.scaleImage( "1607x", imageOrigin, tmpImg ) ) return false;
			img = getImage( tmpImg );
			h = img.getDimension().height;
			w = img.getDimension().width;
			if( h < height ){
				if( !mp.scaleImage( "x1205", imageOrigin, tmpImg ) ) return false;
				if( !mp.crop( new Rectangle( ( w - width ) / 2, 0, 1607, 1205 ), tmpImg, tmpImg ) ) return false;
			} else if( h > height ){
				if( !mp.crop( new Rectangle( 0, (int)( h - height ) / 2, width, height  ), tmpImg, tmpImg )) return false;
			}
		}
		return true;
	}
}

постановка задачи - нужен метод для вращения изображений

guest guest, (Updated )

Комментарии (2, +2)

Jawa / Говнокод #627 Ссылка на оригинал

0

  1. 1
UniqueNamesTableUtils.putPortletRequestIntoResourceRecordLazyLoadAdminTableModelInSession(portletrequest);

Это IBM WebSphere Portal 6.0 - код является частью портлета, отвечающего за управление объектами портала (административный интерфейс).

guest guest, (Updated )

Комментарии (6, +6)

Jawa / Говнокод #613 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
public String find(String request) {
    String result = "";
    status.setState(Status.STATUS_IN_PROGRESS);
    status.setMessage("search start");   
    buildTokens(request);
    if (buildWords()) {
        if (buildSynonyms()) {
            if (buildValues()) {
                if (buildProperties()) {
                    if (buildParameters()) {
                        result = buildCondition();
                        status.setParameters(new ArrayList(parameters));
                        status.setState(Status.STATUS_SUCCESS);
                        status.setMessage("search done successfully");
                    } else {
                        status.setState(Status.STATUS_FAIL);
                        status.setMessage("can't build parameters");
                    }
                } else {
                    status.setState(Status.STATUS_FAIL);
                    status.setMessage("can't build properties");
                }
            } else {
                status.setState(Status.STATUS_FAIL);
                status.setMessage("can't build values");
            }
        } else {
            status.setState(Status.STATUS_FAIL);
            status.setMessage("can't build synonyms");
        }
    } else {
        status.setState(Status.STATUS_FAIL);
        status.setMessage("can't build words");
    }
    return result;
}

По мотивам http://www.govnokod.ru/593
Ява суровей :)

guest guest, (Updated )

Комментарии (4, +4)

Jawa / Говнокод #589 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
if (!"list".equals(message.getString("response"))) {
    throw new IOException("Expected list response but got: " + message.toString());
}

принятие ответа от сервера

guest guest, (Updated )

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

Jawa / Говнокод #586 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
public enum TimePeriod {
	
	NONE,
	DAILY,
	WEEKLY,
	MONTHLY,
	YEARLY;
	
	public static TimePeriod getTimePeriod(String periodStr) {
		if (null == periodStr) {
			return null;
		}
		if (0 == periodStr.length()) {
			return NONE;
		}
		if (0 == periodStr.compareToIgnoreCase("daily")) {
			return DAILY;
		}
		if (0 == periodStr.compareToIgnoreCase("weekly")) {
			return WEEKLY;
		}
		if (0 == periodStr.compareToIgnoreCase("monthly")) {
			return MONTHLY;
		}
		if (0 == periodStr.compareToIgnoreCase("yearly")) {
			return YEARLY;
		}
		return null;
	}
}

а правильно будет так
public static TimePeriod parse(String type) {
return valueOf(type.toUpperCase());
}

guest guest, (Updated )

Комментарии (5, +5)

Jawa / Говнокод #578 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
private String mPrimaryCorrelationKey;
 public String getPrimaryCorrelationKey()
  {
	long current = System.currentTimeMillis();
	current++;

	return new Long(current).toString();
  }

  public void setPrimaryCorrelationKey(String mPrimaryCorrelationKey) {
	  this.mPrimaryCorrelationKey = mPrimaryCorrelationKey;	  
  }

соответствующий геттер для этой проперти должен возвращать всегда уникальный id

guest guest, (Updated )

Комментарии (2, +2)

Jawa / Говнокод #577 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
public final class SqliteWrapper {
    private static final String SQLITE_EXCEPTION_DETAIL_MESSAGE
                = "unable to open database file";

    ...

    // FIXME: need to optimize this method.
    private static boolean isLowMemory(SQLiteException e) {
        return e.getMessage().equals(SQLITE_EXCEPTION_DETAIL_MESSAGE);
    }

    ...
}

Android source

guest guest, (Updated )

Комментарии (2, +2)