-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseqDB.java
More file actions
148 lines (113 loc) · 2.58 KB
/
seqDB.java
File metadata and controls
148 lines (113 loc) · 2.58 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package gsp;
//package gsp;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SeqDB {
private ArrayList<Sequence> seqs; //序列对象
public SeqDB() {
this.seqs = new ArrayList<Sequence>();
/* Sequence s;
//<{1 5}{2}{3}{4}>
s = new Sequence();*/
/* s.addElement(new Element(new int[] {1, 5}));
s.addElement(new Element(new int[] {2}));
s.addElement(new Element(new int[] {3}));
s.addElement(new Element(new int[] {4}));
seqs.add(s);*/
//System.out.println("neirong"+s);
Pattern p=Pattern.compile("(\\d+)");//正则表达式,验证是否是数字
File fRead =new File("d:\\word.txt");//从文本中读取
try{
Reader in =new FileReader(fRead);
BufferedReader bufferRead =new BufferedReader(in);
String str =null;
while((str=bufferRead.readLine())!=null){
Sequence s;
s = new Sequence();
//System.out.println(str);
Matcher m=p.matcher(str);
while(m.find()) {
int find=Integer.parseInt(m.group(1).toString());
s.addElement(new Element(new int[] {find}));
}
seqs.add(s);
//System.out.println("序列有"+s);
}
}
catch(IOException e)
{
System.out.println(e.toString());
}
//<{1}{3}{4}{3 5}>
// s = new Sequence();
//
// s.addElement(new Element(new int[] {1}));
//
// s.addElement(new Element(new int[] {3}));
//
// s.addElement(new Element(new int[] {4}));
//
// s.addElement(new Element(new int[] {3, 5}));
//
// seqs.add(s);
//
// //<{1}{2}{3}{4}>
//
// s = new Sequence();
//
// s.addElement(new Element(new int[] {1}));
//
// s.addElement(new Element(new int[] {2}));
//
// s.addElement(new Element(new int[] {3}));
//
// s.addElement(new Element(new int[] {4}));
//
// seqs.add(s);
//
// //<{1}{3}{5}>
//
// s = new Sequence();
//
// s.addElement(new Element(new int[] {1}));
//
// s.addElement(new Element(new int[] {3}));
//
// s.addElement(new Element(new int[] {5}));
//
// seqs.add(s);
//
// //<{4}{5}>
//
// s = new Sequence();
//
// s.addElement(new Element(new int[] {4}));
//
//
//
// s.addElement(new Element(new int[] {4,5}));
//
// seqs.add(s);
}
/**
* 获取序列集的大小
* 也就是获取有几个序列
* @return 序列集大小
*/
public int size(){
return this.seqs.size();
}
/**
* 获取序列集
* @return 序列集
*/
public ArrayList<Sequence> getSeqs(){
return this.seqs;
}
}