source: other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/TestWhitelistHashmap.java@ 31294

Last change on this file since 31294 was 31199, checked in by davidb, 7 years ago

Renaming of classname to reflect filename rename

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1package org.hathitrust.extractedfeatures;
2
3import java.io.BufferedInputStream;
4import java.io.FileInputStream;
5import java.io.IOException;
6import java.io.InputStream;
7import java.nio.charset.StandardCharsets;
8import java.nio.file.Files;
9import java.nio.file.Paths;
10import java.util.HashMap;
11import java.util.stream.Stream;
12
13
14public class TestWhitelistHashmap {
15
16 protected String _dictionary_filename;
17 protected HashMap<String,Boolean> _hashmap;
18
19 protected int FILL_FACTOR = 26;
20
21 public TestWhitelistHashmap(String dictionary_filename) {
22 System.out.println("Constructing: WhitelistHashmap");
23
24 _dictionary_filename = dictionary_filename;
25
26 _hashmap = new HashMap<String,Boolean>();
27 }
28
29 public void storeEntries()
30 {
31 System.out.println("Build hashmap ...");
32
33 for (int i=0; i<FILL_FACTOR; i++) {
34 char prefix = (char) ('a' + i);
35
36 //read file into stream, try-with-resources
37 try (Stream<String> stream = Files.lines(Paths.get(_dictionary_filename))) {
38
39 stream.forEach(word -> {_hashmap.put(prefix+word,true);});
40 } catch (IOException e) {
41 e.printStackTrace();
42 }
43 }
44 System.out.println("... done");
45
46 }
47
48 public boolean contains(String key)
49 {
50 return _hashmap.containsKey(key);
51 }
52
53}
Note: See TracBrowser for help on using the repository browser.