Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package rectanglecollection;
  2.  
  3. /**
  4. *
  5. * @author User
  6. */
  7. public class Colors implements Comparable<Object>{
  8. final static int BYTE_MASK=255;
  9. private long red, green, blue;
  10. protected long color;
  11. public void rgb2color(){
  12. color=(red<<16)|(green<<8)|(blue);
  13. }
  14. public void color2rgb(){
  15. red =color>>16;
  16. green=(color>>8)& BYTE_MASK;
  17. blue =color & BYTE_MASK;
  18. }
  19.  
  20. public Colors(){}
  21.  
  22. public Colors(long c){
  23. color=c; color2rgb();
  24. }
  25.  
  26. public long getRed()
  27. { return red;}
  28.  
  29. public long getGreen()
  30. { return green;}
  31.  
  32. public long getBlue(){
  33. return blue;
  34. }
  35.  
  36. public long getColor()
  37. {return color;}
  38.  
  39. public void setRed(long red)
  40. {this.red=red; rgb2color();}
  41. public void setGreen(long green)
  42. {
  43. this.green=green; rgb2color();
  44. }
  45. public void setBlue(long blue)
  46. {
  47. this.blue=blue; rgb2color();
  48. }
  49.  
  50. public String toString()
  51. { return "Red: "+ red + " Green: "+green+ " Blue: "+blue;}
  52.  
  53. public boolean equals(Object r)
  54. {
  55. return this.color==(((Colors)r).color);
  56. }
  57.  
  58. public int compareTo(Object r)
  59. {
  60. if(this.color<((Colors)r).color)
  61. return -1;
  62. if(this.color>((Colors)r).color)
  63. return 1;
  64. return 0;}
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement