Debian Codegraph @

current/hiseq/Tile.java

raw symbols SCIP
1 package hiseq;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5
6 import structures.ByteBuilder;
7
8 public class Tile implements Iterable<MicroTile> {
9
10 public Tile(int lane_, int tile_){
11 lane=lane_;
12 tile=tile_;
13 }
14
15 public MicroTile get(int x, int y, boolean create){
16 final int xindex=x/xSize, yindex=y/ySize;
17 ArrayList<MicroTile> ylist=getIndex(xindex, create);
18 if(ylist==null || (yindex>=ylist.size() && !create)) {return null;}
19 while(yindex>=ylist.size()){ylist.add(null);}
20 MicroTile mt=ylist.get(yindex);
21 if(mt==null && create){
22 mt=new MicroTile(lane, tile, xindex*xSize, (xindex+1)*xSize-1, yindex*ySize, (yindex+1)*ySize-1);
23 ylist.set(yindex, mt);
24 }
25 assert(mt==null || mt.contains(x, y)) : x+", "+y+", "+xindex+", "+yindex+", "+mt;
26 return mt;
27 }
28
29 private ArrayList<MicroTile> getIndex(int xindex, boolean create){
30 if(!create && xindex>=xlist.size()) {return null;}
31 while(xindex>=xlist.size()){xlist.add(new ArrayList<MicroTile>());}
32 ArrayList<MicroTile> ylist=xlist.get(xindex);
33 return ylist;
34 }
35
36 @Override
37 public String toString(){
38 return toText(31, 0, null, null).toString();
39 }
40
41 public ByteBuilder toText(int k, double HG, double[] rerf, double[] berf){
42 ByteBuilder bb=new ByteBuilder();
43 for(ArrayList<MicroTile> ylist : xlist){
44 if(ylist!=null){
45 for(MicroTile mt : ylist){
46 if(mt!=null){
47 mt.toText(bb, k, HG, rerf, berf);
48 }
49 }
50 }
51 }
52 return bb;
53 }
54
55 public void add(Tile tb) {
56 for(ArrayList<MicroTile> x : tb.xlist) {
57 for(MicroTile mtb : x) {
58 // System.err.println("Adding mt "+mtb.x1+" "+mtb.y1);
59 if(mtb!=null) {
60 synchronized(mtb) {
61 MicroTile mta=get(mtb.x1, mtb.y1, true);
62 synchronized(mta) {
63 mta.add(mtb);
64 }
65 }
66 }
67 }
68 }
69 }
70
71 @Override
72 public Iterator<MicroTile> iterator() {return mtList().iterator();}
73
74 public ArrayList<MicroTile> mtList() {
75 ArrayList<MicroTile> list=new ArrayList<MicroTile>();
76 for(ArrayList<MicroTile> ylist : xlist){
77 if(ylist!=null){
78 for(MicroTile mt : ylist){
79 if(mt!=null){
80 list.add(mt);
81 }
82 }
83 }
84 }
85 return list;
86 }
87
88 public ArrayList<ArrayList<MicroTile>> xlist=new ArrayList<ArrayList<MicroTile>>();
89
90 public int lane;
91 public int tile;
92 public static int xSize=500;
93 public static int ySize=500;
94 }