Advertisement
Guest User

Untitled

a guest
Sep 18th, 2010
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package model;
  2.  
  3. public class Row_i implements Cloneable, Comparable<Row_i> {
  4. public int id_A, id_B, startPosA, startPosB, endPosA, endPosB, rowType;
  5.  
  6. public Row_i clone() {
  7. try {
  8. return (Row_i)super.clone();
  9. } catch(CloneNotSupportedException e) {
  10. return null;
  11. }
  12. }
  13.  
  14. public Row_i() {}
  15.  
  16. public Row_i(int id_A, int id_B, int startPosA, int startPosB, int endPosA, int endPosB, int rowType) {
  17. this.id_A = id_A;
  18. this.id_B = id_B;
  19. this.startPosA = startPosA;
  20. this.startPosB = startPosB;
  21. this.endPosA = endPosA;
  22. this.endPosB = endPosB;
  23. this.rowType = rowType;
  24.  
  25. }
  26.  
  27. public int compareTo(Row_i other) {
  28. // swap "this" and "other" to reverse sort order
  29. int c = this.id_A - other.id_B;
  30. if (c != 0) return c;
  31. c = this.id_B - other.id_B;
  32. if (c != 0) return c;
  33. c = this.startPosA - other.startPosA;
  34. if (c != 0) return c;
  35. c = this.startPosB - other.startPosB;
  36. return c;
  37. }
  38.  
  39. public boolean equals(Object other) {
  40. ... implement equals
  41. }
  42.  
  43. public int hashcode() {
  44. ... implement hashcode
  45. }
  46. }
  47.  
  48. // somewhere else
  49.  
  50. SortedSet<Row_i> rows = new TreeSet<Row_i>();
  51.  
  52. rows.add( ... )
  53.  
  54. for (Row_i row: rows) {
  55. // iterating over sorted rows
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement