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 | this.path = path;
|
---|
32 | this.pool = pool;
|
---|
33 | specialConditionsList = new HashSet();
|
---|
34 | init();
|
---|
35 |
|
---|
36 | }
|
---|
37 |
|
---|
38 | private void init() {
|
---|
39 | BufferedReader reader = null;
|
---|
40 | try {
|
---|
41 | final String filepath = path;
|
---|
42 | reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(filepath), CHARSET_ENCODING));
|
---|
43 | String line;
|
---|
44 | while ((line = reader.readLine()) != null) {
|
---|
45 | // final String elements = line.split(DELIMITER);
|
---|
46 | specialConditionsList.add(line);
|
---|
47 | }
|
---|
48 | } catch (IOException e) {
|
---|
49 | e.printStackTrace();
|
---|
50 | } finally {
|
---|
51 | close(reader);
|
---|
52 | }
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void close(Reader reader) {
|
---|
57 | if (reader != null) {
|
---|
58 | try {
|
---|
59 | reader.close();
|
---|
60 | } catch (IOException e) {
|
---|
61 | e.printStackTrace();
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public Set<String> getMonogramProbabilities() {
|
---|
67 | return specialConditionsList;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public boolean contains(String s){
|
---|
71 |
|
---|
72 | if(specialConditionsList.contains(s)){
|
---|
73 |
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | }
|
---|