File: SeqPosM.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (90 lines) | stat: -rwxr-xr-x 2,065 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package structures;

import shared.Tools;

public class SeqPosM implements Cloneable, Comparable<SeqPosM>{

	public SeqPosM(byte[] seq_, int pos_) {this(seq_, pos_, 1);}
	public SeqPosM(SeqPosM sp) {this(sp.seq, sp.pos, sp.count, sp.hashcode, sp.gc);}
	public SeqPosM(byte[] seq_, int pos_, int count_) {
//		synchronized(this) {
			Object o=(seq_==null ? this : seq_);
//			synchronized(o) {
				seq=seq_;
				pos=pos_;
				count=count_;
				hashcode=Tools.hash(seq, 22);
				gc=Tools.calcGC(seq);
				assert(count>=0);
//			}
//		}
	}
	private SeqPosM(byte[] seq_, int pos_, int count_, int code_, float gc_) {
//		synchronized(this) {
//			synchronized(seq_) {
			seq=seq_;
			pos=pos_;
			count=count_;
			hashcode=code_;
			assert(count>=0);
			gc=gc_;
//			}
//		}
	}
	
	public void setFrom(SeqPos sp) {
//		synchronized(sp) {
//			synchronized(sp.seq()) {synchronized(this) {
			seq=sp.seq();
			pos=sp.pos();
			count=sp.count;
			hashcode=sp.hashcode;
			assert(count>=0);
//			}}
//		}
	}
	
	@Override
	public boolean equals(Object o) {
		return equals((SeqPosM)o);
	}
	
	public boolean equals(SeqPosM o) {
		if(pos!=o.pos || hashcode!=o.hashcode) {return false;}
		return Tools.equals(seq, o.seq);
	}
	
	@Override
	public int hashCode() {
		return hashcode;
	}
	
	@Override
	public SeqPosM clone() {
		try {
			return (SeqPosM) super.clone();
		} catch (CloneNotSupportedException e) {
			throw new RuntimeException(e);
		}
	}
	
	@Override
	public int compareTo(SeqPosM o) {
		if(count!=o.count) {return o.count-count;}
		if(seq.length!=o.seq.length) {return o.seq.length-seq.length;}
//		if(pos!=o.pos) {return o.pos-pos;}
//		return Tools.compare(seq, o.seq);//Slow; not needed for deterministic behavior if using a stable sort
		return 0;
	}
	
	public final byte[] seq() {return seq;}
	public final int pos() {return pos;}
	public void setPos(int x) {pos=x;}
	
	public byte[] seq;
	public int pos;
	public int hashcode;
	public int count;
	public float gc;
	
}