Changeset 31215


Ignore:
Timestamp:
2016-12-12T17:12:56+13:00 (7 years ago)
Author:
davidb
Message:

Changed back to Guava 20 API, now mvn shading allows me to have this in the JAR file as well as the Guava 14 that Spark/Apache uses

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/WhitelistBloomFilter.java

    r31211 r31215  
    33import java.io.BufferedInputStream;
    44import java.io.BufferedOutputStream;
    5 import java.io.DataInputStream;
    6 import java.io.DataOutputStream;
    75import java.io.File;
    86import java.io.FileInputStream;
     
    119import java.io.IOException;
    1210import java.io.InputStream;
    13 import java.io.OutputStream;
    1411import java.io.Serializable;
    1512import java.nio.charset.Charset;
     
    2118import javax.annotation.Nullable;
    2219
    23 import static com.google.common.base.Preconditions.checkNotNull;
    24 
    2520import com.google.common.base.Preconditions;
    2621import com.google.common.hash.BloomFilter;
    27 //import com.google.common.hash.BloomFilterAdvanced;
    28 //import com.google.common.hash.BloomFilterStrategies.BitArray;
    2922import com.google.common.hash.Funnel;
    3023import com.google.common.hash.Funnels;
    3124import com.google.common.hash.PrimitiveSink;
    32 import com.google.common.primitives.SignedBytes;
    33 import com.google.common.primitives.UnsignedBytes;
    3425
    3526public class WhitelistBloomFilter {
     
    8374                num_lines = countLines(dictionary_filename);
    8475                 
    85                 //Funnel<CharSequence> string_funnel = Funnels.stringFunnel(StandardCharsets.UTF_8);
    86                 Funnel<CharSequence> string_funnel = stringFunnel(StandardCharsets.UTF_8);
     76                Funnel<CharSequence> string_funnel = Funnels.stringFunnel(StandardCharsets.UTF_8);
    8777                _bloomFilter = BloomFilter.create(string_funnel, num_lines,FALSE_POSITIVE_PERCENTAGE);
    8878            }
     
    154144            BufferedInputStream bfis = new BufferedInputStream(fis);
    155145
    156             //Funnel<CharSequence> string_funnel = Funnels.stringFunnel(StandardCharsets.UTF_8);
    157             Funnel<CharSequence> string_funnel = stringFunnel(StandardCharsets.UTF_8);
     146            Funnel<CharSequence> string_funnel = Funnels.stringFunnel(StandardCharsets.UTF_8);
    158147            bloomFilter = BloomFilter.readFrom(bfis,string_funnel);
    159148
     
    171160
    172161
    173     // Spark uses Guava 14.0, the following is future-ported from Guava 20.0
    174     // Added in here, rather then Funnel, and StringCharsetFunnel -> MyStringCharsetFunnel
    175    
    176     public static Funnel<CharSequence> stringFunnel(Charset charset) {
    177162
    178         return new MyStringCharsetFunnel(charset);
    179 
    180       }
    181    
    182     private static class MyStringCharsetFunnel implements Funnel<CharSequence>, Serializable {
    183 
    184         private static final long serialVersionUID = 1L;
    185        
    186         private final Charset charset;
    187 
    188         MyStringCharsetFunnel(Charset charset) {
    189           this.charset = Preconditions.checkNotNull(charset);
    190         }
    191 
    192         public void funnel(CharSequence from, PrimitiveSink into) {
    193           into.putString(from, charset);
    194         }
    195 
    196         @Override
    197         public String toString() {
    198           return "Funnels.stringFunnel(" + charset.name() + ")";
    199         }
    200 
    201         @Override
    202         public boolean equals(@Nullable Object o) {
    203 
    204           if (o instanceof MyStringCharsetFunnel) {
    205             MyStringCharsetFunnel funnel = (MyStringCharsetFunnel) o;
    206             return this.charset.equals(funnel.charset);
    207           }
    208           return false;
    209         }
    210 
    211         @Override
    212         public int hashCode() {
    213           return MyStringCharsetFunnel.class.hashCode() ^ charset.hashCode();
    214         }
    215 
    216         Object writeReplace() {
    217           return new SerializedForm(charset);
    218         }
    219 
    220         private static class SerializedForm implements Serializable {
    221           private final String charsetCanonicalName;
    222 
    223           SerializedForm(Charset charset) {
    224             this.charsetCanonicalName = charset.name();
    225           }
    226 
    227           private Object readResolve() {
    228             return stringFunnel(Charset.forName(charsetCanonicalName));
    229           }
    230 
    231           private static final long serialVersionUID = 0;
    232 
    233         }
    234       }
    235163   
    236164   
Note: See TracChangeset for help on using the changeset viewer.