Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package model;
- public class Row_i implements Cloneable, Comparable<Row_i> {
- public int id_A, id_B, startPosA, startPosB, endPosA, endPosB, rowType;
- public Row_i clone() {
- try {
- return (Row_i)super.clone();
- } catch(CloneNotSupportedException e) {
- return null;
- }
- }
- public Row_i() {}
- public Row_i(int id_A, int id_B, int startPosA, int startPosB, int endPosA, int endPosB, int rowType) {
- this.id_A = id_A;
- this.id_B = id_B;
- this.startPosA = startPosA;
- this.startPosB = startPosB;
- this.endPosA = endPosA;
- this.endPosB = endPosB;
- this.rowType = rowType;
- }
- public int compareTo(Row_i other) {
- // swap "this" and "other" to reverse sort order
- int c = this.id_A - other.id_B;
- if (c != 0) return c;
- c = this.id_B - other.id_B;
- if (c != 0) return c;
- c = this.startPosA - other.startPosA;
- if (c != 0) return c;
- c = this.startPosB - other.startPosB;
- return c;
- }
- public boolean equals(Object other) {
- ... implement equals
- }
- public int hashcode() {
- ... implement hashcode
- }
- }
- // somewhere else
- SortedSet<Row_i> rows = new TreeSet<Row_i>();
- rows.add( ... )
- for (Row_i row: rows) {
- // iterating over sorted rows
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement