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 |
|
---|
15 |
|
---|
16 | /**
|
---|
17 | *
|
---|
18 | * @author tl113
|
---|
19 | */
|
---|
20 | public class ListModel {
|
---|
21 |
|
---|
22 | // private static final String DELIMITER = "\t";
|
---|
23 |
|
---|
24 | private final String CHARSET_ENCODING = "utf-8";
|
---|
25 | private final String path;
|
---|
26 | private final Set<String> specialConditionsList;
|
---|
27 |
|
---|
28 |
|
---|
29 | public ListModel(String path)
|
---|
30 | {
|
---|
31 | this.path = path;
|
---|
32 | this.specialConditionsList = new HashSet<String>();
|
---|
33 |
|
---|
34 | init();
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void init()
|
---|
38 | {
|
---|
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 | {
|
---|
58 | if (reader != null) {
|
---|
59 | try {
|
---|
60 | reader.close();
|
---|
61 | } catch (IOException e) {
|
---|
62 | e.printStackTrace();
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | public Set<String> getMonogramProbabilities()
|
---|
68 | {
|
---|
69 | return specialConditionsList;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public boolean contains(String s)
|
---|
73 | {
|
---|
74 | if(specialConditionsList.contains(s))
|
---|
75 | {
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 |
|
---|
79 | return false;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | }
|
---|