1 | /*
|
---|
2 | * To change this license header, choose License Headers in Project Properties.
|
---|
3 | * To change this template file, choose Tools | Templates
|
---|
4 | * and open the template in the editor.
|
---|
5 | */
|
---|
6 | package monogram.model;
|
---|
7 |
|
---|
8 | import java.io.BufferedReader;
|
---|
9 | import java.io.IOException;
|
---|
10 | import java.io.InputStreamReader;
|
---|
11 | import java.io.Reader;
|
---|
12 | import java.util.HashSet;
|
---|
13 | import java.util.Set;
|
---|
14 | import util.Pool;
|
---|
15 |
|
---|
16 |
|
---|
17 | /**
|
---|
18 | *
|
---|
19 | * @author tl113
|
---|
20 | */
|
---|
21 | public class ListModel {
|
---|
22 |
|
---|
23 | private Set<String> specialConditionsList;
|
---|
24 | private final String CHARSET_ENCODING = "utf-8";
|
---|
25 | private final String DELIMITER = "\t";
|
---|
26 |
|
---|
27 | private Pool<String> pool;
|
---|
28 | private final String path;
|
---|
29 |
|
---|
30 | public ListModel(String path, Pool<String> pool){
|
---|
31 | System.out.println("test 15");
|
---|
32 | this.path = path;
|
---|
33 | this.pool = pool;
|
---|
34 | System.out.println("test 16");
|
---|
35 | specialConditionsList = new HashSet();
|
---|
36 | init();
|
---|
37 |
|
---|
38 | }
|
---|
39 |
|
---|
40 | private void init() {
|
---|
41 | System.out.println("test 17");
|
---|
42 | BufferedReader reader = null;
|
---|
43 | try {
|
---|
44 | System.out.println("test 18");
|
---|
45 | final String filepath = path;
|
---|
46 | reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(filepath), CHARSET_ENCODING));
|
---|
47 | System.out.println("test 19");
|
---|
48 | String line;
|
---|
49 | while ((line = reader.readLine()) != null) {
|
---|
50 | System.out.println("test line1 : "+line);
|
---|
51 | // final String elements = line.split(DELIMITER);
|
---|
52 | specialConditionsList.add(line);
|
---|
53 | System.out.println("test line2");
|
---|
54 | }
|
---|
55 | System.out.println("test 20");
|
---|
56 | } catch (IOException e) {
|
---|
57 | e.printStackTrace();
|
---|
58 | } finally {
|
---|
59 | close(reader);
|
---|
60 | }
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 | private void close(Reader reader) {
|
---|
65 | if (reader != null) {
|
---|
66 | try {
|
---|
67 | reader.close();
|
---|
68 | } catch (IOException e) {
|
---|
69 | e.printStackTrace();
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | public Set<String> getMonogramProbabilities() {
|
---|
75 | return specialConditionsList;
|
---|
76 | }
|
---|
77 |
|
---|
78 | public boolean contains(String s){
|
---|
79 |
|
---|
80 | if(specialConditionsList.contains(s)){
|
---|
81 |
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 |
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | }
|
---|