annotate NGSrich_0.5.5/src/datastructures/Frame.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 package datastructures;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 * Used for various purposes.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 * @author Ali Abdallah
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 * @version 01.2011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 * @since jdk 1.6.0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 public class Frame {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 // Self explanatory.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 protected int start;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 protected int end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 protected int length;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 * Constructs a frame with start position "start", length "length" and
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 * end position "start+length-1".
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 * @param start the start position of the frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 * @param length the length of the frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 public Frame(int start, int length) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 this.start = start; end = start+length-1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 this.length = length;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 * Verify if this frame overlaps the frame specified in the parameter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 * @param f the frame which potentially overlaps the calling frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 * @return true if the two frames overlap each other and false otherwise.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 public boolean overlaps(Frame f){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 return (end >= f.start() && start < f.end());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 * Computes the size of the overlap area.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 * @param f the frame overlapping the calling frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 * @return the size of the overlap if an overlap exists and -1 otherwise.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 public int overlapSize(Frame f){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 if(this.overlaps(f)){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 int s = Math.max(start, f.start());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 int e = Math.min(end, f.end());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 return e-s+1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 return -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 * Unify the calling frame with the frame specified in the parameter.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 * @param f the frame to be unified with the calling frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 * @return the union of the calling frame and f.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 public Frame unify(Frame f){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 return
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 new Frame(Math.min(this.start, f.start),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 Math.max(this.end,f.end)-Math.min(this.start, f.start)+1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 * self explanatory
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 * @return start of the frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 public int start(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 return start;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 * self explanatory
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 * @return end of the frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 public int end(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 return end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 * self explanatory
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 * @return length of the frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 public int length(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 return length;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 * Make a string representation of the frame.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 * @return a string representation of the string.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 public String toString(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 return start+":"+end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 }