View Javadoc
1   package myorg.relex.collection;
2   
3   import javax.persistence.*;
4   
5   import org.slf4j.Logger;
6   import org.slf4j.LoggerFactory;
7   /**
8    * This class represents an example entity that has an order in its parent's list.
9    */
10  @Entity
11  @Table(name="RELATIONEX_SEGMENT")
12  public class Segment implements Comparable<Segment>{
13  	private static final Logger log = LoggerFactory.getLogger(Segment.class);
14  	@Id @GeneratedValue
15  	private int id;
16  	
17  	private int number; //a one-up sequence used to order a route
18  	
19  	@Column(name="TO", length=16)
20  	private String to;
21  	@Column(name="FM", length=16)
22  	private String from;
23  	
24  	
25  	public int getId() { return id; }
26  
27  	public int getNumber() { return number; }
28  	public Segment setNumber(int number) {
29  		this.number = number;
30  		return this;
31  	}
32  	
33  	public String getTo() { return to; }
34  	public Segment setTo(String to) {
35  		this.to = to;
36  		return this;
37  	}
38  	
39  	public String getFrom() { return from; }
40  	public Segment setFrom(String from) {
41  		this.from = from;
42  		return this;
43  	}
44  
45  	@Override
46  	public int compareTo(Segment rhs) {
47  		if (this == rhs) { return 0; }
48  		int result = number - rhs.number;
49  		log.debug(getClass().getSimpleName() + toString() + 
50  				".compareTo" + rhs.toString() + 
51  				"=" + result
52  				);
53  		return result;
54  	}
55  	
56  	@Override
57  	public String toString() {
58  		return "(id=" + id + ",number=" + number + ")";
59  	}
60  
61  	/*
62  	@Override
63  	public int hashCode() {
64  		return number + (from==null?0 : from.hashCode()) + (to==null?0 : to.hashCode());
65  	}
66  	@Override
67  	public boolean equals(Object obj) {
68  		try {
69  			if (this == obj) { return true; }
70  			Segment rhs=(Segment)obj;
71  			return hashCode() == rhs.hashCode();
72  		} catch(Exception ex) { return false; }
73  	}
74  	*/
75  }